diff --git a/scripts/CSharp/Common/Inventory/InventoryInstance.cs b/scripts/CSharp/Common/Inventory/InventoryInstance.cs
index d1c7b50..3ec2ba0 100644
--- a/scripts/CSharp/Common/Inventory/InventoryInstance.cs
+++ b/scripts/CSharp/Common/Inventory/InventoryInstance.cs
@@ -3,6 +3,9 @@ using System;
using Godot;
using System.Collections.Generic;
using System.Linq;
+using Babushka.scripts.CSharp.Common.Farming;
+using Babushka.scripts.CSharp.Common.Savegame;
+using Godot.Collections;
namespace Babushka.scripts.CSharp.Common.Inventory;
@@ -17,6 +20,9 @@ public partial class InventoryInstance : Node
[Signal]
public delegate void InventoryContentsChangedEventHandler();
+ private const string SCENE_NAME = "inventory";
+ private const string ID = "instace";
+
///
/// The total amount of Inventoryslots in the inventory (empty and occupied).
///
@@ -156,4 +162,51 @@ public partial class InventoryInstance : Node
{
return items.All(HasItems);
}
+
+ #region SAVE AND LOAD
+
+ public void UpdateSaveData()
+ {
+ var saveData = new SaveData();
+
+ saveData.SceneName = SCENE_NAME;
+ saveData.Id = ID;
+ var payloadData = new Godot.Collections.Dictionary();
+
+ for (int i = 0; i < _slots.Count; i++)
+ {
+ if (!_slots[i].IsEmpty())
+ {
+ string key = i.ToString();
+ string[] value = new string[2];
+ value[0] = _slots[i].itemInstance.blueprint.ResourcePath;
+ value[1] = _slots[i].itemInstance.amount.ToString();
+ payloadData.Add(key,value);
+ }
+ }
+
+ saveData.JsonPayload = Json.Stringify(payloadData, indent: "\t");
+
+ SavegameService.AppendSave(saveData);
+ }
+
+ public void LoadFromSaveData()
+ {
+ var sceneName = SCENE_NAME;
+ var id = ID;
+ string jsonPayload = SavegameService.GetSaveData(sceneName, id);
+ Godot.Collections.Dictionary save = Json.ParseString(jsonPayload).AsGodotDictionary();
+
+ if (save.Count > 0)
+ {
+ for (int i = 0; i < _slots.Count; i++)
+ {
+ if (save.TryGetValue(i.ToString(), out Variant inventoryItem))
+ {
+ // todo: we have the resource paths and amounts, but how do we get to ItemResources and ItemInstances?
+ }
+ }
+ }
+ }
+ #endregion
}