Add core content definitions
This commit is contained in:
80
godot/scripts/debug/ContentBrowserController.cs
Normal file
80
godot/scripts/debug/ContentBrowserController.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Godot;
|
||||
using SideScrollerGame.Content;
|
||||
using SideScrollerGame.Content.Samples;
|
||||
using SideScrollerGame.Content.Validation;
|
||||
|
||||
namespace SideScrollerGame.Debug;
|
||||
|
||||
public partial class ContentBrowserController : Control
|
||||
{
|
||||
public override void _Ready()
|
||||
{
|
||||
ContentRegistry registry = SampleContent.CreateRegistry();
|
||||
ContentValidationResult validation = new ContentValidator().Validate(registry);
|
||||
string report = BuildReport(registry, validation);
|
||||
SetText(report);
|
||||
|
||||
if (!ShouldValidateAndQuit())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GD.Print(report);
|
||||
GD.Print(validation.HasErrors ? "Content validation failed" : "Content validation succeeded");
|
||||
GetTree().Quit(validation.HasErrors ? 1 : 0);
|
||||
}
|
||||
|
||||
private static string BuildReport(ContentRegistry registry, ContentValidationResult validation)
|
||||
{
|
||||
StringBuilder builder = new();
|
||||
builder.AppendLine("Loaded content definitions:");
|
||||
foreach (string id in registry.AllDefinitionIds())
|
||||
{
|
||||
builder.AppendLine(id);
|
||||
}
|
||||
|
||||
if (validation.Messages.Count > 0)
|
||||
{
|
||||
builder.AppendLine();
|
||||
builder.AppendLine("Validation messages:");
|
||||
foreach (ContentValidationMessage message in validation.Messages)
|
||||
{
|
||||
builder.AppendLine($"{message.Severity}: {message.Code}: {message.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
return builder.ToString().TrimEnd();
|
||||
}
|
||||
|
||||
private static bool ShouldValidateAndQuit()
|
||||
{
|
||||
return IsHeadless() && OS.GetCmdlineUserArgs().Any(argument => argument.Equals(ValidateOnlyArgument, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
private static bool IsHeadless()
|
||||
{
|
||||
return DisplayServer.GetName().Equals("headless", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private void SetText(string report)
|
||||
{
|
||||
Label? title = GetNodeOrNull<Label>("Title");
|
||||
if (title is not null)
|
||||
{
|
||||
title.Text = "Content Browser";
|
||||
}
|
||||
|
||||
Label? content = GetNodeOrNull<Label>("Scroll/Content");
|
||||
if (content is not null)
|
||||
{
|
||||
content.Text = report;
|
||||
}
|
||||
}
|
||||
|
||||
private const string ValidateOnlyArgument = "--content-validate-only";
|
||||
}
|
||||
1
godot/scripts/debug/ContentBrowserController.cs.uid
Normal file
1
godot/scripts/debug/ContentBrowserController.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cfukg3hg4wwpx
|
||||
@@ -3,5 +3,6 @@ namespace SideScrollerGame.Debug;
|
||||
public enum DebugBootMode
|
||||
{
|
||||
Menu,
|
||||
Smoke
|
||||
Smoke,
|
||||
ContentBrowser
|
||||
}
|
||||
@@ -81,7 +81,28 @@ public sealed class DebugSettings
|
||||
|
||||
private static bool TryParseBootMode(string value, out DebugBootMode bootMode)
|
||||
{
|
||||
return Enum.TryParse(value, true, out bootMode);
|
||||
if (Enum.TryParse(value, true, out bootMode))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
string normalizedValue = NormalizeBootModeName(value);
|
||||
foreach (DebugBootMode candidate in Enum.GetValues<DebugBootMode>())
|
||||
{
|
||||
if (NormalizeBootModeName(candidate.ToString()).Equals(normalizedValue, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
bootMode = candidate;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bootMode = DebugBootMode.Menu;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static string NormalizeBootModeName(string value)
|
||||
{
|
||||
return value.Replace("-", string.Empty, StringComparison.Ordinal).Replace("_", string.Empty, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private const string DebugBootModePrefix = "--debug-boot=";
|
||||
|
||||
Reference in New Issue
Block a user