Add debug foundation

This commit is contained in:
2026-04-21 21:16:30 +02:00
parent 693f31dd50
commit cc51f4a6e8
22 changed files with 1246 additions and 12 deletions

View File

@@ -1,6 +1,8 @@
#nullable enable
using System.Globalization;
using Godot;
using SideScrollerGame.Debug.Commands;
namespace SideScrollerGame.Debug;
@@ -15,10 +17,34 @@ public partial class DebugOverlay : CanvasLayer
public void SetStatus(DebugSettings settings, string loadedSceneId)
{
m_Settings = settings;
m_LoadedSceneId = loadedSceneId;
Label label = EnsureLabel();
label.Text = $"Debug boot: {settings.BootMode}\nSeed: {settings.Seed}\nScene: {loadedSceneId}\nDebug: {OS.IsDebugBuild()}";
}
public void Bind(DebugCommandService service, DebugSettings settings, string loadedSceneId)
{
m_Service = service;
m_Settings = settings;
m_LoadedSceneId = loadedSceneId;
service.StateChanged += _ => Refresh();
Refresh();
}
private void Refresh()
{
Label label = EnsureLabel();
if (m_Service is null || m_Settings is null)
{
return;
}
DebugRuntimeState state = m_Service.State;
Visible = state.OverlayVisible;
label.Text = $"Debug boot: {m_Settings.BootMode}\n" + $"Scene: {m_LoadedSceneId}\n" + $"Seed: {state.Seed}\n" + $"Difficulty: {state.ActiveDifficultyId}\n" + $"Paused: {state.IsPaused}\n" + $"Time scale: {state.TimeScale.ToString(CultureInfo.InvariantCulture)}\n" + $"Marker: {DisplayOrNone(state.CurrentMarkerId)}\n" + $"Spawned: {state.SpawnedActorCount} ({DisplayOrNone(state.LastSpawnedActorId)})\n" + $"Flags: invuln={state.Invulnerable}, ammo={state.InfiniteSpecialAmmo}, nofire={state.NoEnemyFire}\n" + $"Debug draw: collisions={state.ShowCollisionShapes}, bounds={state.ShowGameplayBounds}";
}
private Label EnsureLabel()
{
if (m_StatusLabel is not null)
@@ -39,5 +65,13 @@ public partial class DebugOverlay : CanvasLayer
return m_StatusLabel;
}
private static string DisplayOrNone(string value)
{
return string.IsNullOrWhiteSpace(value) ? "none" : value;
}
private Label? m_StatusLabel;
private DebugCommandService? m_Service;
private DebugSettings? m_Settings;
private string m_LoadedSceneId = "none";
}