summaryrefslogtreecommitdiff
path: root/scripts/Entities/Items/ItemEntity.cs
blob: 66944cee4a26b2ea3d40b13065ad20359a21d571 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using Godot;
using Godot.Collections;
using TheLegendOfGustav.Entities;
using TheLegendOfGustav.Map;

namespace TheLegendOfGustav.Entities.Items;

public partial class ItemEntity : Entity, ISaveable
{
	public Item Item { get; private set; }

	public ItemEntity(Vector2I initialPosition, MapData map, Item item) : base(initialPosition, map)
	{
		Item = item;
		// 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);
	}
	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;
	}
}