summaryrefslogtreecommitdiff
path: root/scripts/Entities/Actors/Player.cs
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/Entities/Actors/Player.cs')
-rw-r--r--scripts/Entities/Actors/Player.cs32
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);