Files
Christopher Wiebe b451f83174 Initial commit: Theriapolis baseline at port/godot branch point
Captures the pre-Godot-port state of the codebase. This is the rollback
anchor for the Godot port (M0 of theriapolis-rpg-implementation-plan-godot-port.md).
All Phase 0 through Phase 6.5 work is included; Phase 7 is in flight.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-30 20:40:51 -07:00

113 lines
4.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Text.Json.Serialization;
namespace Theriapolis.Core.Data;
/// <summary>
/// A single cell in the 32×32 authored macro-template grid.
/// Defines the biome character and generation constraints for a 32×32-tile region.
/// </summary>
public sealed class MacroCell
{
[JsonPropertyName("biome_type")]
public string BiomeType { get; set; } = "temperate_grassland";
[JsonPropertyName("clade_affinities")]
public string[] CladeAffinities { get; set; } = Array.Empty<string>();
[JsonPropertyName("development")]
public string Development { get; set; } = "agricultural";
/// <summary>strong | moderate | weak | nominal</summary>
[JsonPropertyName("covenant")]
public string Covenant { get; set; } = "moderate";
// Elevation constraints (01 range). Floor = minimum, Ceiling = maximum.
[JsonPropertyName("elevation_floor")]
public float ElevationFloor { get; set; } = 0f;
[JsonPropertyName("elevation_ceiling")]
public float ElevationCeiling { get; set; } = 1f;
// Moisture constraints
[JsonPropertyName("moisture_floor")]
public float MoistureFloor { get; set; } = 0f;
[JsonPropertyName("moisture_ceiling")]
public float MoistureCeiling { get; set; } = 1f;
// Temperature modifiers (added to base latitude temperature)
[JsonPropertyName("temp_modifier")]
public float TempModifier { get; set; } = 0f;
}
/// <summary>Root structure of macro_template.json.</summary>
public sealed class MacroTemplate
{
[JsonPropertyName("width")]
public int Width { get; set; } = C.MACRO_GRID_WIDTH;
[JsonPropertyName("height")]
public int Height { get; set; } = C.MACRO_GRID_HEIGHT;
[JsonPropertyName("default_cell")]
public MacroCell DefaultCell { get; set; } = new();
[JsonPropertyName("regions")]
public MacroRegion[] Regions { get; set; } = Array.Empty<MacroRegion>();
/// <summary>Expand regions into a flat [width, height] grid. Later regions overwrite earlier ones.</summary>
public MacroCell[,] Build()
{
var grid = new MacroCell[Width, Height];
// Fill with default
for (int y = 0; y < Height; y++)
for (int x = 0; x < Width; x++)
grid[x, y] = DefaultCell;
// Paint regions in order (later regions win)
foreach (var r in Regions)
{
var cell = r.ToCell();
int x1 = Math.Min(r.X + r.W, Width);
int y1 = Math.Min(r.Y + r.H, Height);
for (int y = Math.Max(0, r.Y); y < y1; y++)
for (int x = Math.Max(0, r.X); x < x1; x++)
grid[x, y] = cell;
}
return grid;
}
}
/// <summary>A rectangular block in the macro template, painted over the default.</summary>
public sealed class MacroRegion
{
[JsonPropertyName("x")] public int X { get; set; }
[JsonPropertyName("y")] public int Y { get; set; }
[JsonPropertyName("w")] public int W { get; set; }
[JsonPropertyName("h")] public int H { get; set; }
/// <summary>Human-readable annotation in the JSON file — ignored at runtime.</summary>
[JsonPropertyName("comment")] public string? Comment { get; set; }
[JsonPropertyName("biome_type")] public string BiomeType { get; set; } = "temperate_grassland";
[JsonPropertyName("clade_affinities")] public string[] CladeAffinities { get; set; } = Array.Empty<string>();
[JsonPropertyName("development")] public string Development { get; set; } = "agricultural";
[JsonPropertyName("covenant")] public string Covenant { get; set; } = "moderate";
[JsonPropertyName("elevation_floor")] public float ElevationFloor { get; set; } = 0f;
[JsonPropertyName("elevation_ceiling")]public float ElevationCeiling { get; set; } = 1f;
[JsonPropertyName("moisture_floor")] public float MoistureFloor { get; set; } = 0f;
[JsonPropertyName("moisture_ceiling")] public float MoistureCeiling { get; set; } = 1f;
[JsonPropertyName("temp_modifier")] public float TempModifier { get; set; } = 0f;
public MacroCell ToCell() => new()
{
BiomeType = BiomeType,
CladeAffinities = CladeAffinities,
Development = Development,
Covenant = Covenant,
ElevationFloor = ElevationFloor,
ElevationCeiling = ElevationCeiling,
MoistureFloor = MoistureFloor,
MoistureCeiling = MoistureCeiling,
TempModifier = TempModifier,
};
}