A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Minimap: Borders/Labels start from the map's switches; #2231 test follow-ups (Refs #2231) (#2244)
Eyal Golanc3979aaca7a6
diff --git a/changelog.d/2231-minimap-followup.md b/changelog.d/2231-minimap-followup.mdnew file mode 100644index 000000000..e9ce014b1--- /dev/null+++ b/changelog.d/2231-minimap-followup.md@@ -0,0 +1,5 @@+### Fixed++- The minimap's Borders and Labels buttons now start from the map's own switches after a language switch, New Game or a+ load, and dim to match, so a button and its layer cannot disagree. The 1949 armistice lines follow the Borders button+ then too.diff --git a/unity/Assets/Scripts/Map/MapBorders.cs b/unity/Assets/Scripts/Map/MapBorders.csindex 9c61c9797..f76cde1bf 100644--- a/unity/Assets/Scripts/Map/MapBorders.cs+++ b/unity/Assets/Scripts/Map/MapBorders.cs@@ -212,7 +212,8 @@ namespace Statecraft.Game.Mapstatic bool hasLayer, toggleOn = true;static bool noEarlyOut;- /// <summary>Test seam (internal): the "borders" switch as last set (on at every build), drawn or not (#2227).</summary>+ /// <summary>The "borders" switch as last set (on at every build), drawn or not: a new minimap starts from it (#2227).+ /// A torn-down map does not reset it, so read it only while the switch is registered.</summary>internal static bool ToggleOn => toggleOn;/// <summary>Test seam (_ScBorders.z): true draws every pixel the long way, with no early-out, so a test can prove thediff --git a/unity/Assets/Scripts/UI/MapLabelsPresenter.cs b/unity/Assets/Scripts/UI/MapLabelsPresenter.csindex bdb21a155..457ddc34c 100644--- a/unity/Assets/Scripts/UI/MapLabelsPresenter.cs+++ b/unity/Assets/Scripts/UI/MapLabelsPresenter.cs@@ -72,6 +72,9 @@ namespace Statecraft.Game.UI{public const string ContainerName = "map-labels", SlotClass = "map-label-slot", LabelClass = "map-label";public const string RouteTurnClass = "map-route-turn";+ /// <summary>The "labels" switch's state: it hides the names' container (ContainerName) inline, and the container+ /// outlives the presenter, so a new minimap starts from it (#2227).</summary>+ public static bool SwitchedOn(VisualElement container) => container.style.display.value != DisplayStyle.None;public const float LiftPx = 6f, MarginPx = 4f, DeclutterDistanceM = 150000f;/// <summary>The 1948 localities are named only nearer than this (owner ruling 2026-10-11: names at closer zoom, so/// the map is not cluttered); farther out their pills are hidden and their places are nobody's neighbour.</summary>diff --git a/unity/Assets/Scripts/UI/MinimapPresenter.cs b/unity/Assets/Scripts/UI/MinimapPresenter.csindex 75faa59e8..853c9c6e8 100644--- a/unity/Assets/Scripts/UI/MinimapPresenter.cs+++ b/unity/Assets/Scripts/UI/MinimapPresenter.cs@@ -56,9 +56,14 @@ namespace Statecraft.Game.UIoverview = box.Q<Button>("minimap-overview"); labels = box.Q<Button>("minimap-labels"); borders = box.Q<Button>("minimap-borders");overview.clicked += OnOverview; labels.clicked += OnLabels; borders.clicked += OnBorders;// #2227: GameRoot.Begin (New Game, a load, the language switch) makes a new presenter over the same document and- // the same map, whose switches keep what the last press set; a button dims only together with its switch- // (Switch), so the dim says what the map shows and the new presenter starts from it, keeping the player's choice.- LabelsShown = !labels.ClassListContains(OffClass); BordersShown = !borders.ClassListContains(OffClass);+ // the same map, whose switches keep what was last set. Each button starts from its switch and dims to match, so+ // the two cannot disagree (review of #2231, C1); with no map (a test), a button keeps its own dim. The names'+ // switch is their container's display (Begin makes the MapLabelsPresenter that registers it after this one),+ // and the armistice lines go with Borders (#2195).+ BordersShown = VisualToggles.Names.Contains(MapBorders.ToggleName) ? MapBorders.ToggleOn : !borders.ClassListContains(OffClass);+ LabelsShown = root.Q(MapLabelsPresenter.ContainerName) is VisualElement names ? MapLabelsPresenter.SwitchedOn(names) : !labels.ClassListContains(OffClass);+ borders.EnableInClassList(OffClass, !BordersShown); labels.EnableInClassList(OffClass, !LabelsShown);+ if (VisualToggles.Names.Contains(ArmisticeLines.ToggleName)) VisualToggles.Set(ArmisticeLines.ToggleName, BordersShown);if (text != null){overview.tooltip = text["minimap.overview"]; labels.tooltip = text["minimap.labels"]; borders.tooltip = text["minimap.borders"];diff --git a/unity/Assets/Tests/EditMode/MinimapRestartTests.cs b/unity/Assets/Tests/EditMode/MinimapRestartTests.csindex 825fb2d3f..756eab982 100644--- a/unity/Assets/Tests/EditMode/MinimapRestartTests.cs+++ b/unity/Assets/Tests/EditMode/MinimapRestartTests.cs@@ -88,6 +88,9 @@ public class MinimapRestartTestsAssert.AreEqual(MapBorders.ToggleOn, mini.BordersShown, "the Borders button says what the borders switch does");Assert.AreEqual(LabelsOn, mini.LabelsShown, "the Labels button says what the labels switch does");Assert.IsFalse(MapBorders.ToggleOn || LabelsOn, "the restart keeps the player's choice: both layers stay off");+ // Review of #2231, C2: MapRegions.Shown is false when no layer is drawn, and then both caption asserts hold+ // whatever the caption does; the start date draws one, so they pin it.+ Assert.IsTrue(root.Regions!.Shown, "precondition: the start date draws a region layer");Assert.AreEqual(root.Regions!.Shown && MapBorders.ToggleOn, CaptionShown, "the border caption follows the borders");UiTestKit.Press(ui.Q<Button>("minimap-borders"));@@ -96,11 +99,57 @@ public class MinimapRestartTestsAssert.IsTrue(LabelsOn && mini.LabelsShown, "one press brings the names back");Assert.AreEqual(root.Regions!.Shown, CaptionShown, "and the border caption with them");}- finally+ finally { SwitchesOn(); }+ }++ /// <summary>Review of #2231, C1: the map's switches are the truth, not the buttons' dim. A switch set behind its button's+ /// back (VisualToggles.Set, as the dev instruments do) disagrees with the button until the next Begin, whose minimap+ /// starts from the switches and dims its buttons to match; the armistice lines go with the Borders button (#2195).</summary>+ [UnityTest]+ public IEnumerator AfterARestartTheButtonsFollowTheSwitchesNotTheirOldDim()+ {+ yield return Boot();+ try{- // VisualToggles and MapBorders are static: leave both switches on for the next test.- if (VisualToggles.Names.Contains(MapBorders.ToggleName)) VisualToggles.Set(MapBorders.ToggleName, true);- if (VisualToggles.Names.Contains(MinimapPresenter.LabelsToggle)) VisualToggles.Set(MinimapPresenter.LabelsToggle, true);+ Assert.IsTrue(VisualToggles.Names.Contains(MapBorders.ToggleName) && VisualToggles.Names.Contains(MinimapPresenter.LabelsToggle)+ && VisualToggles.Names.Contains(ArmisticeLines.ToggleName), "precondition: the map's switches, the armistice lines' too");+ var bordersButton = ui.Q<Button>("minimap-borders"); var labelsButton = ui.Q<Button>("minimap-labels");+ UiTestKit.Press(labelsButton); // the Labels button dims with its switch+ VisualToggles.Set(MapBorders.ToggleName, false); // the borders go off behind an undimmed button+ VisualToggles.Set(MinimapPresenter.LabelsToggle, true); // the names come back behind a dimmed one+ Assert.IsFalse(MapBorders.ToggleOn || bordersButton.ClassListContains(MinimapPresenter.OffClass), "precondition: borders off, their button not dimmed");+ Assert.IsTrue(LabelsOn && labelsButton.ClassListContains(MinimapPresenter.OffClass), "precondition: names on, their button dimmed");+ Assert.IsTrue(ArmisticeOn, "precondition: the armistice lines are still shown");++ root.Begin(MapFocusTests.Inputs, 0, keep: root.Bridge); // a restart over the same map (as SwitchLanguage)+ GameSceneTests.HideTheOpeningCard(ui);+ yield return Frames(3);+ var mini = root.Minimap ?? throw new AssertionException("precondition: the restart made a minimap");++ Assert.IsFalse(mini.BordersShown, "the Borders button reads the borders switch: off");+ Assert.IsTrue(bordersButton.ClassListContains(MinimapPresenter.OffClass), "and dims to say so");+ Assert.IsTrue(mini.LabelsShown, "the Labels button reads the names' switch: on");+ Assert.IsFalse(labelsButton.ClassListContains(MinimapPresenter.OffClass), "and is not dimmed");+ Assert.IsFalse(ArmisticeOn, "the armistice lines go with the Borders button");+ Assert.IsTrue(root.Regions!.Shown, "precondition: the start date draws a region layer");+ Assert.IsFalse(CaptionShown, "no border caption over hidden borders");++ UiTestKit.Press(bordersButton);+ Assert.IsTrue(MapBorders.ToggleOn && mini.BordersShown && ArmisticeOn, "one press brings the borders and the lines back");+ Assert.IsTrue(CaptionShown, "and the border caption with them");}+ finally { SwitchesOn(); }+ }++ /// <summary>The armistice lines' switch's real state: it shows or hides the overlay's "Lines" child.</summary>+ bool ArmisticeOn => Object.FindFirstObjectByType<MapScene>().Terrain.transform.Find(ArmisticeLines.RootName + "/Lines").gameObject.activeSelf;++ /// <summary>The global state these tests change: VisualToggles' switches and MapBorders' toggleOn (static, set through+ /// the "borders" switch). The minimap's buttons, the GameRoot and its Language belong to the scene, which TearDown+ /// discards. Left on for the next test however the test ended.</summary>+ static void SwitchesOn()+ {+ foreach (var name in new[] { MapBorders.ToggleName, MinimapPresenter.LabelsToggle, ArmisticeLines.ToggleName })+ if (VisualToggles.Names.Contains(name)) VisualToggles.Set(name, true);}}