blob: 2f1fc097d4ff50981137fc295e1ba198987230c2 (
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
30
31
32
|
using Godot;
using Texty.Scripts.Terminal;
namespace Texty.Scripts.Game
{
[Tool]
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);
}
}
}
|