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": "031eb48a-ab35-4358-b90b-4c6f50b96a38",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5334, 1614, 0],
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "0945ec2d-d81a-4b3e-9c49-4d67c615a056",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5342, 1553, 0],
|
||||
|
|
@ -39,7 +39,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "0b2133ab-a3f1-4857-80a2-c41233c499fe",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5296, 1561, 0],
|
||||
|
|
@ -58,7 +58,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "1a9ae4d0-2900-4a34-a4b0-72d5ed252665",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5200, 1565, 0],
|
||||
|
|
@ -77,7 +77,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "245b8698-8502-4d28-a477-04532306bfd3",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5271, 1693, 0],
|
||||
|
|
@ -96,7 +96,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "27edcd48-0444-44f7-a6d2-dbf5e2bb08f1",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5132, 1623, 0],
|
||||
|
|
@ -116,7 +116,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "286c764e-4d51-42fa-97d5-86fc2f4902f8",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5161, 1584, -15],
|
||||
|
|
@ -135,7 +135,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "2ce3592b-1ef9-4c42-8731-660451045829",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5363, 1709, -75],
|
||||
|
|
@ -151,7 +151,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "3e3c0553-182a-40da-b633-ef4bf2c42425",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5345, 1757, -125],
|
||||
|
|
@ -171,7 +171,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "3f984984-b04b-4635-8685-0e4e2eae07a7",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5348, 1552, 0],
|
||||
|
|
@ -187,7 +187,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "45a4e9ce-7994-4faa-bca4-adaf4e330450",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5177, 1700, 1],
|
||||
|
|
@ -206,7 +206,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "4cc200d3-c1ba-4433-92ba-fa48868ee0f8",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5336, 1708, -70],
|
||||
|
|
@ -225,7 +225,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "50432a43-ccb4-4064-8336-06ea08e4b61e",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5335, 1706, -70],
|
||||
|
|
@ -244,7 +244,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "52c5db98-5de5-4d55-9a26-85f3bc461810",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5345, 1551, 0],
|
||||
|
|
@ -260,7 +260,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "5f285bad-aaa5-40d3-add2-5b550f38e408",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5342, 1552, 0],
|
||||
|
|
@ -280,7 +280,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "656b11cd-88d3-40fb-b9dc-f830f7e22ae5",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5335, 1615, 0],
|
||||
|
|
@ -299,7 +299,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "6fe29b7c-0452-4412-a1b9-d0c30c0721fc",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5270, 1695, 0],
|
||||
|
|
@ -318,7 +318,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "7c337921-7949-4be3-bd19-9353b66560ae",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5132, 1624, 0],
|
||||
|
|
@ -337,7 +337,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "7c3950c7-e1df-4308-905f-f987fe5c9b99",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5176, 1702, 0],
|
||||
|
|
@ -356,7 +356,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "81220dc9-b072-44ff-8b29-3257236c2b25",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5343, 1551, 0],
|
||||
|
|
@ -375,7 +375,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "88aac11e-5718-4d06-be82-14b956899e5c",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5296, 1562, 0],
|
||||
|
|
@ -395,7 +395,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "8af3286d-17b3-4447-8292-ee407d69f826",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5200, 1568, 0],
|
||||
|
|
@ -414,7 +414,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "9fb21a92-1084-4819-a2b2-15e4887c701c",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5334, 1613, 0],
|
||||
|
|
@ -433,7 +433,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "b0fde845-3212-41e0-8f65-c457b0570a53",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5201, 1566, 0],
|
||||
|
|
@ -453,7 +453,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "b116f136-d3a6-43fa-b111-ef38b6ff3efa",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5270, 1694, 0],
|
||||
|
|
@ -473,7 +473,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "bdcd9c84-b005-4f1e-8c9f-0af0f8800d38",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5160, 1586, -15],
|
||||
|
|
@ -492,7 +492,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "bf601676-5f93-4b75-ae89-ac1b1a4774f6",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5176, 1701, 2],
|
||||
|
|
@ -512,7 +512,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "c3d9ecd4-8f8e-42a2-9029-b585a881657f",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5134, 1625, 0],
|
||||
|
|
@ -531,7 +531,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "c9238348-7288-4d4f-97c2-9df88a2981b3",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5365, 1707, -71],
|
||||
|
|
@ -547,7 +547,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "cff18fb7-c66e-4c05-bb2e-01f883d660ce",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5346, 1756, -125],
|
||||
|
|
@ -566,7 +566,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "d6923469-ec40-4861-a6e7-ef21b07024a7",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5344, 1757, -125],
|
||||
|
|
@ -585,7 +585,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "f1bd125f-c580-49ef-be95-922862466bad",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5335, 1707, -70],
|
||||
|
|
@ -605,7 +605,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "f27e8d0a-6a88-40e1-b02b-97b2c550065c",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5163, 1585, -15],
|
||||
|
|
@ -625,7 +625,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"type": "Spawner",
|
||||
"$type": "Spawner",
|
||||
"guid": "fab17e79-c410-496f-8cf8-b7b07363b973",
|
||||
"name": "Spawner (121)",
|
||||
"location": [5297, 1565, 0],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue