feature/day_and_night #34

Merged
kziolkowski merged 16 commits from feature/day_and_night into develop 2025-12-04 22:34:17 +01:00
2 changed files with 19 additions and 1 deletions
Showing only changes of commit c7a4aea70b - Show all commits
@@ -50,12 +50,14 @@ public partial class InventoryInstance : Node, ISaveable
LoadFromSaveData(); LoadFromSaveData();
InventoryContentsChanged += UpdateSaveData; InventoryContentsChanged += UpdateSaveData;
SlotAmountChanged += UpdateSaveData; SlotAmountChanged += UpdateSaveData;
SavegameService.OnSaveGameReset += SaveGameReset;
} }
public override void _ExitTree() public override void _ExitTree()
{ {
InventoryContentsChanged -= UpdateSaveData; InventoryContentsChanged -= UpdateSaveData;
SlotAmountChanged -= UpdateSaveData; SlotAmountChanged -= UpdateSaveData;
SavegameService.OnSaveGameReset -= SaveGameReset;
} }
public InventoryActionResult AddItem(ItemInstance newItem) public InventoryActionResult AddItem(ItemInstance newItem)
@@ -216,5 +218,17 @@ public partial class InventoryInstance : Node, ISaveable
} }
} }
} }
/// <summary>
/// Called when a new save is created.
/// Needs to do a runtime check because the InventoryInstance is already in existence at the beginning of the first scene.
/// </summary>
private void SaveGameReset()
{
foreach (var slot in _slots)
{
slot.itemInstance = null;
}
}
#endregion #endregion
} }
@@ -19,6 +19,9 @@ public static class SavegameService
public static bool _loaded = false; public static bool _loaded = false;
public delegate void SaveGameDelegate();
public static event SaveGameDelegate OnSaveGameReset = delegate {};
public static void AppendDataToSave( string id, Dictionary<string, Variant> payload) public static void AppendDataToSave( string id, Dictionary<string, Variant> payload)
{ {
@@ -130,5 +133,6 @@ public static class SavegameService
{ {
SaveDatas = new (); SaveDatas = new ();
Save(); Save();
OnSaveGameReset();
} }
} }