From 0daf9a1b4f46a370862211973ccb110d8b0ee8fa Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Thu, 25 Jun 2026 23:08:04 -0700 Subject: [PATCH] refactor(spawners): drop trivial Dto* helpers; reference public properties Guid/MinDelay/MaxDelay/Team/SpawnLocationIsHome have plain public properties, so ToDto uses them directly. Keep DtoWalkingRange (public WalkingRange is computed), DtoName (DefaultName -> null), DtoSpawnPositionMode/DtoMaxSpawnAttempts (sentinel mapping), DtoHomeRange. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../Engines/Spawners/BaseSpawner.Dto.cs | 27 ++++++++++++------- .../Engines/Spawners/ProximitySpawner.Dto.cs | 10 +++---- .../Engines/Spawners/RegionSpawner.Dto.cs | 10 +++---- .../UOContent/Engines/Spawners/Spawner.Dto.cs | 10 +++---- 4 files changed, 32 insertions(+), 25 deletions(-) diff --git a/Projects/UOContent/Engines/Spawners/BaseSpawner.Dto.cs b/Projects/UOContent/Engines/Spawners/BaseSpawner.Dto.cs index af5fae281..d5c2d5e5e 100644 --- a/Projects/UOContent/Engines/Spawners/BaseSpawner.Dto.cs +++ b/Projects/UOContent/Engines/Spawners/BaseSpawner.Dto.cs @@ -78,23 +78,30 @@ public abstract partial class BaseSpawner ); } - // Export helpers. Options use WhenWritingDefault, so optional fields are omitted at their CLR - // default; helpers below map non-CLR-default "omit" values onto the default so they drop out. - private protected Guid DtoGuid => _guid; - private protected string DtoName => string.IsNullOrEmpty(Name) ? null : Name; - private protected TimeSpan DtoMinDelay => _minDelay; - private protected TimeSpan DtoMaxDelay => _maxDelay; - private protected int DtoTeam => _team; + private protected string DtoName + { + get + { + var name = Name; + return string.IsNullOrEmpty(name) || name == DefaultName ? null : name; + } + } + + // Export helpers for values whose ToDto form differs from the public property. Options use + // WhenWritingDefault, so non-CLR-default "omit" values are mapped onto the default to drop out. + // Fields with a plain matching public property (Guid/MinDelay/MaxDelay/Team/SpawnLocationIsHome) + // are referenced directly in ToDto and need no helper. + + // The public WalkingRange property is computed (falls back to HomeRange), so it cannot be used + // here without losing the raw -1 round-trip. private protected int DtoWalkingRange => _walkingRange; - private protected bool DtoSpawnLocationIsHome => _spawnLocationIsHome; // Abandoned is a transient "gave up" runtime state, not persisted -> map to Automatic (omitted). private protected SpawnPositionMode DtoSpawnPositionMode => _spawnPositionMode == SpawnPositionMode.Abandoned ? SpawnPositionMode.Automatic : _spawnPositionMode; // Runtime treats 0 identically to DefaultMaxSpawnAttempts(10) -> map the default to 0 (omitted). - private protected int DtoMaxSpawnAttempts => - _maxSpawnAttempts == DefaultMaxSpawnAttempts ? 0 : _maxSpawnAttempts; + private protected int DtoMaxSpawnAttempts => _maxSpawnAttempts == DefaultMaxSpawnAttempts ? 0 : _maxSpawnAttempts; // The homeRange radius if SpawnBounds is EXACTLY what that radius reconstructs (square, centered, // standard z/depth) so the round-trip is lossless; otherwise -1 (write spawnBounds instead). diff --git a/Projects/UOContent/Engines/Spawners/ProximitySpawner.Dto.cs b/Projects/UOContent/Engines/Spawners/ProximitySpawner.Dto.cs index a74b7a358..219e91943 100644 --- a/Projects/UOContent/Engines/Spawners/ProximitySpawner.Dto.cs +++ b/Projects/UOContent/Engines/Spawners/ProximitySpawner.Dto.cs @@ -22,17 +22,17 @@ public partial class ProximitySpawner var homeRange = DtoHomeRange; return new ProximitySpawnerDto { - Guid = DtoGuid, + Guid = Guid, Name = DtoName, Location = Location, Map = Map, Count = Count, - MinDelay = DtoMinDelay, - MaxDelay = DtoMaxDelay, - Team = DtoTeam, + MinDelay = MinDelay, + MaxDelay = MaxDelay, + Team = Team, WalkingRange = DtoWalkingRange, Entries = Entries, - SpawnLocationIsHome = DtoSpawnLocationIsHome, + SpawnLocationIsHome = SpawnLocationIsHome, SpawnPositionMode = DtoSpawnPositionMode, MaxSpawnAttempts = DtoMaxSpawnAttempts, HomeRange = homeRange, diff --git a/Projects/UOContent/Engines/Spawners/RegionSpawner.Dto.cs b/Projects/UOContent/Engines/Spawners/RegionSpawner.Dto.cs index 23e8ebcb4..3d9614247 100644 --- a/Projects/UOContent/Engines/Spawners/RegionSpawner.Dto.cs +++ b/Projects/UOContent/Engines/Spawners/RegionSpawner.Dto.cs @@ -20,17 +20,17 @@ public partial class RegionSpawner // RegionSpawner spawns from region rectangles, so it writes neither homeRange nor spawnBounds. public override SpawnerDto ToDto() => new RegionSpawnerDto { - Guid = DtoGuid, + Guid = Guid, Name = DtoName, Location = Location, Map = Map, Count = Count, - MinDelay = DtoMinDelay, - MaxDelay = DtoMaxDelay, - Team = DtoTeam, + MinDelay = MinDelay, + MaxDelay = MaxDelay, + Team = Team, WalkingRange = DtoWalkingRange, Entries = Entries, - SpawnLocationIsHome = DtoSpawnLocationIsHome, + SpawnLocationIsHome = SpawnLocationIsHome, SpawnPositionMode = DtoSpawnPositionMode, MaxSpawnAttempts = DtoMaxSpawnAttempts, Region = SpawnRegion?.Name diff --git a/Projects/UOContent/Engines/Spawners/Spawner.Dto.cs b/Projects/UOContent/Engines/Spawners/Spawner.Dto.cs index 6d867089f..a291a4854 100644 --- a/Projects/UOContent/Engines/Spawners/Spawner.Dto.cs +++ b/Projects/UOContent/Engines/Spawners/Spawner.Dto.cs @@ -22,17 +22,17 @@ public partial class Spawner var homeRange = DtoHomeRange; return new SpawnerDataDto { - Guid = DtoGuid, + Guid = Guid, Name = DtoName, Location = Location, Map = Map, Count = Count, - MinDelay = DtoMinDelay, - MaxDelay = DtoMaxDelay, - Team = DtoTeam, + MinDelay = MinDelay, + MaxDelay = MaxDelay, + Team = Team, WalkingRange = DtoWalkingRange, Entries = Entries, - SpawnLocationIsHome = DtoSpawnLocationIsHome, + SpawnLocationIsHome = SpawnLocationIsHome, SpawnPositionMode = DtoSpawnPositionMode, MaxSpawnAttempts = DtoMaxSpawnAttempts, HomeRange = homeRange,