summaryrefslogtreecommitdiff
path: root/Scripts/Game/Input.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Scripts/Game/Input.cs')
-rw-r--r--Scripts/Game/Input.cs29
1 files changed, 29 insertions, 0 deletions
diff --git a/Scripts/Game/Input.cs b/Scripts/Game/Input.cs
new file mode 100644
index 0000000..2342ac2
--- /dev/null
+++ b/Scripts/Game/Input.cs
@@ -0,0 +1,29 @@
+using Godot;
+
+namespace Texty.Scripts.Game
+{
+ public class Input : PanelContainer
+ {
+ [Signal] public delegate void CommandSubmitted(Command command);
+ [Signal] public delegate void UnknownInputSubmitted(string text);
+
+ private CommandParser CommandParser => GetNodeOrNull<CommandParser>($"%{nameof(CommandParser)}");
+ private Label Prompt => GetNodeOrNull<Label>($"%{nameof(Prompt)}");
+ private LineEdit Text => GetNodeOrNull<LineEdit>($"%{nameof(Text)}");
+
+ public override void _Ready()
+ {
+ Text.GrabFocus();
+ }
+
+ public void OnTextEntered(string text)
+ {
+ Text.Clear();
+ var command = CommandParser.TryParse(text);
+ if (command != null)
+ EmitSignal(nameof(CommandSubmitted), command);
+ else
+ EmitSignal(nameof(UnknownInputSubmitted), text);
+ }
+ }
+} \ No newline at end of file