summaryrefslogtreecommitdiff
path: root/Scripts/Game/CommandInputArea.cs
diff options
context:
space:
mode:
authorSophia Pearson <codergal89@gmail.com>2022-09-05 20:35:53 +0200
committerSophia Pearson <codergal89@gmail.com>2022-09-05 20:35:53 +0200
commitf20bd89dc4a7bf14a88b1effcaa1887b29314525 (patch)
treed114787f68efd2a7d61d95fa9c84e8e5d69a7c11 /Scripts/Game/CommandInputArea.cs
parent1b477b62f8be8c546a35dbd1d2688ebf623c496f (diff)
downloadtexty-f20bd89dc4a7bf14a88b1effcaa1887b29314525.tar.xz
texty-f20bd89dc4a7bf14a88b1effcaa1887b29314525.zip
gui: split GUI into Terminal components
Diffstat (limited to 'Scripts/Game/CommandInputArea.cs')
-rw-r--r--Scripts/Game/CommandInputArea.cs31
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