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": "0c628980-8a6f-45e1-bdc8-ed7ea16765fd",
"name": "Spawner (402)",
"location": [2205, 145, -90],
@ -16,7 +16,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "135a20a6-0885-4a61-9a55-a01593f3e874",
"name": "Spawner (402)",
"location": [1482, 347, -50],
@ -37,7 +37,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "2db6869c-b590-4f82-a5eb-edb7afdd18e4",
"name": "Spawner (402)",
"location": [1274, 300, -50],
@ -58,7 +58,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "2efda65d-ebc3-4251-b6a3-356d42cca581",
"name": "Spawner (402)",
"location": [2291, 295, -90],
@ -74,7 +74,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "41a269ac-0492-4a16-bbc3-449c7efa9ef9",
"name": "Spawner (402)",
"location": [2121, 597, -50],
@ -95,7 +95,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "63d80004-20f7-48d8-bcc8-639a8d83c099",
"name": "Spawner (402)",
"location": [766, 114, -90],
@ -116,7 +116,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "67b52f00-d808-4db4-91ca-9313330d0b40",
"name": "Spawner (402)",
"location": [1710, 403, -50],
@ -137,7 +137,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "6ef4d890-5038-4d39-977c-5eb15448543a",
"name": "Spawner (402)",
"location": [1659, 112, -80],
@ -158,7 +158,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "a1e3857a-952a-47c2-9311-d6bcc3806c45",
"name": "Spawner (402)",
"location": [1980, 660, -50],
@ -179,7 +179,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "a7be1139-619a-4d84-a98a-8ea04c550827",
"name": "Spawner (402)",
"location": [1869, 480, -50],
@ -200,7 +200,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "abaa8a2d-9997-4bff-b033-a9dfa78d46f9",
"name": "Spawner (402)",
"location": [2030, 500, -50],
@ -221,7 +221,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "b48ebb7a-8bfc-4c48-a0ab-f82ca41e38ac",
"name": "Spawner (402)",
"location": [1381, 340, -50],
@ -242,7 +242,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "b85a0fee-612e-4bd9-8489-28fbcdc60ef5",
"name": "Spawner (402)",
"location": [1137, 223, -50],
@ -263,7 +263,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "be2f76e8-a03b-42b9-b39c-c641f03ee091",
"name": "Spawner (402)",
"location": [1206, 191, -50],
@ -284,7 +284,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "dec6f03f-a79d-414a-8b8b-c46af723371a",
"name": "Spawner (402)",
"location": [1587, 386, -50],
@ -305,7 +305,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "e2af6c55-d320-4255-a85f-c694f8d9886b",
"name": "Spawner (402)",
"location": [2233, 555, -90],
@ -326,7 +326,7 @@
]
},
{
"type": "Spawner",
"$type": "Spawner",
"guid": "e3f940e1-3225-416f-a9ba-717b28fb944a",
"name": "Spawner (402)",
"location": [1023, 192, -50],