Add Godot project shell

This commit is contained in:
2026-04-21 18:54:38 +02:00
parent 0d9957fa62
commit 12a2868c9c
17 changed files with 424 additions and 6 deletions

View File

@@ -0,0 +1,91 @@
using System;
using Godot;
namespace SideScrollerGame.Debug;
public sealed class DebugSettings
{
public DebugSettings(DebugBootMode bootMode, int seed)
{
BootMode = bootMode;
Seed = seed;
}
public static DebugSettings Load()
{
DebugBootMode bootMode = LoadBootModeFromProjectSettings();
int seed = LoadSeedFromProjectSettings();
foreach (string argument in OS.GetCmdlineUserArgs())
{
if (argument.StartsWith(DebugBootModePrefix, StringComparison.OrdinalIgnoreCase))
{
string value = argument[DebugBootModePrefix.Length..];
if (TryParseBootMode(value, out DebugBootMode parsedBootMode))
{
bootMode = parsedBootMode;
}
else
{
GD.PushWarning($"Unknown debug boot mode '{value}'. Falling back to Menu.");
bootMode = DebugBootMode.Menu;
}
}
else if (argument.StartsWith(SeedPrefix, StringComparison.OrdinalIgnoreCase))
{
string value = argument[SeedPrefix.Length..];
if (int.TryParse(value, out int parsedSeed))
{
seed = parsedSeed;
}
else
{
GD.PushWarning($"Unknown debug seed '{value}'. Keeping seed {seed}.");
}
}
}
return new DebugSettings(bootMode, seed);
}
public DebugBootMode BootMode { get; }
public int Seed { get; }
private static DebugBootMode LoadBootModeFromProjectSettings()
{
if (!ProjectSettings.HasSetting(DebugBootModeSetting))
{
return DebugBootMode.Menu;
}
string configuredBootMode = ProjectSettings.GetSetting(DebugBootModeSetting).AsString();
if (TryParseBootMode(configuredBootMode, out DebugBootMode bootMode))
{
return bootMode;
}
GD.PushWarning($"Unknown configured debug boot mode '{configuredBootMode}'. Falling back to Menu.");
return DebugBootMode.Menu;
}
private static int LoadSeedFromProjectSettings()
{
if (!ProjectSettings.HasSetting(DebugSeedSetting))
{
return 1;
}
return ProjectSettings.GetSetting(DebugSeedSetting).AsInt32();
}
private static bool TryParseBootMode(string value, out DebugBootMode bootMode)
{
return Enum.TryParse(value, true, out bootMode);
}
private const string DebugBootModePrefix = "--debug-boot=";
private const string DebugBootModeSetting = "application/run/debug_boot_mode";
private const string DebugSeedSetting = "application/run/debug_seed";
private const string SeedPrefix = "--seed=";
}