Add F1 debug menu with paused diagnostics and scene controls
This commit is contained in:
1 parent
8d60a68511
commit
3078b8afd0
21 files changed
+809
-36
No files matched your search
@@ -0,0 +1,120 @@
|
||||
using System.Globalization;
|
||||
using System.Numerics;
|
||||
using GamePort.Assets;
|
||||
|
||||
namespace GamePort.Application;
|
||||
|
||||
public sealed record DebugScene(string LevelFile, string Code, string[] Starts);
|
||||
public enum DebugAction { None, Resume, Camera, SkipCutscene, RefillEnergy, GiveJetpack, ApplySceneTask, LoadScene, Reset }
|
||||
public sealed record DebugMenuView(string[] Lines, int SelectedLine);
|
||||
public sealed record DebugStatus(string Level, string Start, Vector3 Root, float Yaw, float Speed,
|
||||
bool Grounded, float Energy, int Score, int SceneTask, string Cutscene, bool Controlled,
|
||||
int Issues, float FarPlane, bool Inspecting);
|
||||
|
||||
/// <summary>Modern investigation tools, deliberately separate from recovered game UI.</summary>
|
||||
public sealed class DebugMenu
|
||||
{
|
||||
public const uint ToggleKey = 58; // SDL scancode F1; F11 remains fullscreen.
|
||||
public const int ItemCount = 10;
|
||||
public bool Open { get; private set; }
|
||||
public int Selected { get; private set; }
|
||||
public int SceneTask { get; private set; }
|
||||
public string Message { get; set; } = "";
|
||||
private readonly DebugScene[] scenes;
|
||||
private int sceneIndex, startIndex;
|
||||
public DebugScene? Scene => scenes.Length == 0 ? null : scenes[sceneIndex];
|
||||
public string? Start => Scene is { } scene ? scene.Starts[startIndex] : null;
|
||||
|
||||
public DebugMenu(IEnumerable<DebugScene> scenes, string? currentLevel, string? currentStart)
|
||||
{
|
||||
this.scenes = scenes.ToArray();
|
||||
if (this.scenes.Any(s => s.Starts.Length == 0)) throw new ArgumentException("Debug scenes require a startpoint");
|
||||
sceneIndex = Math.Max(0, Array.FindIndex(this.scenes,
|
||||
s => string.Equals(s.LevelFile, currentLevel, StringComparison.OrdinalIgnoreCase)));
|
||||
if (Scene is { } selected)
|
||||
startIndex = Math.Max(0, Array.FindIndex(selected.Starts,
|
||||
s => string.Equals(s, currentStart, StringComparison.OrdinalIgnoreCase)));
|
||||
}
|
||||
|
||||
public void Toggle(int currentSceneTask)
|
||||
{
|
||||
Open = !Open;
|
||||
if (Open) { SceneTask = currentSceneTask; Message = ""; }
|
||||
}
|
||||
public void Close() => Open = false;
|
||||
|
||||
public DebugAction Key(uint scancode, bool repeat = false)
|
||||
{
|
||||
if (!Open) return DebugAction.None;
|
||||
if (scancode == 41) { Close(); return DebugAction.None; }
|
||||
if (scancode is 82 or 81)
|
||||
Selected = (Selected + (scancode == 82 ? ItemCount - 1 : 1)) % ItemCount;
|
||||
else if (scancode is 80 or 79 or 75 or 78)
|
||||
{
|
||||
var direction = scancode is 80 or 78 ? -1 : 1;
|
||||
if (Selected == 5)
|
||||
SceneTask = (int)Math.Clamp((long)SceneTask + direction * (scancode is 75 or 78 ? 10 : 1), 0, 999);
|
||||
else if (Selected == 6 && scenes.Length > 0)
|
||||
{ sceneIndex = (sceneIndex + scenes.Length + direction) % scenes.Length; startIndex = 0; }
|
||||
else if (Selected == 7 && Scene is { } scene)
|
||||
startIndex = (startIndex + scene.Starts.Length + direction) % scene.Starts.Length;
|
||||
}
|
||||
else if (scancode is 40 or 88 && !repeat)
|
||||
return Selected switch
|
||||
{
|
||||
0 => DebugAction.Resume, 1 => DebugAction.Camera, 2 => DebugAction.SkipCutscene,
|
||||
3 => DebugAction.RefillEnergy, 4 => DebugAction.GiveJetpack, 5 => DebugAction.ApplySceneTask,
|
||||
8 => Scene == null ? DebugAction.None : DebugAction.LoadScene, 9 => DebugAction.Reset,
|
||||
_ => DebugAction.None
|
||||
};
|
||||
return DebugAction.None;
|
||||
}
|
||||
|
||||
public DebugMenuView View(DebugStatus status)
|
||||
{
|
||||
if (!Open) return new([], -1);
|
||||
var c = CultureInfo.InvariantCulture;
|
||||
string F(float value) => value.ToString("0.0", c);
|
||||
return new([
|
||||
"NEUTRON DEBUG MENU - F1",
|
||||
"PAUSED - MODERN DEBUG TOOLS",
|
||||
$"LEVEL {status.Level} / START {status.Start}",
|
||||
$"ROOT X {F(status.Root.X)} Y {F(status.Root.Y)} Z {F(status.Root.Z)}",
|
||||
$"YAW {F(status.Yaw)} SPEED {F(status.Speed)} GROUNDED {status.Grounded}",
|
||||
$"ENERGY {F(status.Energy)} SCORE {status.Score} SCENE {status.SceneTask}",
|
||||
$"CONTROL {status.Controlled} CUTSCENE {status.Cutscene}",
|
||||
$"ISSUES {status.Issues} FAR {F(status.FarPlane)} CAMERA {(status.Inspecting ? "ORBIT" : "GAMEPLAY")}",
|
||||
"",
|
||||
"RESUME",
|
||||
$"CAMERA: {(status.Inspecting ? "SWITCH TO GAMEPLAY" : "SWITCH TO ORBIT")}",
|
||||
"SKIP CURRENT CUTSCENE",
|
||||
"REFILL ENERGY TO 100",
|
||||
"GIVE / SELECT JET PACK",
|
||||
$"SCENE TASK: {SceneTask} (ENTER APPLIES)",
|
||||
$"LEVEL: {Scene?.LevelFile ?? "UNAVAILABLE"}",
|
||||
$"START: {Start ?? "UNAVAILABLE"}",
|
||||
"LOAD SELECTED LEVEL / START",
|
||||
"RESET CURRENT START",
|
||||
"",
|
||||
"UP/DOWN SELECT LEFT/RIGHT CHANGE ENTER APPLY",
|
||||
"SCENE TASK: PAGE UP/DOWN CHANGES BY 10",
|
||||
"F1 / ESC CLOSE - GAME INPUT IS CAPTURED WHILE OPEN",
|
||||
Message
|
||||
], 9 + Selected);
|
||||
}
|
||||
|
||||
public static DebugScene[] AvailableScenes(string assets, string prepared)
|
||||
{
|
||||
var scenes = new List<DebugScene>();
|
||||
foreach (var path in Directory.EnumerateFiles(AssetPath.Resolve(assets, "gam"))
|
||||
.Where(p => p.EndsWith(".gam", StringComparison.OrdinalIgnoreCase)).OrderBy(Path.GetFileName, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
try { AssetPath.Resolve(prepared, Path.GetFileNameWithoutExtension(path) + "/scene.json"); }
|
||||
catch (FileNotFoundException) { continue; }
|
||||
var level = GamLevel.Load(path);
|
||||
var starts = level.Entities.Where(e => e.Kind == "STRT" && e.Tag is { Length: > 0 }).Select(e => e.Tag!).ToArray();
|
||||
if (level.Player != null && starts.Length > 0) scenes.Add(new(Path.GetFileName(path), level.Code, starts));
|
||||
}
|
||||
return scenes.ToArray();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user