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/InspectInputHandler.cs | 70 ++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 scripts/InputHandling/InspectInputHandler.cs (limited to 'scripts/InputHandling/InspectInputHandler.cs') diff --git a/scripts/InputHandling/InspectInputHandler.cs b/scripts/InputHandling/InspectInputHandler.cs new file mode 100644 index 0000000..90734f9 --- /dev/null +++ b/scripts/InputHandling/InspectInputHandler.cs @@ -0,0 +1,70 @@ +using Godot; +using TheLegendOfGustav.Entities.Actions; +using TheLegendOfGustav.Entities.Actors; +using TheLegendOfGustav.Utils; + +namespace TheLegendOfGustav.InputHandling; + +/// +/// TODO: Esta solução é nojenta e precisa ser retrabalhada. +/// +public partial class InspectInputHandler : BaseInputHandler +{ + private static readonly PackedScene InspectorScene = GD.Load("res://scenes/Inspector.tscn"); + + private static readonly Godot.Collections.Dictionary directions = new() + { + {"walk-up", Vector2I.Up}, + {"walk-down", Vector2I.Down}, + {"walk-left", Vector2I.Left}, + {"walk-right", Vector2I.Right}, + {"walk-up-right", Vector2I.Up + Vector2I.Right}, + {"walk-up-left", Vector2I.Up + Vector2I.Left}, + {"walk-down-right", Vector2I.Down + Vector2I.Right}, + {"walk-down-left", Vector2I.Down + Vector2I.Left}, + }; + + /// + /// Preciso disso + /// + [Export] + private Map.Map Map { get; set; } + + private Inspector Inspector { get; set; } + + public override void Enter() + { + SignalBus.Instance.EmitSignal(SignalBus.SignalName.EnterInspectionMode); + Inspector = InspectorScene.Instantiate(); + + Inspector.GridPosition = Map.MapData.Player.GridPosition; + + Map.AddChild(Inspector); + } + + public override void Exit() + { + Inspector.QueueFree(); + + SignalBus.Instance.EmitSignal(SignalBus.SignalName.ExitInspectionMode); + } + + public override Action GetAction(Player player) + { + Action action = null; + foreach (var direction in directions) + { + if (Input.IsActionJustPressed(direction.Key)) + { + Inspector.Walk(direction.Value); + } + } + + if (Input.IsActionJustPressed("quit")) + { + GetParent().SetInputHandler(InputHandlers.MainGame); + } + + return action; + } +} \ No newline at end of file -- cgit v1.2.3