summaryrefslogtreecommitdiff
path: root/scripts/Entities/Actors/Inventory.cs
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/Entities/Actors/Inventory.cs')
-rw-r--r--scripts/Entities/Actors/Inventory.cs34
1 files changed, 33 insertions, 1 deletions
diff --git a/scripts/Entities/Actors/Inventory.cs b/scripts/Entities/Actors/Inventory.cs
index 5ae61b4..ebc60e4 100644
--- a/scripts/Entities/Actors/Inventory.cs
+++ b/scripts/Entities/Actors/Inventory.cs
@@ -1,11 +1,12 @@
using Godot;
+using Godot.Collections;
using TheLegendOfGustav.Entities.Items;
using TheLegendOfGustav.Map;
using TheLegendOfGustav.Utils;
namespace TheLegendOfGustav.Entities.Actors;
-public partial class Inventory(int capacity) : Node
+public partial class Inventory(int capacity) : Node, ISaveable
{
private Player player;
public int Capacity { get; private set; } = capacity;
@@ -42,4 +43,35 @@ public partial class Inventory(int capacity) : Node
{
Items.Remove(item);
}
+
+ public Dictionary<string, Variant> GetSaveData()
+ {
+ Godot.Collections.Array<Dictionary<string, Variant>> itemsData = [];
+ foreach (Item item in Items) {
+ itemsData.Add(item.GetSaveData());
+ }
+
+ return new()
+ {
+ {"items", itemsData}
+ };
+ }
+
+ public bool LoadSaveData(Dictionary<string, Variant> saveData)
+ {
+ Array<Dictionary<string, Variant>> itemRess = (Array<Dictionary<string, Variant>>)saveData["items"];
+
+ foreach(Dictionary<string, Variant> item in itemRess)
+ {
+ Item it = new();
+ if(!it.LoadSaveData(item))
+ {
+ return false;
+ }
+
+ Items.Add(it);
+ }
+
+ return true;
+ }
} \ No newline at end of file