diff --git a/scripts/CSharp/Common/Inventory/InventoryInstance.cs b/scripts/CSharp/Common/Inventory/InventoryInstance.cs index a05f778..55fb944 100644 --- a/scripts/CSharp/Common/Inventory/InventoryInstance.cs +++ b/scripts/CSharp/Common/Inventory/InventoryInstance.cs @@ -50,12 +50,14 @@ public partial class InventoryInstance : Node, ISaveable LoadFromSaveData(); InventoryContentsChanged += UpdateSaveData; SlotAmountChanged += UpdateSaveData; + SavegameService.OnSaveGameReset += SaveGameReset; } - + public override void _ExitTree() { InventoryContentsChanged -= UpdateSaveData; SlotAmountChanged -= UpdateSaveData; + SavegameService.OnSaveGameReset -= SaveGameReset; } public InventoryActionResult AddItem(ItemInstance newItem) @@ -216,5 +218,17 @@ public partial class InventoryInstance : Node, ISaveable } } } + + /// + /// 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. + /// + private void SaveGameReset() + { + foreach (var slot in _slots) + { + slot.itemInstance = null; + } + } #endregion } diff --git a/scripts/CSharp/Common/Savegame/SavegameService.cs b/scripts/CSharp/Common/Savegame/SavegameService.cs index 8def82e..66f9d47 100644 --- a/scripts/CSharp/Common/Savegame/SavegameService.cs +++ b/scripts/CSharp/Common/Savegame/SavegameService.cs @@ -18,6 +18,9 @@ public static class SavegameService public static Dictionary SaveDatas = new (); public static bool _loaded = false; + + public delegate void SaveGameDelegate(); + public static event SaveGameDelegate OnSaveGameReset = delegate {}; public static void AppendDataToSave( string id, Dictionary payload) @@ -130,5 +133,6 @@ public static class SavegameService { SaveDatas = new (); Save(); + OnSaveGameReset(); } } \ No newline at end of file