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/Player.cs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'scripts/Entities/Actors/Player.cs') diff --git a/scripts/Entities/Actors/Player.cs b/scripts/Entities/Actors/Player.cs index d6fedb9..7304e0a 100644 --- a/scripts/Entities/Actors/Player.cs +++ b/scripts/Entities/Actors/Player.cs @@ -1,4 +1,5 @@ using Godot; +using Godot.Collections; using TheLegendOfGustav.Map; namespace TheLegendOfGustav.Entities.Actors; @@ -7,7 +8,7 @@ namespace TheLegendOfGustav.Entities.Actors; /// Classe do jogador. Por enquanto não é diferente do Ator, mas isso pode mudar. /// [GlobalClass] -public partial class Player : Actor +public partial class Player : Actor, ISaveable { private PlayerDefinition definition; @@ -19,8 +20,37 @@ public partial class Player : Actor public Inventory Inventory { get; private set; } + public new Dictionary GetSaveData() + { + Dictionary baseData = base.GetSaveData(); + baseData.Add("inventory", Inventory.GetSaveData()); + baseData.Add("definition", definition.ResourcePath); + + return baseData; + } + + public new bool LoadSaveData(Dictionary saveData) + { + PlayerDefinition definition = GD.Load((string)saveData["definition"]); + + SetDefinition(definition); + + if (!base.LoadSaveData(saveData)) + { + return false; + } + + if(!Inventory.LoadSaveData((Dictionary)saveData["inventory"])) + { + return false; + } + + return true; + } + public void SetDefinition(PlayerDefinition definition) { + Inventory?.QueueFree(); Inventory = new(definition.InventoryCapacity); AddChild(Inventory); -- cgit v1.2.3