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:
parent
a26219c837
commit
d8a64f3316
135 changed files with 7654 additions and 6079 deletions
|
|
@ -1,6 +1,6 @@
|
|||
[
|
||||
[
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "01ae830b-c7f9-4857-8a6b-4bacca6758ad",
|
||||
"name": "Spawner (212)",
|
||||
"location": [5356, 1304, 0],
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "03b59250-db54-481c-85f4-1d0b8b433252",
|
||||
"name": "Spawner (212)",
|
||||
"location": [5153, 1971, 0],
|
||||
|
|
@ -34,7 +34,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "0e858157-adc4-4963-a34b-101fefb109d1",
|
||||
"name": "Spawner (212)",
|
||||
"location": [5308, 1372, 0],
|
||||
|
|
@ -50,7 +50,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "1a6833ee-9e32-4900-ad6e-87926e8fb427",
|
||||
"name": "Spawner (212)",
|
||||
"location": [5316, 1332, 0],
|
||||
|
|
@ -66,7 +66,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "1bff583d-3643-4e60-9a44-e3dea6882a02",
|
||||
"name": "Spawner (212)",
|
||||
"location": [5308, 2005, 0],
|
||||
|
|
@ -83,7 +83,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "2d24f1f9-20ff-4ee1-8f31-8304e2e4822d",
|
||||
"name": "Spawner (212)",
|
||||
"location": [5310, 1969, 0],
|
||||
|
|
@ -100,7 +100,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "40c5eacc-9b5d-49f4-b13d-c605a32f6816",
|
||||
"name": "Spawner (212)",
|
||||
"location": [5354, 1332, 0],
|
||||
|
|
@ -119,7 +119,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "471bb8b3-f768-4654-a3ae-9517ecc8dd45",
|
||||
"name": "Spawner (212)",
|
||||
"location": [5317, 1309, 0],
|
||||
|
|
@ -138,7 +138,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "5145b262-72b3-4bf2-8a73-91efe509ce18",
|
||||
"name": "Spawner (212)",
|
||||
"location": [5144, 1960, 0],
|
||||
|
|
@ -154,7 +154,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "572a2fac-11c7-4583-837a-1b03eae15f85",
|
||||
"name": "Spawner (212)",
|
||||
"location": [5146, 1995, 0],
|
||||
|
|
@ -172,7 +172,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "593ee3b4-df42-426d-8976-faced7cd2435",
|
||||
"name": "Spawner (212)",
|
||||
"location": [5302, 1355, 0],
|
||||
|
|
@ -189,7 +189,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "70960aad-63ab-4bc2-9784-0ae5db883fe1",
|
||||
"name": "Spawner (212)",
|
||||
"location": [5331, 1346, 0],
|
||||
|
|
@ -205,7 +205,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "81a40400-c93d-42f3-8f19-0e9492198a82",
|
||||
"name": "Spawner (212)",
|
||||
"location": [5292, 1316, 0],
|
||||
|
|
@ -221,7 +221,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "a1dbbaf6-03e3-42f2-ba42-35d88349fd0c",
|
||||
"name": "Spawner (212)",
|
||||
"location": [5153, 1961, 0],
|
||||
|
|
@ -237,7 +237,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "a70f186a-94a1-4f54-963f-5c039c7d4006",
|
||||
"name": "Spawner (212)",
|
||||
"location": [5348, 2011, 0],
|
||||
|
|
@ -254,7 +254,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "d01dca90-9fac-438e-9660-a93e9df7fc58",
|
||||
"name": "Spawner (212)",
|
||||
"location": [5281, 2029, 0],
|
||||
|
|
@ -270,7 +270,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "d313d866-1199-45fc-a72c-018d146bbe8c",
|
||||
"name": "Spawner (212)",
|
||||
"location": [5300, 1314, 0],
|
||||
|
|
@ -288,7 +288,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "ee800978-f2bf-47e0-8e19-c7f5fe0b33bc",
|
||||
"name": "Spawner (212)",
|
||||
"location": [5332, 1365, 0],
|
||||
|
|
@ -304,7 +304,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "fe0be93b-5f45-40b0-9169-16df378c0e6e",
|
||||
"name": "Spawner (212)",
|
||||
"location": [5141, 1968, 0],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue