summaryrefslogtreecommitdiff
path: root/scripts/Utils
diff options
context:
space:
mode:
authorMatheus <matheus.guedes.mg.m@gmail.com>2025-09-09 19:09:34 -0300
committerMatheus <matheus.guedes.mg.m@gmail.com>2025-09-09 19:09:34 -0300
commitc6bbb834f7758027c0df338f1520f34fad3befea (patch)
tree1818cd23c24be16fbe19b16dd0a510874d440d83 /scripts/Utils
parentf1b51bed52ffbd90b5b7cc8dcfc6f0484bbbeb3c (diff)
Organização
Diffstat (limited to 'scripts/Utils')
-rw-r--r--scripts/Utils/Grid.cs12
-rw-r--r--scripts/Utils/Inspector.cs48
-rw-r--r--scripts/Utils/Inspector.cs.uid1
-rw-r--r--scripts/Utils/MessageLogData.cs59
-rw-r--r--scripts/Utils/SignalBus.cs19
5 files changed, 101 insertions, 38 deletions
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;
/// <summary>
/// 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.
/// </summary>
-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;
+
+/// <summary>
+/// Isto é uma abominação
+/// </summary>
+public partial class Inspector : Sprite2D
+{
+ private Vector2I gridPosition = Vector2I.Zero;
+
+
+ /// <summary>
+ /// Posição do inspetor no espaço. Diferentemente de Position, GridPosition tem como formato
+ /// os tiles do mapa.
+ /// </summary>
+ 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>("Camera2D");
+ camera.Enabled = true;
+ camera.MakeCurrent();
+
+ SignalBus.Instance.EmitSignal(SignalBus.SignalName.InspectorMoved, GridPosition);
+ }
+
+ /// <summary>
+ /// O Inspetor não faz parte do mapa.
+ /// </summary>
+ /// <param name="offset"></param>
+ 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
{
+ /// <summary>
+ /// Acionado sempre que uma mensagem for adicionada para o log.
+ /// </summary>
+ /// <param name="text">Mensagem.</param>
+ [Signal]
+ public delegate void messageSentEventHandler(Message message);
+
public static MessageLogData Instance { get; private set; }
- private Godot.Collections.Array<Message> messages = [];
- public Godot.Collections.Array<Message> Messages {get => messages;}
-private Message LastMessage {
- get {
- if (messages.Count <= 0) {
+ public Godot.Collections.Array<Message> 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);
}
-
- /// <summary>
- /// Acionado sempre que uma mensagem for adicionada para o log.
- /// </summary>
- /// <param name="text">Mensagem.</param>
- [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;
/// <summary>
/// Objeto global com sinais, fortes sinais.
@@ -7,16 +8,10 @@ using System;
public partial class SignalBus : Node
{
/// <summary>
- /// Pois é.
- /// </summary>
+ /// Pois é.
+ /// </summary>
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;
+ }
}