ModernUO/Distribution/Data
Kamron Batman d8a64f3316
refactor(spawners): replace DynamicJson with typed SpawnerDto records (#2505)
## Summary

Removes the dated `DynamicJson` JSON helper and migrates spawner JSON (de)serialization to a polymorphic `record SpawnerDto` hierarchy. `DynamicJson` was the last remaining consumer (regions moved off it in #1400).

The key correctness improvement: **System.Text.Json deserializes plain DTO records, never a live `Item`.** Previously, deserializing directly into an `Item` meant STJ constructed world-registered objects *before* the data was validated — a malformed/hand-edited spawn file could leave orphaned spawner Items in the world save. Now a parse failure is GC-only; `dto.ToSpawner()` constructs the spawner only from a fully-validated DTO and self-cleans on failure.

## What changed

- **New:** `SpawnerDto` (abstract) + `SpawnerDataDto` / `RegionSpawnerDto` / `ProximitySpawnerDto`, each marked with a reusable `[JsonDiscoverableType]` opt-in attribute. Auto-discovered at the `Configure` phase — no manual registration list (avoids the regions `Register<T>()` footgun), open to custom spawner subtypes.
- **Symmetric mapping:** `BaseSpawner.ToDto()` (export) ⇄ `SpawnerDto.ToSpawner()` (import). `ToSpawner()` deletes-and-rethrows on any failure, so the importer can never orphan an Item.
- **`SpawnerJsonSerializer`** wires `$type` polymorphism on the `SpawnerDto` root with loud collision/constructibility validation.
- **Import/export commands** rewired to the typed DTO path (reflection `FindTypeByName`/`CreateInstance` removed).
- **Data migration:** the 109 `Distribution/Data/Spawns/**` files moved from `"type"`→`"$type"` and legacy `homeRange`→`spawnBounds`. The runtime still *reads* legacy `homeRange` for external files. The `homeRange→spawnBounds` formula is proven equivalent to the runtime conversion (`BoundsEquivalenceTests`, hr=0/1/3/7).
- **Deleted:** `Projects/Server/Json/DynamicJson.cs`.

Sparse export output matches the legacy `ToJson` (nullable DTO properties + `WhenWritingNull`). Binary world-save serialization is untouched.

## Tests

- DTO round-trip per spawner type; sparse-default omission; legacy `homeRange` read; export/import file round-trip.
- `Import_MalformedFile_LeaksNoWorldItems` — proves a mid-array parse failure constructs zero world Items.
- `AllSpawnFilesLoadTests` — every migrated spawn file deserializes and builds.
- Duplicate-discriminator validation.
- UOContent.Tests 485/485, Server.Tests 710/710, build clean.

## Follow-up (not in this PR)

`Rectangle3DConverter.Write` (in `Projects/Server/`) omits `z1/z2` when `Start.Z == -128`, so a future server-side export of a `homeRange`-style spawner round-trips depth 256→255. Pre-existing and out of scope here (Server change); the migrated data reads correctly. Worth a separate small converter PR.
2026-06-25 23:24:45 -07:00
..
Bulk Orders Fixes more line ending issues (#267) 2020-09-27 13:54:56 -07:00
commands feat: Adds Network Packet Documentation (#2302) 2026-01-01 17:52:56 -08:00
Components Fixes more line ending issues (#267) 2020-09-27 13:54:56 -07:00
Decoration feat: Adds rope teleporter for New Haven Mines (#2439) 2026-05-03 17:23:31 -07:00
Items feat: Adds item graphic size to Bounds.bin and makes item graphic offset available to gumps (#2115) 2025-02-10 19:31:39 -08:00
Locations fix(admin): Fixes Tokuno Go Locations (#602) 2021-05-15 19:07:28 -07:00
Professions fix: Updates professions & new player gargish equipment (#819) 2021-10-16 10:48:58 -07:00
Spawns refactor(spawners): replace DynamicJson with typed SpawnerDto records (#2505) 2026-06-25 23:24:45 -07:00
assemblies.json fix: Fixes assembly loading. (#759) 2021-09-03 23:35:44 -07:00
bodyTable.cfg Fixes more line ending issues (#267) 2020-09-27 13:54:56 -07:00
categorization.json fix: Fixes NPE in champ titles (#1434) 2023-07-28 00:39:10 -07:00
containers.cfg Fixes more line ending issues (#267) 2020-09-27 13:54:56 -07:00
expansions.json fix: Fixes expansions.json to correctly reflect name of supported feature flags (#1471) 2023-08-25 11:55:36 -07:00
map-definitions.json fix(core): Moves map definitions and cleans up loading maps, regions, and tiles (#431) 2021-01-25 11:05:52 -08:00
MLQuests.cfg Fixes more line ending issues (#267) 2020-09-27 13:54:56 -07:00
names.json Updates Data to JSON (#159) 2020-06-19 13:53:18 -07:00
npc-speeds.json fix: Reverts to RunUO speeds, fixes direction glitching, adds movement speed interpolation (#1695) 2024-03-18 14:13:41 -07:00
pageresponse.cfg Fixes more line ending issues (#267) 2020-09-27 13:54:56 -07:00
regions.json fix: Fix unguarded/termur regions in regions.json (#1723) 2024-04-07 13:30:35 -07:00
shrink.json fix(shrink): Changes shrink table to use json (#446) 2021-02-03 16:58:50 -08:00
signs.cfg Fixes more line ending issues (#267) 2020-09-27 13:54:56 -07:00
skills.json feat: Adds configurable skill and stat gain (#1489) 2023-10-14 12:02:36 -07:00
teleporters.json fix: Update Hythloth teleport locations in Felucca and Trammel to new coordinates to prevent looping and stuck. (#2012) 2024-12-17 08:59:36 -08:00
treasure.cfg Fixes more line ending issues (#267) 2020-09-27 13:54:56 -07:00