Files
TheriapolisV3/Theriapolis.Godot/Main.cs
T
Christopher Wiebe 59784048cd M2: World map render in Godot
Renders the full worldgen output as a Godot scene at visual parity with
worldgen-dump's PNG output: biome tiles, rivers/roads/rails as Line2D
polylines, settlements as filled circles. Pan + zoom via Camera2D.

WorldMapView.cs:
  - Loads Content/Data via res:// walk-up, runs WorldGenerator.RunAll
  - Tile palette built from BiomeDef.ParsedColor() — same source as the
    PNG dump, so colours are identical
  - Tiles rendered as a 256x256 Image scaled by WORLD_TILE_PIXELS to
    cover world-pixel space (matches polyline coord system)
  - Polyline draw order mirrors LineFeatureRenderer.cs: roads (smaller
    first) -> rivers -> rail tie underlay -> rail line. Bridges as
    short Line2Ds; settlements as SettlementDot (Node2D + _Draw circle)
  - Line widths in world-pixel space, tuned for visibility at world-map
    zoom; M4 will add zoom-aware width scaling for tactical view
  - Camera fits the whole world (95% of viewport) on first frame

PanZoomCamera.cs:
  - Mouse-wheel zoom centered on cursor (cursor world-point stays fixed)
  - Middle/right click + drag to pan
  - MinZoom/MaxZoom configurable per-instance

Main.cs:
  - --world-map [seed] flag launches the view (default seed 12345)
  - Arg parser now reads both GetCmdlineArgs and GetCmdlineUserArgs so
    callers don't need to remember the "--" separator
  - --smoke-test path and M0 hello-world fallback unchanged

Visual diff against world_seed12345.png (generated by
worldgen-dump --seed 12345) confirmed manually: same biome palette, same
rivers/roads topology, same settlement placement and tier colours.
3 rivers, 91 roads, 226 settlements (138 PoIs), 0 rails (ENABLE_RAIL=false),
0 bridges (this seed has no road/river crossings). All match the PNG.

Settlement dot sizes iterated twice from user feedback — final values
in tile units, scaled to world-pixel space, so they shrink at world-map
zoom and grow toward tactical zoom (the right "scale with the map"
behaviour).

Closes M2 of theriapolis-rpg-implementation-plan-godot-port.md.
Next: M3 (asset pipeline).

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

72 lines
2.3 KiB
C#

using Godot;
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;
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] == "--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 (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);
}
}
}