Added simple, modular command parsing

This commit is contained in:
2026-04-04 10:08:24 +02:00
parent e41332cf85
commit 20158802dd
11 changed files with 164 additions and 10 deletions
+34 -10
View File
@@ -1,5 +1,6 @@
using Godot;
using System;
using YourProject.Commands; // Add this using statement
public partial class ConsoleUI : CanvasLayer
{
@@ -10,27 +11,50 @@ public partial class ConsoleUI : CanvasLayer
{
consoleOutput = GetNode<Label>("ConsoleOutput");
consoleInput = GetNode<LineEdit>("ConsoleInput");
consoleInput.TextSubmitted += OnTextSubmitted;
consoleInput.GrabFocus();
Callable.From(() => consoleInput.GrabFocus()).CallDeferred();
}
private void OnTextSubmitted(string submittedText)
{
if (!string.IsNullOrWhiteSpace(submittedText))
if (string.IsNullOrWhiteSpace(submittedText))
{
string currentOutput = consoleOutput.Text;
if (!string.IsNullOrEmpty(currentOutput))
consoleInput.Clear();
return;
}
AddToConsole($"> {submittedText}");
bool commandExecuted = ConsoleManager.Execute(submittedText, (output) =>
{
if (output == "CLEAR_CONSOLE")
{
consoleOutput.Text = currentOutput + "\n" + submittedText;
consoleOutput.Text = "";
}
else
{
consoleOutput.Text = submittedText;
AddToConsole(output);
}
consoleInput.Clear();
});
if (!commandExecuted)
{
AddToConsole($"Unknown command. Type 'help' for available commands.");
}
consoleInput.Clear();
Callable.From(() => consoleInput.GrabFocus()).CallDeferred();
}
private void AddToConsole(string text)
{
if (string.IsNullOrEmpty(consoleOutput.Text))
{
consoleOutput.Text = text;
}
else
{
consoleOutput.Text += "\n" + text;
}
}
}