Add Godot project shell
This commit is contained in:
7
godot/scripts/debug/DebugBootMode.cs
Normal file
7
godot/scripts/debug/DebugBootMode.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace SideScrollerGame.Debug;
|
||||
|
||||
public enum DebugBootMode
|
||||
{
|
||||
Menu,
|
||||
Smoke
|
||||
}
|
||||
1
godot/scripts/debug/DebugBootMode.cs.uid
Normal file
1
godot/scripts/debug/DebugBootMode.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cebwe1o0qw160
|
||||
43
godot/scripts/debug/DebugOverlay.cs
Normal file
43
godot/scripts/debug/DebugOverlay.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
#nullable enable
|
||||
|
||||
using Godot;
|
||||
|
||||
namespace SideScrollerGame.Debug;
|
||||
|
||||
public partial class DebugOverlay : CanvasLayer
|
||||
{
|
||||
public override void _Ready()
|
||||
{
|
||||
Layer = 100;
|
||||
ProcessMode = ProcessModeEnum.Always;
|
||||
EnsureLabel();
|
||||
}
|
||||
|
||||
public void SetStatus(DebugSettings settings, string loadedSceneId)
|
||||
{
|
||||
Label label = EnsureLabel();
|
||||
label.Text = $"Debug boot: {settings.BootMode}\nSeed: {settings.Seed}\nScene: {loadedSceneId}\nDebug: {OS.IsDebugBuild()}";
|
||||
}
|
||||
|
||||
private Label EnsureLabel()
|
||||
{
|
||||
if (m_StatusLabel is not null)
|
||||
{
|
||||
return m_StatusLabel;
|
||||
}
|
||||
|
||||
m_StatusLabel = GetNodeOrNull<Label>("StatusLabel");
|
||||
if (m_StatusLabel is null)
|
||||
{
|
||||
m_StatusLabel = new Label { Name = "StatusLabel" };
|
||||
AddChild(m_StatusLabel);
|
||||
}
|
||||
|
||||
m_StatusLabel.MouseFilter = Control.MouseFilterEnum.Ignore;
|
||||
m_StatusLabel.Position = new Vector2(8.0f, 8.0f);
|
||||
m_StatusLabel.AutowrapMode = TextServer.AutowrapMode.Off;
|
||||
return m_StatusLabel;
|
||||
}
|
||||
|
||||
private Label? m_StatusLabel;
|
||||
}
|
||||
1
godot/scripts/debug/DebugOverlay.cs.uid
Normal file
1
godot/scripts/debug/DebugOverlay.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b41hmmnemingf
|
||||
91
godot/scripts/debug/DebugSettings.cs
Normal file
91
godot/scripts/debug/DebugSettings.cs
Normal 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=";
|
||||
}
|
||||
1
godot/scripts/debug/DebugSettings.cs.uid
Normal file
1
godot/scripts/debug/DebugSettings.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://m3c08h4ms4qu
|
||||
24
godot/scripts/debug/SmokeSceneController.cs
Normal file
24
godot/scripts/debug/SmokeSceneController.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Godot;
|
||||
|
||||
namespace SideScrollerGame.Debug;
|
||||
|
||||
public partial class SmokeSceneController : Node2D
|
||||
{
|
||||
public override async void _Ready()
|
||||
{
|
||||
GD.Print("Smoke scene loaded");
|
||||
|
||||
if (!IsHeadless())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||
GetTree().Quit(0);
|
||||
}
|
||||
|
||||
private static bool IsHeadless()
|
||||
{
|
||||
return DisplayServer.GetName().Equals("headless", System.StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
1
godot/scripts/debug/SmokeSceneController.cs.uid
Normal file
1
godot/scripts/debug/SmokeSceneController.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dwc6njr4c222l
|
||||
Reference in New Issue
Block a user