blob: 2342ac29cf52a99541fea695cc1fd3f2850cc285 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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);
}
}
}
|