summaryrefslogtreecommitdiff
path: root/scripts/InputHandling/InputHandler.cs
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/InputHandling/InputHandler.cs
parentf1b51bed52ffbd90b5b7cc8dcfc6f0484bbbeb3c (diff)
Organização
Diffstat (limited to 'scripts/InputHandling/InputHandler.cs')
-rw-r--r--scripts/InputHandling/InputHandler.cs58
1 files changed, 58 insertions, 0 deletions
diff --git a/scripts/InputHandling/InputHandler.cs b/scripts/InputHandling/InputHandler.cs
new file mode 100644
index 0000000..55a17b4
--- /dev/null
+++ b/scripts/InputHandling/InputHandler.cs
@@ -0,0 +1,58 @@
+using Godot;
+using TheLegendOfGustav.Entities.Actions;
+using TheLegendOfGustav.Entities.Actors;
+
+namespace TheLegendOfGustav.InputHandling;
+
+public enum InputHandlers
+{
+ MainGame,
+ GameOver,
+ Inspect,
+ Pickup,
+ Inventory
+}
+
+/// <summary>
+/// Máquina de estado que obtém ações do usuário conforme o estado atual do jogo.
+/// </summary>
+public partial class InputHandler : Node
+{
+ [Export]
+ private InputHandlers StartingInputHandler { get; set; }
+
+ private Godot.Collections.Dictionary<InputHandlers, BaseInputHandler> InputHandlerDict { get; set; } = [];
+
+ private BaseInputHandler SelectedInputHandler { get; set; }
+
+ public override void _Ready()
+ {
+ base._Ready();
+ // Controles para quando o jogador está vivo e jogando normalmente.
+ InputHandlerDict.Add(InputHandlers.MainGame, GetNode<MainGameInputHandler>("MainGameInputHandler"));
+ // Controles para quando o jogador está morto.
+ InputHandlerDict.Add(InputHandlers.GameOver, GetNode<GameOverInputHandler>("GameOverInputHandler"));
+ InputHandlerDict.Add(InputHandlers.Inspect, GetNode<InspectInputHandler>("InspectInputHandler"));
+ InputHandlerDict.Add(InputHandlers.Pickup, GetNode<PickupInputHandler>("PickupInputHandler"));
+ InputHandlerDict.Add(InputHandlers.Inventory, GetNode<InventoryInputHandler>("InventoryInputHandler"));
+
+ SetInputHandler(StartingInputHandler);
+ }
+
+ public Action GetAction(Player player)
+ {
+ return SelectedInputHandler.GetAction(player);
+ }
+
+ /// <summary>
+ /// Define o esquema de controle atual do jogo
+ /// para o estado informado.
+ /// </summary>
+ /// <param name="inputhandler">Estado do jogo.</param>
+ public void SetInputHandler(InputHandlers inputhandler)
+ {
+ SelectedInputHandler?.Exit();
+ SelectedInputHandler = InputHandlerDict[inputhandler];
+ SelectedInputHandler.Enter();
+ }
+}