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": "0076bc53-87a0-493c-9251-8b689c0aac25",
|
||||
"name": "Spawner (112)",
|
||||
"location": [5354, 1332, 0],
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "02f05175-47b3-49ce-adfd-6838f0bb93a7",
|
||||
"name": "Spawner (112)",
|
||||
"location": [5331, 1346, 0],
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "03496f57-4e3d-4a83-a12c-8ee3523f4efb",
|
||||
"name": "Spawner (112)",
|
||||
"location": [5348, 2011, 0],
|
||||
|
|
@ -52,7 +52,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "04dd6b85-c84e-49e1-8e6a-fbea6734f30b",
|
||||
"name": "Spawner (112)",
|
||||
"location": [5153, 1971, 0],
|
||||
|
|
@ -68,7 +68,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "17e3d0fd-73d1-435c-9d32-ea6716977e80",
|
||||
"name": "Spawner (112)",
|
||||
"location": [5308, 1372, 0],
|
||||
|
|
@ -84,7 +84,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "20658391-8218-48bd-bdab-fd04bbafad31",
|
||||
"name": "Spawner (112)",
|
||||
"location": [5141, 1968, 0],
|
||||
|
|
@ -100,7 +100,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "264b83e9-092d-4d4b-9dac-8f717b8a21a6",
|
||||
"name": "Spawner (112)",
|
||||
"location": [5153, 1961, 0],
|
||||
|
|
@ -116,7 +116,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "434454b5-2093-4125-8b2c-59c57d6bd98b",
|
||||
"name": "Spawner (112)",
|
||||
"location": [5292, 1316, 0],
|
||||
|
|
@ -132,7 +132,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "48b68bf1-d9b1-4fac-af9e-9c51c90fe891",
|
||||
"name": "Spawner (112)",
|
||||
"location": [5302, 1355, 0],
|
||||
|
|
@ -149,7 +149,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "4abbaeaf-4d90-4eef-bca1-55bbc1b0b631",
|
||||
"name": "Spawner (112)",
|
||||
"location": [5144, 1960, 0],
|
||||
|
|
@ -165,7 +165,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "646f189b-b834-4e7d-9e96-dc8b5d71412d",
|
||||
"name": "Spawner (112)",
|
||||
"location": [5300, 1314, 0],
|
||||
|
|
@ -183,7 +183,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "6d6544ae-63b4-4c8b-8be3-7b52b505f7f9",
|
||||
"name": "Spawner (112)",
|
||||
"location": [5317, 1309, 0],
|
||||
|
|
@ -202,7 +202,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "c13bf083-3691-486a-b5af-7779a398b1f8",
|
||||
"name": "Spawner (112)",
|
||||
"location": [5308, 2005, 0],
|
||||
|
|
@ -219,7 +219,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "c343a444-ed8b-4bc7-9c5f-4ac06bcb18f8",
|
||||
"name": "Spawner (112)",
|
||||
"location": [5332, 1365, 0],
|
||||
|
|
@ -235,7 +235,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "cd4b9397-58f2-42bf-ac91-033ad8396eda",
|
||||
"name": "Spawner (112)",
|
||||
"location": [5146, 1995, 0],
|
||||
|
|
@ -253,7 +253,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "def6d26d-288a-4659-9ccc-b7556ba93dfe",
|
||||
"name": "Spawner (112)",
|
||||
"location": [5281, 2029, 0],
|
||||
|
|
@ -269,7 +269,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "ebff4db1-6752-4457-b629-109818ec0294",
|
||||
"name": "Spawner (112)",
|
||||
"location": [5356, 1304, 0],
|
||||
|
|
@ -287,7 +287,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "f128f5b2-ca75-465f-87b2-d5bbf8c933cf",
|
||||
"name": "Spawner (112)",
|
||||
"location": [5316, 1332, 0],
|
||||
|
|
@ -303,7 +303,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "f769344d-9b4e-4573-b61a-5d1e4d66361d",
|
||||
"name": "Spawner (112)",
|
||||
"location": [5310, 1969, 0],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue