diff options
Diffstat (limited to 'Scripts/Game/CommandInputArea.cs')
| -rw-r--r-- | Scripts/Game/CommandInputArea.cs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Scripts/Game/CommandInputArea.cs b/Scripts/Game/CommandInputArea.cs new file mode 100644 index 0000000..7d0ba5c --- /dev/null +++ b/Scripts/Game/CommandInputArea.cs @@ -0,0 +1,31 @@ +using Godot; +using Texty.Scripts.Terminal; + +namespace Texty.Scripts.Game +{ + public class CommandInputArea : InputArea + { + [Signal] public delegate void CommandSubmitted(Command command); + [Signal] public delegate void UnknownInputSubmitted(string text); + + private CommandParser CommandParser => GetNodeOrNull<CommandParser>($"%{nameof(CommandParser)}"); + + public override void _Ready() + { + TextInput.GrabFocus(); + } + + public override void OnTextEntered(string text) + { + if (text.Empty()) + return; + + TextInput.Clear(); + var command = CommandParser.TryParse(text); + if (command != null) + EmitSignal(nameof(CommandSubmitted), command); + else + EmitSignal(nameof(UnknownInputSubmitted), text); + } + } +}
\ No newline at end of file |
