feat(progression): remaining slice 1 value objects
Lives (floors at zero, exhaustion observable), LevelId, SkillId, PlaythroughId (never self-generates, keeps tests deterministic), StatName enum, LevelTime rejects NaN/infinity. 14 tests. Arithmetic/comparison members deferred to the slices whose behaviour needs them rather than added speculatively.
This commit is contained in:
21
progression/LevelId.cs
Normal file
21
progression/LevelId.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace Mr.BrickAdventures.Progression;
|
||||
|
||||
/// <summary>
|
||||
/// Stable identity of a Level. Never a position in a list — Playthroughs and Best Times both
|
||||
/// reference Levels, so ids must survive inserting and reordering.
|
||||
/// </summary>
|
||||
public readonly struct LevelId : IEquatable<LevelId>
|
||||
{
|
||||
public string Value { get; }
|
||||
|
||||
private LevelId(string value) => Value = value;
|
||||
|
||||
public static LevelId Of(string value) => string.IsNullOrWhiteSpace(value)
|
||||
? throw new ArgumentException("A level id cannot be blank.", nameof(value))
|
||||
: new LevelId(value);
|
||||
|
||||
public bool Equals(LevelId other) => string.Equals(Value, other.Value, StringComparison.Ordinal);
|
||||
public override bool Equals(object? obj) => obj is LevelId other && Equals(other);
|
||||
public override int GetHashCode() => StringComparer.Ordinal.GetHashCode(Value ?? string.Empty);
|
||||
public override string ToString() => Value;
|
||||
}
|
||||
@@ -10,7 +10,7 @@ public readonly struct LevelTime
|
||||
|
||||
private LevelTime(double seconds) => Seconds = seconds;
|
||||
|
||||
public static LevelTime Of(double seconds) => seconds <= 0
|
||||
? throw new ArgumentOutOfRangeException(nameof(seconds), seconds, "A completion time must be positive.")
|
||||
: new LevelTime(seconds);
|
||||
public static LevelTime Of(double seconds) => double.IsFinite(seconds) && seconds > 0
|
||||
? new LevelTime(seconds)
|
||||
: throw new ArgumentOutOfRangeException(nameof(seconds), seconds, "A completion time must be a finite positive number.");
|
||||
}
|
||||
|
||||
24
progression/Lives.cs
Normal file
24
progression/Lives.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
namespace Mr.BrickAdventures.Progression;
|
||||
|
||||
/// <summary>
|
||||
/// Lives remaining in a Playthrough. Never negative.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Decrementing at zero floors rather than failing — unlike <see cref="Coins"/>, where a shortfall
|
||||
/// is a game rule the caller must handle. Flooring here is purely defensive; the invariant that one
|
||||
/// death costs exactly one life is enforced by the Attempt's outcome, not by this type.
|
||||
/// </remarks>
|
||||
public readonly struct Lives
|
||||
{
|
||||
public int Value { get; }
|
||||
|
||||
private Lives(int value) => Value = value;
|
||||
|
||||
public static Lives Of(int value) => value < 0
|
||||
? throw new ArgumentOutOfRangeException(nameof(value), value, "Lives cannot be negative.")
|
||||
: new Lives(value);
|
||||
|
||||
public bool IsExhausted => Value == 0;
|
||||
|
||||
public Lives Decrement() => new(Value == 0 ? 0 : Value - 1);
|
||||
}
|
||||
25
progression/PlaythroughId.cs
Normal file
25
progression/PlaythroughId.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
namespace Mr.BrickAdventures.Progression;
|
||||
|
||||
/// <summary>
|
||||
/// Identity of one Playthrough. Several Playthroughs exist at once and the player picks between
|
||||
/// them; "slot" is the word the UI uses for the same thing.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Deliberately has no factory that generates a value. Ids are created by an adapter and passed in,
|
||||
/// so nothing in the domain depends on a source of randomness.
|
||||
/// </remarks>
|
||||
public readonly struct PlaythroughId : IEquatable<PlaythroughId>
|
||||
{
|
||||
public Guid Value { get; }
|
||||
|
||||
private PlaythroughId(Guid value) => Value = value;
|
||||
|
||||
public static PlaythroughId Of(Guid value) => value == Guid.Empty
|
||||
? throw new ArgumentException("A playthrough id cannot be the empty guid.", nameof(value))
|
||||
: new PlaythroughId(value);
|
||||
|
||||
public bool Equals(PlaythroughId other) => Value.Equals(other.Value);
|
||||
public override bool Equals(object? obj) => obj is PlaythroughId other && Equals(other);
|
||||
public override int GetHashCode() => Value.GetHashCode();
|
||||
public override string ToString() => Value.ToString();
|
||||
}
|
||||
21
progression/SkillId.cs
Normal file
21
progression/SkillId.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace Mr.BrickAdventures.Progression;
|
||||
|
||||
/// <summary>
|
||||
/// Stable identity of a Skill, matching the authored <c>SkillData</c> name that saves already
|
||||
/// reference. Identity only — the upgrade table and presentation stay in the authored asset.
|
||||
/// </summary>
|
||||
public readonly struct SkillId : IEquatable<SkillId>
|
||||
{
|
||||
public string Value { get; }
|
||||
|
||||
private SkillId(string value) => Value = value;
|
||||
|
||||
public static SkillId Of(string value) => string.IsNullOrWhiteSpace(value)
|
||||
? throw new ArgumentException("A skill id cannot be blank.", nameof(value))
|
||||
: new SkillId(value);
|
||||
|
||||
public bool Equals(SkillId other) => string.Equals(Value, other.Value, StringComparison.Ordinal);
|
||||
public override bool Equals(object? obj) => obj is SkillId other && Equals(other);
|
||||
public override int GetHashCode() => StringComparer.Ordinal.GetHashCode(Value ?? string.Empty);
|
||||
public override string ToString() => Value;
|
||||
}
|
||||
18
progression/StatName.cs
Normal file
18
progression/StatName.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace Mr.BrickAdventures.Progression;
|
||||
|
||||
/// <summary>
|
||||
/// The closed set of statistics a Profile tracks. Mirrors the five names in the old
|
||||
/// <c>StatNames</c> constants, but as a type, so a typo cannot invent a sixth statistic.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Persisted names live at the persistence seam, not here — the store adapter maps these to and
|
||||
/// from the wire strings and decides what to do with unknown keys from an older save.
|
||||
/// </remarks>
|
||||
public enum StatName
|
||||
{
|
||||
CoinsCollected,
|
||||
EnemiesDefeated,
|
||||
Deaths,
|
||||
LevelsCompleted,
|
||||
ChildrenRescued,
|
||||
}
|
||||
Reference in New Issue
Block a user