✨ Starting a new game resets the inventory now
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -19,6 +19,9 @@ public static class SavegameService
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user