Files
TheriapolisV3/Theriapolis.Godot/Main.cs
T
Christopher Wiebe a23cf8bd97 M3: Asset pipeline — ContentPaths + ContentLoader + asset-test
Formalises Content/ access from the Godot host. Content lives at the
repo root (sibling of Theriapolis.Godot/), not duplicated under res://,
so the MonoGame branch and headless Tools keep reading from the same
single source of truth.

ContentPaths.cs:
  Static ContentRoot/DataDir/GfxDir resolved once via res:// walk-up
  and cached. Replaces two inline ResolveDataDir copies in SmokeTest
  and WorldMapView.

ContentLoader.cs:
  LoadGfx(relativePath) -> ImageTexture, cached by relative path.
  Bypasses the res:// import pipeline because Content/ lives outside
  the project — fine for static pixel-art assets at native size, and
  the project default texture filter is already Nearest. Cache is
  per-process, never evicted (full atlas <1 MB).

AssetTest.cs + Main.cs --asset-test flag:
  Smoke-tests the pipeline. Walks Content/Data and Content/Gfx,
  reports counts, attempts to load every PNG, prints per-subdir
  breakdown. Quits with non-zero on any failure.

Verified post-refactor (--asset-test):
  53 JSON files in Data, 50 PNG files in Gfx (8 tactical/deco +
  42 tactical/surface), 50/50 loaded, 0 failures.

Verified no regressions:
  --smoke-test (M1) still produces canonical FNV hashes.
  --world-map 12345 (M2) still produces 3 rivers / 91 roads /
  226 settlements / 0 rails / 0 bridges.

Scope note: plan mentioned "tile/NPC/CodexUI atlases — three
separate themes". Only tactical/ exists in Content/Gfx today; NPC
and CodexUI atlases never landed during MonoGame development. M3
ships what's actually present. ContentLoader.LoadGfx works for any
future sub-directories without changes.

Closes M3 of theriapolis-rpg-implementation-plan-godot-port.md.
Next: M4 (tactical render).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-01 19:13:51 -07:00

86 lines
2.6 KiB
C#

using Godot;
using Theriapolis.GodotHost.Platform;
using Theriapolis.GodotHost.Rendering;
namespace Theriapolis.GodotHost;
public partial class Main : Node
{
public override void _Ready()
{
// GetCmdlineArgs returns every arg (Godot's own flags + ours);
// GetCmdlineUserArgs only returns args after a "--" separator.
// Use the union so users don't have to remember the separator.
var userArgs = OS.GetCmdlineUserArgs();
var allArgs = OS.GetCmdlineArgs();
var args = new string[userArgs.Length + allArgs.Length];
userArgs.CopyTo(args, 0);
allArgs.CopyTo(args, userArgs.Length);
ulong? smokeTestSeed = null;
ulong? worldMapSeed = null;
bool runAssetTest = false;
for (int i = 0; i < args.Length; i++)
{
if (args[i] == "--smoke-test")
{
ulong seed = 12345UL;
if (i + 1 < args.Length && ulong.TryParse(args[i + 1], out var parsed))
seed = parsed;
smokeTestSeed = seed;
break;
}
if (args[i] == "--asset-test")
{
runAssetTest = true;
break;
}
if (args[i] == "--world-map")
{
ulong seed = 12345UL;
if (i + 1 < args.Length && ulong.TryParse(args[i + 1], out var parsed))
seed = parsed;
worldMapSeed = seed;
break;
}
}
if (smokeTestSeed.HasValue)
{
int code = SmokeTest.Run(smokeTestSeed.Value);
GetTree().Quit(code);
return;
}
if (runAssetTest)
{
int code = AssetTest.Run();
GetTree().Quit(code);
return;
}
if (worldMapSeed.HasValue)
{
// Replace the M0 hello-world children with the M2 world-map view.
foreach (Node child in GetChildren())
child.QueueFree();
AddChild(new WorldMapView(worldMapSeed.Value));
return;
}
GD.Print("Theriapolis.Godot host ready (M0 hello-world).");
}
public override void _UnhandledInput(InputEvent @event)
{
if (@event.IsActionPressed("ui_toggle_fullscreen"))
{
var mode = DisplayServer.WindowGetMode();
DisplayServer.WindowSetMode(
mode == DisplayServer.WindowMode.Fullscreen
? DisplayServer.WindowMode.Windowed
: DisplayServer.WindowMode.Fullscreen);
}
}
}