diff options
| author | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-10-26 20:02:15 -0300 |
|---|---|---|
| committer | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-10-26 20:02:15 -0300 |
| commit | f4ed469fc9eaeebf39093fbf6601581cc10c6e2f (patch) | |
| tree | d8f29ae3288e950b5fb1f5251845d57949ca2ac0 /scripts/Entities/Actors/Player.cs | |
| parent | 639cd8cef403e9e66bf31e7888e786effac2b292 (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/Player.cs')
| -rw-r--r-- | scripts/Entities/Actors/Player.cs | 32 |
1 files changed, 31 insertions, 1 deletions
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. /// </summary> [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<string, Variant> GetSaveData() + { + Dictionary<string, Variant> baseData = base.GetSaveData(); + baseData.Add("inventory", Inventory.GetSaveData()); + baseData.Add("definition", definition.ResourcePath); + + return baseData; + } + + public new bool LoadSaveData(Dictionary<string, Variant> saveData) + { + PlayerDefinition definition = GD.Load<PlayerDefinition>((string)saveData["definition"]); + + SetDefinition(definition); + + if (!base.LoadSaveData(saveData)) + { + return false; + } + + if(!Inventory.LoadSaveData((Dictionary<string, Variant>)saveData["inventory"])) + { + return false; + } + + return true; + } + public void SetDefinition(PlayerDefinition definition) { + Inventory?.QueueFree(); Inventory = new(definition.InventoryCapacity); AddChild(Inventory); |
