From f2d3d5a583c4298c00a795c1527851364217630c Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Wed, 14 Aug 2024 22:03:56 -0700 Subject: [PATCH] Remove GetSeason(string) --- MultiversalDiplomacy/Adjudicate/PathFinder.cs | 8 ++++---- MultiversalDiplomacy/Model/World.cs | 14 ++++---------- MultiversalDiplomacyTests/MDATC_A.cs | 4 ++-- .../MovementAdjudicatorTest.cs | 2 +- MultiversalDiplomacyTests/SeasonTests.cs | 2 +- MultiversalDiplomacyTests/SerializationTest.cs | 4 ++-- 6 files changed, 14 insertions(+), 20 deletions(-) diff --git a/MultiversalDiplomacy/Adjudicate/PathFinder.cs b/MultiversalDiplomacy/Adjudicate/PathFinder.cs index 0c64685..d60881c 100644 --- a/MultiversalDiplomacy/Adjudicate/PathFinder.cs +++ b/MultiversalDiplomacy/Adjudicate/PathFinder.cs @@ -114,7 +114,7 @@ public static class PathFinder List adjacents = []; // The immediate past and all immediate futures are adjacent. - if (season.Past != null) adjacents.Add(world.GetSeason(season.Past)); + if (season.Past != null) adjacents.Add(world.Seasons[season.Past]); adjacents.AddRange(world.GetFutures(season)); // Find all adjacent timelines by finding all timelines that branched off of this season's @@ -123,8 +123,8 @@ public static class PathFinder List adjacentTimelineRoots = []; Season? current; for (current = season; - current?.Past != null && world.GetSeason(current.Past).Timeline == current.Timeline; - current = world.GetSeason(current.Past)) + current?.Past != null && world.Seasons[current.Past].Timeline == current.Timeline; + current = world.Seasons[current.Past]) { adjacentTimelineRoots.AddRange( world.GetFutures(current).Where(s => s.Timeline != current.Timeline)); @@ -135,7 +135,7 @@ public static class PathFinder // then current is the branch timeline's root season (current.past.timeline != // current.timeline). There are co-branches if this season is in a branched timeline, since // the first timeline by definition cannot have co-branches. - if (current?.Past != null && world.GetSeason(current.Past) is Season past) + if (current?.Past != null && world.Seasons[current.Past] is Season past) { IEnumerable cobranchRoots = world .GetFutures(past) diff --git a/MultiversalDiplomacy/Model/World.cs b/MultiversalDiplomacy/Model/World.cs index fe3aeb8..35814c4 100644 --- a/MultiversalDiplomacy/Model/World.cs +++ b/MultiversalDiplomacy/Model/World.cs @@ -48,7 +48,7 @@ public class World /// The first season of the game. /// [JsonIgnore] - public Season RootSeason => GetSeason("a0"); + public Season RootSeason => Seasons["a0"]; /// /// All units in the multiverse. @@ -256,13 +256,7 @@ public class World /// Get a season by coordinate. Throws if the season is not found. /// public Season GetSeason(string timeline, int turn) - => GetSeason($"{timeline}{turn}"); - - /// - /// Get a season by designation. - /// - public Season GetSeason(string designation) - => Seasons[designation]; + => Seasons[$"{timeline}{turn}"]; /// /// Get all seasons that are immediate futures of a season. @@ -311,8 +305,8 @@ public class World // if they both branched off of the same point. Season rootOne = GetTimelineRoot(one); Season rootTwo = GetTimelineRoot(two); - bool oneForked = rootOne.Past != null && GetSeason(rootOne.Past).Timeline == two.Timeline; - bool twoForked = rootTwo.Past != null && GetSeason(rootTwo.Past).Timeline == one.Timeline; + bool oneForked = rootOne.Past != null && Seasons[rootOne.Past].Timeline == two.Timeline; + bool twoForked = rootTwo.Past != null && Seasons[rootTwo.Past].Timeline == one.Timeline; bool bothForked = rootOne.Past == rootTwo.Past; return oneForked || twoForked || bothForked; } diff --git a/MultiversalDiplomacyTests/MDATC_A.cs b/MultiversalDiplomacyTests/MDATC_A.cs index 7603f72..e28cc85 100644 --- a/MultiversalDiplomacyTests/MDATC_A.cs +++ b/MultiversalDiplomacyTests/MDATC_A.cs @@ -42,7 +42,7 @@ public class TimeTravelTest "Failed to fork timeline when unit moved in"); // Confirm that there is a unit in Tyr b1 originating from Mun a1 - Season fork = world.GetSeason("b1"); + Season fork = world.Seasons["b1"]; Unit originalUnit = world.GetUnitAt("Mun", s0); Unit aMun0 = world.GetUnitAt("Mun", s1); Unit aTyr = world.GetUnitAt("Tyr", fork); @@ -91,7 +91,7 @@ public class TimeTravelTest // Confirm that an alternate future is created. World world = setup.UpdateWorld(); - Season fork = world.GetSeason("b1"); + Season fork = world.Seasons["b1"]; Unit tyr1 = world.GetUnitAt("Tyr", fork); Assert.That( tyr1.Past, diff --git a/MultiversalDiplomacyTests/MovementAdjudicatorTest.cs b/MultiversalDiplomacyTests/MovementAdjudicatorTest.cs index 27aded2..cae7c71 100644 --- a/MultiversalDiplomacyTests/MovementAdjudicatorTest.cs +++ b/MultiversalDiplomacyTests/MovementAdjudicatorTest.cs @@ -199,7 +199,7 @@ public class MovementAdjudicatorTest World updated = setup.UpdateWorld(); // Confirm the future was created - Season s2 = updated.GetSeason("a1"); + Season s2 = updated.Seasons["a1"]; Assert.That(s2.Past, Is.EqualTo(s1.ToString())); Assert.That(updated.GetFutures(s2), Is.Empty); Assert.That(s2.Timeline, Is.EqualTo(s1.Timeline)); diff --git a/MultiversalDiplomacyTests/SeasonTests.cs b/MultiversalDiplomacyTests/SeasonTests.cs index adc2fcf..17a44c9 100644 --- a/MultiversalDiplomacyTests/SeasonTests.cs +++ b/MultiversalDiplomacyTests/SeasonTests.cs @@ -10,7 +10,7 @@ public class SeasonTests public void TimelineForking() { World world = World.WithMap(Map.Test); - Season a0 = world.GetSeason("a0"); + Season a0 = world.Seasons["a0"]; world = world .ContinueOrFork(a0, out Season a1) .ContinueOrFork(a1, out Season a2) diff --git a/MultiversalDiplomacyTests/SerializationTest.cs b/MultiversalDiplomacyTests/SerializationTest.cs index 146a8bf..3b5ffd8 100644 --- a/MultiversalDiplomacyTests/SerializationTest.cs +++ b/MultiversalDiplomacyTests/SerializationTest.cs @@ -86,7 +86,7 @@ public class SerializationTest setup = new(reserialized, MovementPhaseAdjudicator.Instance); setup[("a", 1)] ["Germany"] - .Army("Mun").Supports.Army("Mun", season: reserialized.GetSeason("a0")).MoveTo("Tyr").GetReference(out var mun1) + .Army("Mun").Supports.Army("Mun", season: reserialized.Seasons["a0"]).MoveTo("Tyr").GetReference(out var mun1) ["Austria"] .Army("Tyr").Holds(); @@ -102,7 +102,7 @@ public class SerializationTest // Confirm that an alternate future is created. World world = setup.UpdateWorld(); - Season fork = world.GetSeason("b1"); + Season fork = world.Seasons["b1"]; Unit tyr1 = world.GetUnitAt("Tyr", fork); Assert.That( tyr1.Past,