From f4ed469fc9eaeebf39093fbf6601581cc10c6e2f Mon Sep 17 00:00:00 2001 From: Matheus Date: Sun, 26 Oct 2025 20:02:15 -0300 Subject: feat:save AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit O vazio dentro de mim é como uma xícara de café esquecida no canto da mesa. --- scripts/Map/Tile.cs | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) (limited to 'scripts/Map/Tile.cs') diff --git a/scripts/Map/Tile.cs b/scripts/Map/Tile.cs index 488d124..6790f3e 100644 --- a/scripts/Map/Tile.cs +++ b/scripts/Map/Tile.cs @@ -1,16 +1,41 @@ +using System.Threading; using Godot; +using Godot.Collections; using TheLegendOfGustav.Utils; namespace TheLegendOfGustav.Map; +public enum TileType +{ + WALL, + FLOOR +} + /// /// O mundo do jogo é composto por Tiles. /// Um tile é um quadrado de 16x16 que representa uma /// unidade discreta do cenário. Tiles podem agir como /// parede, chão, ou outras funções. /// -public partial class Tile : Sprite2D +public partial class Tile : Sprite2D, ISaveable { + private static readonly Godot.Collections.Dictionary Types = new() + { + {TileType.WALL, GD.Load("res://assets/definitions/tiles/wall.tres")}, + {TileType.FLOOR, GD.Load("res://assets/definitions/tiles/floor.tres")} + }; + + TileType key; + public TileType Key + { + get => key; + set + { + key = value; + SetDefinition(Types[value]); + } + } + private bool isExplored = false; private bool isInView = false; @@ -19,7 +44,7 @@ public partial class Tile : Sprite2D /// private TileDefinition definition; - public Tile(Vector2I pos, TileDefinition definition) + public Tile(Vector2I pos, TileType type) { // Tile herda da classe Sprite2D. // Por padrão, a posição do Sprite2D é no centro de sua textura. @@ -29,7 +54,7 @@ public partial class Tile : Sprite2D // Tiles começam invisíveis porque não foram vistos pelo jogador. Visible = false; Position = Grid.GridToWorld(pos); - SetDefinition(definition); + Key = type; } /// @@ -89,4 +114,22 @@ public partial class Tile : Sprite2D IsWalkable = definition.IsWalkable; IsTransparent = definition.IsTransparent; } + + public Dictionary GetSaveData() + { + return new() + { + {"key", (int)Key}, + {"is_explored", IsExplored} + }; + } + + public bool LoadSaveData(Dictionary saveData) + { + // É o seguinte, não tenho tempo, não vou verificar se a entrada está correta. + Key = (TileType)(int)saveData["key"]; + + IsExplored = (bool)saveData["is_explored"]; + return true; + } } -- cgit v1.2.3