summaryrefslogtreecommitdiff
path: root/scripts/Entities/Entity.cs
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/Entities/Entity.cs')
-rw-r--r--scripts/Entities/Entity.cs25
1 files changed, 24 insertions, 1 deletions
diff --git a/scripts/Entities/Entity.cs b/scripts/Entities/Entity.cs
index b7dbcc2..76002b1 100644
--- a/scripts/Entities/Entity.cs
+++ b/scripts/Entities/Entity.cs
@@ -1,4 +1,5 @@
using Godot;
+using Godot.Collections;
using TheLegendOfGustav.Map;
using TheLegendOfGustav.Utils;
@@ -18,7 +19,7 @@ public enum EntityType
/// <summary>
/// Classe para elementos móveis que o jogador pode interagir.
/// </summary>
-public abstract partial class Entity : Sprite2D
+public abstract partial class Entity : Sprite2D, ISaveable
{
private Vector2I gridPosition = Vector2I.Zero;
@@ -138,4 +139,26 @@ public abstract partial class Entity : Sprite2D
Type = definition.Type;
Texture = definition.texture;
}
+
+ public Dictionary<string, Variant> GetSaveData()
+ {
+ return new()
+ {
+ {"position_x", GridPosition.X},
+ {"position_y", GridPosition.Y},
+ {"blocks_movement", BlocksMovement},
+ {"name", DisplayName},
+ {"layer", (int)Type},
+
+ };
+ }
+
+ public bool LoadSaveData(Dictionary<string, Variant> saveData)
+ {
+ GridPosition = new((int)saveData["position_x"], (int)saveData["position_y"]);
+ BlocksMovement = (bool)saveData["blocks_movement"];
+ DisplayName = (string)saveData["name"];
+ Type = (EntityType)(int)saveData["layer"];
+ return true;
+ }
} \ No newline at end of file