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.
This commit is contained in:
Kamron Batman 2026-06-25 23:24:45 -07:00 • committed by GitHub
parent a26219c837
commit d8a64f3316
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
135 changed files with 7654 additions and 6079 deletions

View file

@ -1,6 +1,6 @@
[
[
{
"type": "Spawner",
"$type": "Spawner",
"guid": "16798caa-188d-4b2d-8494-c3b56cbaa4c7",
"name": "Spawner (102)",
"location": [6049, 1470, 5],
@ -18,7 +18,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "1fb937a2-b8d8-4796-8f7e-62dc86db4541",
"name": "Spawner (102)",
"location": [6052, 1463, 0],
@ -34,7 +34,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "2059e438-3ea0-4553-9d80-2c4b3e179956",
"name": "Spawner (102)",
"location": [6092, 1448, 5],
@ -52,7 +52,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "308b2558-7402-46d1-a300-11eb22feaf0b",
"name": "Spawner (102)",
"location": [6049, 1447, 4],
@ -70,7 +70,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "31142c48-f400-4b04-a235-4df3d184432a",
"name": "Spawner (102)",
"location": [6115, 1491, -15],
@ -88,7 +88,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "424591d5-810a-4248-b002-51d2d993b09e",
"name": "Spawner (102)",
"location": [6108, 1471, 0],
@ -104,7 +104,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "4502169a-d510-4779-a2d4-7ecff61c32a1",
"name": "Spawner (102)",
"location": [6091, 1491, 10],
@ -122,7 +122,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "551ba232-804a-48e2-a289-048ac2c5952c",
"name": "Spawner (102)",
"location": [6087, 1443, 0],
@ -138,7 +138,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "5873288f-b3d0-4ffc-b937-1a938b0ab0a3",
"name": "Spawner (102)",
"location": [6039, 1438, 4],
@ -156,7 +156,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "5e47e277-8d43-46c0-b43a-a15ce3623ceb",
"name": "Spawner (102)",
"location": [6112, 1462, 5],
@ -174,7 +174,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "639f6230-75e9-4633-8e2b-cfd6f35f4fdc",
"name": "Spawner (102)",
"location": [6077, 1492, 0],
@ -190,7 +190,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "70842ac5-c2f9-490b-8fca-603396002f94",
"name": "Spawner (102)",
"location": [6048, 1487, 5],
@ -208,7 +208,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "73483117-862e-472d-b856-13fbe0f2cb04",
"name": "Spawner (102)",
"location": [6065, 1459, 5],
@ -226,7 +226,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "80883952-a77b-466d-b01e-f810fca42c11",
"name": "Spawner (102)",
"location": [6090, 1483, 0],
@ -242,7 +242,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "82cbfa7a-4ea4-476b-ac8c-a3963746fffd",
"name": "Spawner (102)",
"location": [6061, 1490, 5],
@ -260,7 +260,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "bda24adb-c409-4c12-a0c0-8aacd36ab3d9",
"name": "Spawner (102)",
"location": [6034, 1467, 5],
@ -278,7 +278,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "cb41f5b8-add1-42be-8bbe-48b76f9a4dd9",
"name": "Spawner (102)",
"location": [6107, 1452, 25],
@ -296,7 +296,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "dd1b022d-98d5-4f06-aac1-7751d2416304",
"name": "Spawner (102)",
"location": [6059, 1438, 4],
@ -314,7 +314,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "e40a3f76-4701-425c-a806-06cb36504593",
"name": "Spawner (102)",
"location": [6037, 1494, 0],
@ -330,7 +330,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "e5f0bff7-c610-4923-8c17-b32a00911628",
"name": "Spawner (102)",
"location": [6041, 1486, 5],
@ -348,7 +348,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "ed8f2188-17cd-4235-86d8-54d62209ef93",
"name": "Spawner (102)",
"location": [6084, 1470, 5],