From c6bbb834f7758027c0df338f1520f34fad3befea Mon Sep 17 00:00:00 2001 From: Matheus Date: Tue, 9 Sep 2025 19:09:34 -0300 Subject: Organização MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/Utils/Grid.cs | 12 ++++++--- scripts/Utils/Inspector.cs | 48 +++++++++++++++++++++++++++++++++ scripts/Utils/Inspector.cs.uid | 1 + scripts/Utils/MessageLogData.cs | 59 ++++++++++++++++++++++++----------------- scripts/Utils/SignalBus.cs | 19 ++++++------- 5 files changed, 101 insertions(+), 38 deletions(-) create mode 100644 scripts/Utils/Inspector.cs create mode 100644 scripts/Utils/Inspector.cs.uid (limited to 'scripts/Utils') diff --git a/scripts/Utils/Grid.cs b/scripts/Utils/Grid.cs index 271f559..b744c60 100644 --- a/scripts/Utils/Grid.cs +++ b/scripts/Utils/Grid.cs @@ -1,5 +1,6 @@ using Godot; -using System; + +namespace TheLegendOfGustav.Utils; /// /// Classe utilitária para converter coordenadas da malha dos tiles @@ -7,14 +8,17 @@ using System; /// Esta classe é necessária porque o Godot trata posições em pixels, /// mas faz mais sentido tratarmos as posições em tiles. /// -public abstract partial class Grid : GodotObject { +public abstract partial class Grid : GodotObject +{ public static readonly Vector2I tileSize = new(16, 16); - public static Vector2I WorldToGrid(Vector2 coord) { + public static Vector2I WorldToGrid(Vector2 coord) + { return (Vector2I)(coord / tileSize); } - public static Vector2 GridToWorld(Vector2I coord) { + public static Vector2 GridToWorld(Vector2I coord) + { return coord * tileSize; } } diff --git a/scripts/Utils/Inspector.cs b/scripts/Utils/Inspector.cs new file mode 100644 index 0000000..7fb12ff --- /dev/null +++ b/scripts/Utils/Inspector.cs @@ -0,0 +1,48 @@ +using Godot; + +namespace TheLegendOfGustav.Utils; + +/// +/// Isto é uma abominação +/// +public partial class Inspector : Sprite2D +{ + private Vector2I gridPosition = Vector2I.Zero; + + + /// + /// Posição do inspetor no espaço. Diferentemente de Position, GridPosition tem como formato + /// os tiles do mapa. + /// + public Vector2I GridPosition + { + set + { + gridPosition = value; + // O sistema de coordenadas do Godot é em pixels, mas faz mais sentido para o jogo utilizar coordenadas em tiles. + // Esta propriedade converte um sistema para o outro automaticamente. + Position = Grid.GridToWorld(value); + } + get => gridPosition; + } + + public override void _Ready() + { + base._Ready(); + Camera2D camera = GetNode("Camera2D"); + camera.Enabled = true; + camera.MakeCurrent(); + + SignalBus.Instance.EmitSignal(SignalBus.SignalName.InspectorMoved, GridPosition); + } + + /// + /// O Inspetor não faz parte do mapa. + /// + /// + public void Walk(Vector2I offset) + { + GridPosition += offset; + SignalBus.Instance.EmitSignal(SignalBus.SignalName.InspectorMoved, GridPosition); + } +} \ No newline at end of file diff --git a/scripts/Utils/Inspector.cs.uid b/scripts/Utils/Inspector.cs.uid new file mode 100644 index 0000000..ca411e4 --- /dev/null +++ b/scripts/Utils/Inspector.cs.uid @@ -0,0 +1 @@ +uid://dxsrtu4b3pi08 diff --git a/scripts/Utils/MessageLogData.cs b/scripts/Utils/MessageLogData.cs index e8f0f09..46d2c3e 100644 --- a/scripts/Utils/MessageLogData.cs +++ b/scripts/Utils/MessageLogData.cs @@ -1,25 +1,30 @@ using Godot; +using TheLegendOfGustav.GUI; + +namespace TheLegendOfGustav.Utils; public partial class MessageLogData : Node { + /// + /// Acionado sempre que uma mensagem for adicionada para o log. + /// + /// Mensagem. + [Signal] + public delegate void messageSentEventHandler(Message message); + public static MessageLogData Instance { get; private set; } - private Godot.Collections.Array messages = []; - public Godot.Collections.Array Messages {get => messages;} -private Message LastMessage { - get { - if (messages.Count <= 0) { + public Godot.Collections.Array Messages { get; private set; } = []; + + private Message LastMessage + { + get + { + if (Messages.Count <= 0) + { return null; } - return messages[^1]; - } - } - - public void ClearMessages() { - for (int i = messages.Count - 1; i >= 0; i--) { - Message message = messages[i]; - messages.RemoveAt(i); - message.QueueFree(); + return Messages[^1]; } } @@ -29,22 +34,26 @@ private Message LastMessage { Instance = this; } - public void AddMessage(string text) { - if (LastMessage != null && LastMessage.PlainText == text) { + public void ClearMessages() + { + for (int i = Messages.Count - 1; i >= 0; i--) + { + Message message = Messages[i]; + Messages.RemoveAt(i); + message.QueueFree(); + } + } + + public void AddMessage(string text) + { + if (LastMessage != null && LastMessage.PlainText == text) + { LastMessage.Count++; return; } Message message = new(text); - messages.Add(message); + Messages.Add(message); EmitSignal(SignalName.messageSent, message); } - - /// - /// Acionado sempre que uma mensagem for adicionada para o log. - /// - /// Mensagem. - [Signal] - public delegate void messageSentEventHandler(Message message); - } \ No newline at end of file diff --git a/scripts/Utils/SignalBus.cs b/scripts/Utils/SignalBus.cs index edeb09b..a2aa6ca 100644 --- a/scripts/Utils/SignalBus.cs +++ b/scripts/Utils/SignalBus.cs @@ -1,5 +1,6 @@ using Godot; -using System; + +namespace TheLegendOfGustav.Utils; /// /// Objeto global com sinais, fortes sinais. @@ -7,16 +8,10 @@ using System; public partial class SignalBus : Node { /// - /// Pois é. - /// + /// Pois é. + /// public static SignalBus Instance { get; private set; } - public override void _Ready() - { - base._Ready(); - Instance = this; - } - [Signal] public delegate void InspectorMovedEventHandler(Vector2I pos); @@ -24,4 +19,10 @@ public partial class SignalBus : Node public delegate void EnterInspectionModeEventHandler(); [Signal] public delegate void ExitInspectionModeEventHandler(); + + public override void _Ready() + { + base._Ready(); + Instance = this; + } } -- cgit v1.2.3