Starting a new game resets the inventory now

This commit is contained in:
2025-12-02 12:08:19 +01:00
parent b6caf4dbed
commit c7a4aea70b
2 changed files with 19 additions and 1 deletions
@@ -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
}
}
}
/// <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
}
@@ -18,6 +18,9 @@ public static class SavegameService
public static Dictionary<string, string> SaveDatas = new ();
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)
@@ -130,5 +133,6 @@ public static class SavegameService
{
SaveDatas = new ();
Save();
OnSaveGameReset();
}
}