From f4ed469fc9eaeebf39093fbf6601581cc10c6e2f Mon Sep 17 00:00:00 2001 From: Matheus Date: Sun, 26 Oct 2025 20:02:15 -0300 Subject: feat:save AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit O vazio dentro de mim é como uma xícara de café esquecida no canto da mesa. --- scripts/Entities/Actors/Inventory.cs | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'scripts/Entities/Actors/Inventory.cs') 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 GetSaveData() + { + Godot.Collections.Array> itemsData = []; + foreach (Item item in Items) { + itemsData.Add(item.GetSaveData()); + } + + return new() + { + {"items", itemsData} + }; + } + + public bool LoadSaveData(Dictionary saveData) + { + Array> itemRess = (Array>)saveData["items"]; + + foreach(Dictionary item in itemRess) + { + Item it = new(); + if(!it.LoadSaveData(item)) + { + return false; + } + + Items.Add(it); + } + + return true; + } } \ No newline at end of file -- cgit v1.2.3