A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
fix(ui): dates through PlayerText, IL currency, (vacant) budget lines, Ongoing effects
eyalgolan7191a32f28e9
diff --git a/content/offices.yaml b/content/offices.yamlindex a8c7e8e31..9805334e8 100644--- a/content/offices.yaml+++ b/content/offices.yaml@@ -1,5 +1,8 @@offices:- { id: prime_minister, title: Prime Minister }+ # Spelling is deliberate, do not "fix" it (playtest 1, item 8): the office title keeps Israel's official English,+ # "Ministry of Defense" / "Minister of Defense", because it is a proper noun. The UI is otherwise British English, so+ # the screen and its button say "Defence".- { id: defense_minister, title: Minister of Defense }- { id: finance_minister, title: Minister of Finance }- { id: foreign_minister, title: Minister of Foreign Affairs }diff --git a/unity/Assets/Scripts/UI/BudgetPresenter.cs b/unity/Assets/Scripts/UI/BudgetPresenter.csindex fe17dd884..066a2e7da 100644--- a/unity/Assets/Scripts/UI/BudgetPresenter.cs+++ b/unity/Assets/Scripts/UI/BudgetPresenter.cs@@ -111,7 +111,7 @@ namespace Statecraft.Game.UIvar share = draft.TryGetValue(office, out var v) ? v : 0;var row = new VisualElement { name = "budget-" + office };row.AddToClassList("row");- row.Add(new Label(text.Format("budget.office", o.Title, Cabinet.Holder(c, s, office)?.Name ?? "-")) { name = "budget-" + office + "-name" });+ row.Add(new Label(text.Format("budget.office", o.Title, Cabinet.Holder(c, s, office)?.Name ?? text["budget.vacant"])) { name = "budget-" + office + "-name" });row[0].AddToClassList("grow");row.Add(new Button(() => Change(office, -Step)) { name = "budget-" + office + "-down", text = "-" });row.Add(new Label(text.Format("budget.share", share * 100)) { name = "budget-" + office + "-share" });diff --git a/unity/Assets/Scripts/UI/HudModel.cs b/unity/Assets/Scripts/UI/HudModel.csindex 16c821153..c7ede0f8b 100644--- a/unity/Assets/Scripts/UI/HudModel.cs+++ b/unity/Assets/Scripts/UI/HudModel.cs@@ -38,7 +38,7 @@ namespace Statecraft.Game.UI{Year = s.Date.Year.ToString(System.Globalization.CultureInfo.InvariantCulture),Turn = t.Format("hud.turn", s.Turn),- Date = t.Format("hud.date", s.Date),+ Date = t.Format("hud.date", PlayerText.Date(s.Date)),Attention = t.Format("hud.attention", b.AttentionLeft, c.Rules.AttentionPerTurn),SecurityLevel = t.Format("hud.level", s.Rung),Treasury = M(s.Treasury - s.Debt, prev == null ? (double?)null : prev.Treasury - prev.Debt, "hud.money", "hud.delta_money"),diff --git a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs b/unity/Assets/Scripts/UI/InfoPanelPresenter.csindex 163d09bac..dadf8f6f4 100644--- a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs+++ b/unity/Assets/Scripts/UI/InfoPanelPresenter.cs@@ -63,7 +63,7 @@ namespace Statecraft.Game.UIvar here = MapActions.At(s, q, r);var queued = bridge.QueuedLike(new MapAction(MapActions.Housing, q, r)) as MapAction;placement.text = queued != null ? text.Format("info.queued", text["info." + queued.Action])- : here != null ? text.Format("info.built", text["info." + here.Action], here.Date) : "";+ : here != null ? text.Format("info.built", text["info." + here.Action], PlayerText.Month(here.Date)) : "";var campWhy = MapActions.Check(c, s, MapActions.TransitCamp, q, r);var housingWhy = MapActions.Check(c, s, MapActions.Housing, q, r);camp.style.display = DisplayStyle.Flex; housing.style.display = DisplayStyle.Flex;diff --git a/unity/Assets/Scripts/UI/WhyPresenter.cs b/unity/Assets/Scripts/UI/WhyPresenter.csindex caccd3300..36b6b6e57 100644--- a/unity/Assets/Scripts/UI/WhyPresenter.cs+++ b/unity/Assets/Scripts/UI/WhyPresenter.cs@@ -36,7 +36,7 @@ namespace Statecraft.Game.UIvar rows = screen.Q<ScrollView>("why-rows");rows.Clear();var prev = bridge.Session.Previous;- screen.Q<Label>("why-turn").text = last == null || prev == null ? "" : text.Format("why.turn", prev.Date, bridge.State.Date);+ screen.Q<Label>("why-turn").text = last == null || prev == null ? "" : text.Format("why.turn", PlayerText.Date(prev.Date), PlayerText.Date(bridge.State.Date));if (last == null) { rows.Add(new Label(text["why.empty"]) { name = "why-empty" }); return; }if (last.Why.Count == 0) { rows.Add(new Label(text["why.nothing"]) { name = "why-nothing" }); return; }int i = 0;diff --git a/unity/Assets/Tests/EditMode/BudgetScreenTests.cs b/unity/Assets/Tests/EditMode/BudgetScreenTests.csindex 5f10dc5c2..f5eceeb1e 100644--- a/unity/Assets/Tests/EditMode/BudgetScreenTests.cs+++ b/unity/Assets/Tests/EditMode/BudgetScreenTests.cs@@ -36,7 +36,7 @@ public class BudgetScreenTestsAssert.AreEqual("Minister of Defense (David Ben-Gurion)", ui.Q<Label>("budget-defense_minister-name").text);Assert.AreEqual("effect x1.50", ui.Q<Label>("budget-defense_minister-factor").text); // capped at 1.5Assert.AreEqual("The Provisional State Council does not vote on the budget", ui.Q<Label>("budget-vote").text);- Assert.AreEqual("Treasury 20.0m · debt 0.0m · foreign currency $40.0m", ui.Q<Label>("budget-money").text);+ Assert.AreEqual("Treasury IL 20.0m · debt IL 0.0m · foreign currency $40.0m", ui.Q<Label>("budget-money").text);UiTestKit.Press(ui.Q<Button>("budget-education_minister-up"));Assert.AreEqual("11%", ui.Q<Label>("budget-education_minister-share").text);Assert.AreEqual("Changed: submit to put it to the vote", ui.Q<Label>("budget-status").text);@@ -69,7 +69,7 @@ public class BudgetScreenTestsforeach (var office in C.Rules.BudgetStart.Keys)Assert.AreEqual(System.FormattableString.Invariant($"effect x{EffectsSystem.BudgetFactor(budget.Draft, office):0.00}"), ui.Q<Label>($"budget-{office}-factor").text, office);var f = EconomySystem.Flows(C, bridge.State, 1.0);- Assert.AreEqual(System.FormattableString.Invariant($"Taxes {f.Tax:0.0}m, spending {f.Spending:0.0}m and reserve call-up {f.Mobilization:0.0}m a year"), ui.Q<Label>("budget-flow").text);+ Assert.AreEqual(System.FormattableString.Invariant($"Taxes IL {f.Tax:0.0}m, spending IL {f.Spending:0.0}m and reserve call-up IL {f.Mobilization:0.0}m a year"), ui.Q<Label>("budget-flow").text);UiTestKit.Press(ui.Q<Button>("budget-education_minister-up"));Assert.AreEqual(System.FormattableString.Invariant($"effect x{EffectsSystem.BudgetFactor(budget.Draft, "education_minister"):0.00}"), ui.Q<Label>("budget-education_minister-factor").text);}@@ -204,4 +204,21 @@ public class BudgetScreenTestsforeach (var kv in bridge.State.Budget) Assert.AreEqual(kv.Value, budget.Draft[kv.Key], 1e-12);}}++ /// <summary>Playtest 1, item 6: a vacant ministry reads "(vacant)", as on the Cabinet screen, never "(-)".</summary>+ [Test]+ public void AVacantMinistryReadsVacant()+ {+ var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);+ Seat vacant = null;+ for (int i = 0; i < 400 && g.State.GameOver == null && vacant == null; i++)+ {+ vacant = Cabinet.Lineup(C, g.State).FirstOrDefault(x => x.Holder == null && g.State.Budget.ContainsKey(x.Office.Id));+ if (vacant == null) g.Step(HistoricalAI.Commands(C, g.State));+ }+ Assert.IsNotNull(vacant, "the historical game has a vacant budgeted ministry to test with");+ using var ui = new UiTestKit();+ new BudgetPresenter(ui.Root, new SimBridge(g, Text), Text);+ Assert.AreEqual(vacant.Office.Title + " (vacant)", ui.Q<Label>("budget-" + vacant.Office.Id + "-name").text);+ }}diff --git a/unity/Assets/Tests/EditMode/DefenceScreenTests.cs b/unity/Assets/Tests/EditMode/DefenceScreenTests.csindex 1cddecf84..6639711b6 100644--- a/unity/Assets/Tests/EditMode/DefenceScreenTests.cs+++ b/unity/Assets/Tests/EditMode/DefenceScreenTests.cs@@ -32,7 +32,7 @@ public class DefenceScreenTestsAssert.AreEqual("A UN ceasefire will be imposed in 52 weeks", ui.Q<Label>("ceasefire").text);Assert.AreEqual("Minister of Defense David Ben-Gurion · Chief of Staff Yaakov Dori", ui.Q<Label>("defence-command").text);Assert.AreEqual("80% of reserves called up (level 5 needs at least 80%)", ui.Q<Label>("mob-level").text);- Assert.AreEqual("Costs 48.0m a year in pay and lost work", ui.Q<Label>("mob-cost").text);+ Assert.AreEqual("Costs IL 48.0m a year in pay and lost work", ui.Q<Label>("mob-cost").text);Assert.IsFalse(ui.Q<Button>("escalate").enabledSelf);}}@@ -84,7 +84,7 @@ public class DefenceScreenTestsAssert.AreEqual(0.4, bridge.State.Mobilization, 1e-9);ui.Press("escalate"); // back to full war needs 80% againStringAssert.StartsWith("80% of reserves called up (level 5 needs at least 80%)", ui.Q<Label>("mob-level").text);- Assert.AreEqual("Costs 48.0m a year in pay and lost work", ui.Q<Label>("mob-cost").text);+ Assert.AreEqual("Costs IL 48.0m a year in pay and lost work", ui.Q<Label>("mob-cost").text);bridge.EndTurn();Assert.AreEqual(0.8, bridge.State.Mobilization, 1e-9);Assert.AreEqual(5, bridge.State.Rung);diff --git a/unity/Assets/Tests/EditMode/HudTests.cs b/unity/Assets/Tests/EditMode/HudTests.csindex a418f1436..c29baa5b1 100644--- a/unity/Assets/Tests/EditMode/HudTests.cs+++ b/unity/Assets/Tests/EditMode/HudTests.cs@@ -23,7 +23,7 @@ public class HudTestsAssert.AreEqual("1948", m.Year);Assert.AreEqual("Turn 0", m.Turn);Assert.AreEqual("15 May 1948", m.Date);- Assert.AreEqual("20.0m", m.Treasury.Value);+ Assert.AreEqual("IL 20.0m", m.Treasury.Value); // Israeli pounds (playtest 1, item 7)Assert.AreEqual("$40.0m", m.Fx.Value);Assert.AreEqual("Level 5 of 5", m.SecurityLevel);Assert.AreEqual("Attention 4.0 of 4.0", m.Attention);@@ -268,4 +268,45 @@ public class HudTestsAssert.AreSame(order, seen![0].Command);Assert.AreEqual("Not done: The turn could not run: boom", ui.Q<Label>("toast").text);}++ /// <summary>Playtest 1, item 11: pressing the open screen's button closes it, every time, with every presenter+ /// GameRoot creates listening, with the button focused (as after a mouse click), and across End Turn.</summary>+ [Test]+ public void PressingTheOpenScreensButtonClosesItAcrossTurns()+ {+ using var ui = new UiTestKit();+ var bridge = NewBridge();+ var portraits = ScriptableObject.CreateInstance<PortraitCatalog>();+ try+ {+ new HudPresenter(ui.Root, bridge, Text);+ var nav = new ScreenNav(ui.Root);+ new EventCardPresenter(ui.Root, bridge, Text, portraits);+ new DefencePresenter(ui.Root, bridge, Text);+ new BudgetPresenter(ui.Root, bridge, Text);+ new WhyPresenter(ui.Root, bridge, Text);+ new CabinetPresenter(ui.Root, bridge, Text, portraits);+ DisplayStyle Shown(string screen) => ui.Q<VisualElement>("screen-" + screen).style.display.value;+ for (int turn = 0; turn < 4; turn++)+ {+ foreach (var screen in ScreenNav.Screens)+ {+ ui.Press("nav-" + screen);+ Assert.AreEqual(DisplayStyle.Flex, Shown(screen), $"turn {turn}: {screen} did not open");+ ui.Q<Button>("nav-" + screen).Focus();+ ui.Press("nav-" + screen);+ Assert.AreEqual(DisplayStyle.None, Shown(screen), $"turn {turn}: {screen} did not close");+ Assert.IsNull(nav.Current);+ }+ var open = ScreenNav.Screens[turn % ScreenNav.Screens.Length];+ ui.Press("nav-" + open);+ ui.Press("end-turn");+ Assert.AreEqual(turn + 1, bridge.State.Turn, $"turn {turn}: End Turn did not run");+ Assert.AreEqual(DisplayStyle.Flex, Shown(open), $"turn {turn}: End Turn closed {open}");+ ui.Press("nav-" + open);+ Assert.AreEqual(DisplayStyle.None, Shown(open), $"turn {turn}: {open} did not close after End Turn");+ }+ }+ finally { Object.DestroyImmediate(portraits); }+ }}diff --git a/unity/Assets/Tests/EditMode/MapActionUiTests.cs b/unity/Assets/Tests/EditMode/MapActionUiTests.csindex 9a986fcfe..0a344bbb4 100644--- a/unity/Assets/Tests/EditMode/MapActionUiTests.cs+++ b/unity/Assets/Tests/EditMode/MapActionUiTests.cs@@ -63,7 +63,7 @@ public class MapActionUiTestsAssert.AreEqual("Tel Aviv", ui.Q<Label>("info-title").text);StringAssert.StartsWith("Coastal plain · hex (", ui.Q<Label>("info-subtitle").text);Assert.IsFalse(ui.Q<Button>("build-camp").enabledSelf);- Assert.AreEqual("Transit camps and housing projects can be placed from 1950-01-01", ui.Q<Label>("info-reason").text);+ Assert.AreEqual("Transit camps and housing projects can be placed from 1 January 1950", ui.Q<Label>("info-reason").text);}[Test]@@ -75,7 +75,7 @@ public class MapActionUiTestsvar tlv = C.SettlementHexes.Single(s => s.Id == "tel_aviv");info.Show(tlv.Q, tlv.R);Assert.IsTrue(ui.Q<Button>("build-camp").enabledSelf, ui.Q<Label>("info-reason").text);- Assert.AreEqual("Place a transit camp (1.5m)", ui.Q<Button>("build-camp").text);+ Assert.AreEqual("Place a transit camp (IL 1.5m)", ui.Q<Button>("build-camp").text);ui.Press("build-camp");Assert.AreEqual("Ordered: A transit camp, at End Turn", ui.Q<Label>("info-placement").text);bridge.EndTurn();diff --git a/unity/Assets/Tests/EditMode/WhyScreenTests.cs b/unity/Assets/Tests/EditMode/WhyScreenTests.csindex 70782b9bf..c1cb25c95 100644--- a/unity/Assets/Tests/EditMode/WhyScreenTests.cs+++ b/unity/Assets/Tests/EditMode/WhyScreenTests.cs@@ -165,4 +165,18 @@ public class WhyScreenTestsAssert.AreEqual(loaded.Last!.Why.Count, ui.Q<ScrollView>("why-rows").Query<Label>(className: "why-line").ToList().Count);}}++ /// <summary>Playtest 1, item 4: the effects group covers effects that are not policies too.</summary>+ [Test]+ public void TheEffectsGroupIsCalledOngoingEffects() => Assert.AreEqual("Ongoing effects", Text["why.effects"]);++ /// <summary>Playtest 1, item 5: every date the player sees goes through Statecraft.Sim.PlayerText ("15 May 1948"),+ /// so no UI string carries a date format of its own.</summary>+ [Test]+ public void NoUiStringFormatsADateItself()+ {+ var yaml = AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings).text;+ foreach (var line in yaml.Split('\n'))+ Assert.IsFalse(System.Text.RegularExpressions.Regex.IsMatch(line, "yyyy|MMM|MM-dd|:d "), "date format in strings.en.yaml: " + line);+ }}diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yamlindex 8280ce2a8..09edb4026 100644--- a/unity/Assets/UI/strings.en.yaml+++ b/unity/Assets/UI/strings.en.yaml@@ -1,9 +1,11 @@# UI strings (English). Code looks strings up by key (Statecraft.Game.UI.UiText); placeholders are string.Format# arguments ({0}, {1}) formatted with the invariant culture. Static labels live in the UXML files.+# Dates arrive already formatted by Statecraft.Sim.PlayerText ("15 May 1948"); no string here formats a date itself.+# Money in Israeli pounds reads "IL 18.6m"; foreign currency (dollars) reads "$41.5m".hud.turn: "Turn {0}"-hud.date: "{0:d MMMM yyyy}"+hud.date: "{0}"hud.attention: "Attention {0:0.0} of {1:0.0}"-hud.money: "{0:0.0}m"+hud.money: "IL {0:0.0}m"hud.people: "{0:N0}"hud.percent: "{0:0}"hud.fx: "${0:0.0}m"@@ -31,19 +33,20 @@ defence.command: "Minister of Defense {0} · Chief of Staff {1}"defence.ceasefire: "A UN ceasefire will be imposed in {0} weeks"defence.order: "Ordered: level {0} to {1}"defence.mob: "{0:0}% of reserves called up (level {1} needs at least {2:0}%)"-defence.mob_cost: "Costs {0:0.0}m a year in pay and lost work"+defence.mob_cost: "Costs IL {0:0.0}m a year in pay and lost work"defence.ceasefire_stops: "The UN ceasefire clock stops if the level is lowered"defence.ceasefire_starts: "UN ceasefire: {0} weeks once level 5 is reached"budget.share: "{0:0}%"budget.office: "{0} ({1})"+budget.vacant: "vacant"budget.factor: "effect x{0:0.00}"budget.vote_needed: "The {0} must approve it: the coalition holds {1} of {2} seats"budget.no_vote: "The {0} does not vote on the budget"-budget.money: "Treasury {0:0.0}m · debt {1:0.0}m · foreign currency ${2:0.0}m"-budget.flow: "Taxes {0:0.0}m, spending {1:0.0}m and reserve call-up {2:0.0}m a year"+budget.money: "Treasury IL {0:0.0}m · debt IL {1:0.0}m · foreign currency ${2:0.0}m"+budget.flow: "Taxes IL {0:0.0}m, spending IL {1:0.0}m and reserve call-up IL {2:0.0}m a year"budget.queued: "Submitted: takes effect at End Turn"budget.unsaved: "Changed: submit to put it to the vote"-why.turn: "{0:d MMMM yyyy} to {1:d MMMM yyyy}"+why.turn: "{0} to {1}"why.empty: "Nothing has happened yet: end the turn to see its causes."why.events: "Events"why.politics: "Politics"@@ -53,7 +56,7 @@ why.economy: "Economy"why.population: "Immigration and population"why.map: "Building"why.policy: "Policies"-why.effects: "Effects of policies"+why.effects: "Ongoing effects"why.situations: "Situations"why.other: "Other"why.nothing: "Nothing notable happened this turn."@@ -69,12 +72,12 @@ info.hint: "Click the map to inspect a hex"info.off_map: "Off the map"info.hex: "{0} · hex ({1}, {2}) · {3:N0} m"info.owned: "Settlements: {0}"-info.built: "{0} built here in {1:MMMM yyyy}"+info.built: "{0} built here in {1}"info.queued: "Ordered: {0}, at End Turn"info.transit_camp: "A transit camp"info.housing: "A housing project"-info.build_camp: "Place a transit camp ({0:0.0}m)"-info.build_housing: "Build housing ({0:0.0}m)"+info.build_camp: "Place a transit camp (IL {0:0.0}m)"+info.build_housing: "Build housing (IL {0:0.0}m)"info.build_camp_plain: "Place a transit camp"info.build_housing_plain: "Build housing"info.biome.sea: "Sea"