SupaLidlGame/Debug/Entry.cs

67 lines
1.5 KiB
C#
Raw Normal View History

2023-09-24 18:51:23 -07:00
using Godot;
2023-09-29 11:32:15 -07:00
using GodotUtilities;
using System.Linq;
2023-09-24 18:51:23 -07:00
namespace SupaLidlGame.Debug;
public partial class Entry : CodeEdit
2023-09-24 18:51:23 -07:00
{
[Signal]
public delegate void ConsoleInputEventHandler(string input);
public override void _Ready()
{
GuiInput += OnGuiInput;
2023-09-29 11:32:15 -07:00
AddStringDelimiter("\'", "\"", true);
AddStringDelimiter("'", "'", true);
2023-09-24 18:51:23 -07:00
}
/*
public override void _Input(InputEvent @event)
{
if (HasFocus())
{
if (@event is InputEventKey && @event.IsPressed())
{
AcceptEvent();
OnGuiInput(@event);
}
}
}
*/
2023-09-24 18:51:23 -07:00
public void OnGuiInput(InputEvent @event)
{
2023-09-29 11:32:15 -07:00
if (@event is InputEventKey key && key.Pressed)
2023-09-24 18:51:23 -07:00
{
if (key.KeyLabel == Key.Enter)
2023-09-24 18:51:23 -07:00
{
AcceptEvent();
2023-09-29 11:32:15 -07:00
if (key.Pressed)
2023-09-24 18:51:23 -07:00
{
EmitSignal(SignalName.ConsoleInput, Text);
if (!key.IsCommandOrControlPressed())
{
Text = "";
}
2023-09-24 18:51:23 -07:00
}
}
}
}
2023-09-29 11:32:15 -07:00
public void SetContext(Node context)
{
var properties = context.GetPropertyList();
var propNames = properties.Select((prop) => prop["name"].ToString());
foreach (var prop in propNames)
{
AddCodeCompletionOption(
CodeCompletionKind.Member,
prop, prop);
}
UpdateCodeCompletionOptions(true);
}
2023-09-24 18:51:23 -07:00
}