summaryrefslogtreecommitdiff
path: root/scripts/Entities/Actors/Inventory.cs
diff options
context:
space:
mode:
authorMatheus <matheus.guedes.mg.m@gmail.com>2025-10-26 20:02:15 -0300
committerMatheus <matheus.guedes.mg.m@gmail.com>2025-10-26 20:02:15 -0300
commitf4ed469fc9eaeebf39093fbf6601581cc10c6e2f (patch)
treed8f29ae3288e950b5fb1f5251845d57949ca2ac0 /scripts/Entities/Actors/Inventory.cs
parent639cd8cef403e9e66bf31e7888e786effac2b292 (diff)
feat:save AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
O vazio dentro de mim é como uma xícara de café esquecida no canto da mesa.
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