summaryrefslogtreecommitdiff
path: root/Scripts/Game/Input.cs
diff options
context:
space:
mode:
authorSophia Pearson <codergal89@gmail.com>2022-09-04 15:43:12 +0200
committerSophia Pearson <codergal89@gmail.com>2022-09-04 15:44:04 +0200
commit2f3abbb6f1141f15ef77ac27e431bc66bb0c7899 (patch)
tree17f7ee50161e1de1c11c6dd14a54a11614e7de03 /Scripts/Game/Input.cs
parent0967a4654c9fa67b5cfc19edf3cfc075bf6bde92 (diff)
downloadtexty-2f3abbb6f1141f15ef77ac27e431bc66bb0c7899.tar.xz
texty-2f3abbb6f1141f15ef77ac27e431bc66bb0c7899.zip
game: adapt scripts to new design
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