blob: af54a15588c0f717a980ca4f34752fab322eb49d (
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 partial class CommandInputArea : InputArea
{
[Signal] public delegate void CommandSubmittedEventHandler(Command command);
[Signal] public delegate void UnknownInputSubmittedEventHandler(string text);
private CommandParser CommandParser => GetNodeOrNull<CommandParser>($"%{nameof(CommandParser)}");
public override void _Ready()
{
TextInput.GrabFocus();
}
public override void OnTextEntered(string text)
{
if (text.Length == 0)
return;
TextInput.Clear();
var command = CommandParser.TryParse(text);
if (command != null)
EmitSignal(SignalName.CommandSubmitted, command);
else
EmitSignal(SignalName.UnknownInputSubmitted, text);
}
}
}
|