Use a simpler override where available

This commit is contained in:
Tim Van Baak 2024-08-12 14:57:16 -07:00
parent 11dfa403e4
commit 3242186208
3 changed files with 5 additions and 11 deletions

View File

@ -37,7 +37,7 @@ public class World
/// <summary> /// <summary>
/// The first season of the game. /// The first season of the game.
/// </summary> /// </summary>
public Season RootSeason => GetSeason("a", 0); public Season RootSeason => GetSeason("a0");
/// <summary> /// <summary>
/// All units in the multiverse. /// All units in the multiverse.
@ -227,13 +227,7 @@ public class World
/// Get a season by coordinate. Throws if the season is not found. /// Get a season by coordinate. Throws if the season is not found.
/// </summary> /// </summary>
public Season GetSeason(string timeline, int turn) public Season GetSeason(string timeline, int turn)
{ => GetSeason($"{timeline}{turn}");
Season? foundSeason = this.Seasons.SingleOrDefault(
s => s!.Turn == turn && s.Timeline == timeline,
null)
?? throw new KeyNotFoundException($"Season {timeline}@{turn} not found");
return foundSeason;
}
public Season GetSeason(string designation) public Season GetSeason(string designation)
=> SeasonLookup[designation]; => SeasonLookup[designation];

View File

@ -42,7 +42,7 @@ public class TimeTravelTest
"Failed to fork timeline when unit moved in"); "Failed to fork timeline when unit moved in");
// Confirm that there is a unit in Tyr b1 originating from Mun a1 // Confirm that there is a unit in Tyr b1 originating from Mun a1
Season fork = world.GetSeason("b", 1); Season fork = world.GetSeason("b1");
Unit originalUnit = world.GetUnitAt("Mun", s0.Coord); Unit originalUnit = world.GetUnitAt("Mun", s0.Coord);
Unit aMun0 = world.GetUnitAt("Mun", s1.Coord); Unit aMun0 = world.GetUnitAt("Mun", s1.Coord);
Unit aTyr = world.GetUnitAt("Tyr", fork.Coord); Unit aTyr = world.GetUnitAt("Tyr", fork.Coord);
@ -91,7 +91,7 @@ public class TimeTravelTest
// Confirm that an alternate future is created. // Confirm that an alternate future is created.
World world = setup.UpdateWorld(); World world = setup.UpdateWorld();
Season fork = world.GetSeason("b", 1); Season fork = world.GetSeason("b1");
Unit tyr1 = world.GetUnitAt("Tyr", fork.Coord); Unit tyr1 = world.GetUnitAt("Tyr", fork.Coord);
Assert.That( Assert.That(
tyr1.Past, tyr1.Past,

View File

@ -199,7 +199,7 @@ public class MovementAdjudicatorTest
World updated = setup.UpdateWorld(); World updated = setup.UpdateWorld();
// Confirm the future was created // Confirm the future was created
Season s2 = updated.GetSeason("a", 1); Season s2 = updated.GetSeason("a1");
Assert.That(s2.Past, Is.EqualTo(s1.ToString())); Assert.That(s2.Past, Is.EqualTo(s1.ToString()));
Assert.That(s2.Futures, Is.Empty); Assert.That(s2.Futures, Is.Empty);
Assert.That(s2.Timeline, Is.EqualTo(s1.Timeline)); Assert.That(s2.Timeline, Is.EqualTo(s1.Timeline));