BUTR / BUTR/Bannerlord.ButterLib
SyncDataAsJson not working
- Dominant language
- C#
- Stars
- 28
- Forks
- 9
- Avg merge
- 1m
- Merged PRs (30d)
- 1
Description
Hey, the JSON based Sync-System for Bannerlords 1.3 (BETA) together with Bannerlord.ButterLib/2.10.0 is having issues.
Below an example how I use it and the serialized data always is a empty String and the deserialized one is null.
https://butterlib.butr.link/articles/SaveSystem/Overview.html
```csharp
internal class RevoltCampaignBehavior(CampaignGameStarter CampaignGameStarterObject) : CampaignBehaviorBase
{
private RevoltSaveData _revoltSaveData = new();
internal Kingdom? RandomLuckyNation { get; private set; }
internal Kingdom? ImperialLuckyNation { get; private set; }
internal Kingdom? NonImperialLuckyNation { get; private set; }
internal Dictionary SettlementsPreviousFaction { get; } = new();
public override void RegisterEvents()
{
CampaignEvents.OnSessionLaunchedEvent.AddNonSerializedListener(this, OnSessionLaunched);
CampaignEvents.OnClanChangedKingdomEvent.AddNonSerializedListener(this, OnClanChangedKingdom);
}
public override void SyncData(IDataStore dataStore)
{
if (dataStore.IsSaving)
{
_revoltSaveData.RandomLuckyNation = RandomLuckyNation;
_revoltSaveData.ImperialLuckyNation = ImperialLuckyNation;
_revoltSaveData.NonImperialLuckyNation = NonImperialLuckyNation;
_revoltSaveData.SettlementsPreviousFactionId = SettlementsPreviousFaction.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.StringId);
dataStore.SyncDataAsJson(nameof(RevoltCampaignBehavior), ref _revoltSaveData!);
}
else
{
dataStore.SyncDataAsJson(nameof(RevoltCampaignBehavior), ref _revoltSaveData!);
RandomLuckyNation = _revoltSaveData.RandomLuckyNation;
ImperialLuckyNation = _revoltSaveData.ImperialLuckyNation;
NonImperialLuckyNation = _revoltSaveData.NonImperialLuckyNation;
SettlementsPreviousFaction.Clear();
foreach (var settlementPreviousFactionId in _revoltSaveData.SettlementsPreviousFactionId)
{
var settlement = settlementPreviousFactionId.Key;
var factionStringId = settlementPreviousFactionId.Value;
var faction = Campaign.Current.Factions.FirstOrDefault(faction => faction.StringId == factionStringId);
if (faction is not null)
{
SettlementsPreviousFaction[settlement] = faction;
}
}
}
}
}
using TaleWorlds.CampaignSystem;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.SaveSystem;
namespace Bannerlord.RevolutionsReloaded.Components.Revolts.SaveData;
[Serializable]
internal class RevoltSaveData
{
[SaveableField(1)]
public Kingdom? RandomLuckyNation;
[SaveableField(2)]
public Kingdom? ImperialLuckyNation;
[SaveableField(3)]
public Kingdom? NonImperialLuckyNation;
[SaveableField(4)]
public Dictionary SettlementsPreviousFactionId = new();
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the IDataStore.SyncDataAsJson calls and the Bannerlord.ButterLib SaveSystem documentation linked in the issue. Reproduce the shown save and load paths, then trace why serialization produces an empty string and deserialization returns null. Done means the reported data round-trips correctly for this example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100