diff options
Diffstat (limited to 'scripts/Entities/Items')
| -rw-r--r-- | scripts/Entities/Items/Item.cs | 24 | ||||
| -rw-r--r-- | scripts/Entities/Items/ItemEntity.cs | 40 |
2 files changed, 61 insertions, 3 deletions
diff --git a/scripts/Entities/Items/Item.cs b/scripts/Entities/Items/Item.cs index 0eeffd8..17c318c 100644 --- a/scripts/Entities/Items/Item.cs +++ b/scripts/Entities/Items/Item.cs @@ -1,11 +1,12 @@ using System.Reflection.Metadata; using Godot; +using Godot.Collections; using TheLegendOfGustav.Entities.Actions; using TheLegendOfGustav.Entities.Actors; namespace TheLegendOfGustav.Entities.Items; -public partial class Item : RefCounted +public partial class Item : RefCounted, ISaveable { public Item(ItemResource definition) @@ -14,6 +15,10 @@ public partial class Item : RefCounted Uses = Definition.MaxUses; } + public Item() + { + } + public ItemResource Definition { get; private set; } public int Uses { get; set; } @@ -58,4 +63,21 @@ public partial class Item : RefCounted Inventory inventory = consumer.Inventory; inventory.RemoveItem(this); } + + public Dictionary<string, Variant> GetSaveData() + { + return new() + { + {"definition", Definition.ResourcePath}, + {"uses", Uses} + }; + } + + public bool LoadSaveData(Dictionary<string, Variant> saveData) + { + Definition = GD.Load<ItemResource>((string)saveData["definition"]); + Uses = (int)saveData["uses"]; + + return true; + } }
\ No newline at end of file diff --git a/scripts/Entities/Items/ItemEntity.cs b/scripts/Entities/Items/ItemEntity.cs index e646e40..66944ce 100644 --- a/scripts/Entities/Items/ItemEntity.cs +++ b/scripts/Entities/Items/ItemEntity.cs @@ -1,10 +1,11 @@ using Godot; +using Godot.Collections; using TheLegendOfGustav.Entities; using TheLegendOfGustav.Map; namespace TheLegendOfGustav.Entities.Items; -public partial class ItemEntity : Entity +public partial class ItemEntity : Entity, ISaveable { public Item Item { get; private set; } @@ -14,7 +15,7 @@ public partial class ItemEntity : Entity // Eu quero muito reescrever o jogo do zero, mas não tenho tempo :( EntityDefinition sad = new() { - blocksMovement = true, + blocksMovement = false, name = item.Definition.DisplayName, texture = item.Definition.Icon, Type = EntityType.ITEM, @@ -22,4 +23,39 @@ public partial class ItemEntity : Entity SetDefinition(sad); } + public ItemEntity(Vector2I initialPosition, MapData map) : base(initialPosition, map) + { + } + + public new Dictionary<string, Variant> GetSaveData() + { + Dictionary<string, Variant> baseData = base.GetSaveData(); + baseData.Add("item", Item.GetSaveData()); + + return baseData; + } + + public new bool LoadSaveData(Dictionary<string, Variant> saveData) + { + Item = new(); + + if (!Item.LoadSaveData((Dictionary<string, Variant>)saveData["item"])) + { + return false; + } + // Eu quero muito reescrever o jogo do zero, mas não tenho tempo :( + EntityDefinition sad = new() + { + blocksMovement = false, + name = Item.Definition.DisplayName, + texture = Item.Definition.Icon, + Type = EntityType.ITEM, + }; + + SetDefinition(sad); + + base.LoadSaveData(saveData); + + return true; + } }
\ No newline at end of file |
