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) <noreply@anthropic.com>
This commit is contained in:
parent
b77f7c1c50
commit
0daf9a1b4f
4 changed files with 32 additions and 25 deletions
|
|
@ -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).
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue