feat: add in-game debug console UI
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
using Game.Features.Console.Application.Commands;
|
||||
using Game.Features.Console.Godot;
|
||||
using Game.Features.Console.Infrastructure;
|
||||
using Game.Godot;
|
||||
using Game.Godot.Extensions;
|
||||
using Game.Godot.Mappings;
|
||||
using Godot;
|
||||
|
||||
@@ -6,9 +10,24 @@ namespace Game.Godot.Bootstrap;
|
||||
|
||||
public partial class GameBootstrap : Node
|
||||
{
|
||||
[Export] public ConsoleController Console;
|
||||
|
||||
private void RegisterConsoleCommands()
|
||||
{
|
||||
CommandRegistry registry = new();
|
||||
registry.Register(new HelpCommand(registry));
|
||||
registry.Register(new EchoCommand());
|
||||
registry.Register(new ClearCommand());
|
||||
|
||||
Console.UseCommandRegistry(registry);
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
this.AssertRequiredExports();
|
||||
|
||||
MouseCapture.Capture();
|
||||
RegisterConsoleCommands();
|
||||
}
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
using Godot;
|
||||
|
||||
namespace Game.Godot;
|
||||
|
||||
public static class GamePause
|
||||
{
|
||||
private static SceneTree Tree => (SceneTree)Engine.GetMainLoop();
|
||||
|
||||
public static bool IsPaused => Tree.Paused;
|
||||
|
||||
public static void Pause() => Tree.Paused = true;
|
||||
|
||||
public static void Resume() => Tree.Paused = false;
|
||||
|
||||
public static void Toggle()
|
||||
{
|
||||
if (IsPaused)
|
||||
{
|
||||
Resume();
|
||||
}
|
||||
else
|
||||
{
|
||||
Pause();
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetIgnoresPause(Node node, bool value) =>
|
||||
node.ProcessMode = value ? Node.ProcessModeEnum.Always : Node.ProcessModeEnum.Inherit;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://i7fuhrb208r8
|
||||
@@ -9,7 +9,8 @@ public enum InputAction
|
||||
MoveForward,
|
||||
MoveBack,
|
||||
Jump,
|
||||
Cancel
|
||||
Cancel,
|
||||
ToggleConsole
|
||||
}
|
||||
|
||||
public static class InputActionExtensions
|
||||
@@ -25,6 +26,7 @@ public static class InputActionExtensions
|
||||
InputAction.MoveBack => "move_back",
|
||||
InputAction.Jump => "jump",
|
||||
InputAction.Cancel => "ui_cancel",
|
||||
InputAction.ToggleConsole => "toggle_console",
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(action), action, null)
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user