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/InputHandling/InputHandler.cs | 58 +++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 scripts/InputHandling/InputHandler.cs (limited to 'scripts/InputHandling/InputHandler.cs') 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 +} + +/// +/// Máquina de estado que obtém ações do usuário conforme o estado atual do jogo. +/// +public partial class InputHandler : Node +{ + [Export] + private InputHandlers StartingInputHandler { get; set; } + + private Godot.Collections.Dictionary 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")); + // Controles para quando o jogador está morto. + InputHandlerDict.Add(InputHandlers.GameOver, GetNode("GameOverInputHandler")); + InputHandlerDict.Add(InputHandlers.Inspect, GetNode("InspectInputHandler")); + InputHandlerDict.Add(InputHandlers.Pickup, GetNode("PickupInputHandler")); + InputHandlerDict.Add(InputHandlers.Inventory, GetNode("InventoryInputHandler")); + + SetInputHandler(StartingInputHandler); + } + + public Action GetAction(Player player) + { + return SelectedInputHandler.GetAction(player); + } + + /// + /// Define o esquema de controle atual do jogo + /// para o estado informado. + /// + /// Estado do jogo. + public void SetInputHandler(InputHandlers inputhandler) + { + SelectedInputHandler?.Exit(); + SelectedInputHandler = InputHandlerDict[inputhandler]; + SelectedInputHandler.Enter(); + } +} -- cgit v1.2.3