Starting a new game resets the inventory now

pull/34/head
kziolkowski 1 month ago
parent b6caf4dbed
commit c7a4aea70b

@ -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();
}
}
Loading…
Cancel
Save