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): money and 0-100 values carry their unit through PlayerText; captions match content
eyalgolanca0acecdc537
diff --git a/unity/Assets/Scripts/UI/BudgetPresenter.cs b/unity/Assets/Scripts/UI/BudgetPresenter.csindex 066a2e7da..ffc2fb2b4 100644--- a/unity/Assets/Scripts/UI/BudgetPresenter.cs+++ b/unity/Assets/Scripts/UI/BudgetPresenter.cs@@ -114,7 +114,7 @@ namespace Statecraft.Game.UIrow.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" });+ row.Add(new Label(text.Format("budget.share", PlayerText.Percent(share))) { name = "budget-" + office + "-share" });row.Add(new Button(() => Change(office, +Step)) { name = "budget-" + office + "-up", text = "+" });var factor = EffectsSystem.BudgetFactor(draft, office);row.Add(new Label(text.Format("budget.factor", factor)) { name = "budget-" + office + "-factor" });@@ -125,9 +125,9 @@ namespace Statecraft.Game.UIvar (seats, size) = PoliticsSystem.CoalitionSeats(c, s.Date);screen.Q<Label>("budget-vote").text = leg == null ? "" : leg.BudgetApproval? text.Format("budget.vote_needed", leg.Body, seats, size) : text.Format("budget.no_vote", leg.Body);- screen.Q<Label>("budget-money").text = text.Format("budget.money", s.Treasury, s.Debt, s.FxReserves);+ screen.Q<Label>("budget-money").text = text.Format("budget.money", PlayerText.Money(c, "treasury", s.Treasury), PlayerText.Money(c, "debt", s.Debt), PlayerText.Money(c, "fx_reserves", s.FxReserves));var flows = EconomySystem.Flows(c, s, 1.0); // the sim's own arithmetic, for a year- screen.Q<Label>("budget-flow").text = text.Format("budget.flow", flows.Tax, flows.Spending, flows.Mobilization);+ screen.Q<Label>("budget-flow").text = text.Format("budget.flow", PlayerText.Money(c, "treasury", flows.Tax), PlayerText.Money(c, "treasury", flows.Spending), PlayerText.Money(c, "treasury", flows.Mobilization));var queuedShares = QueuedShares;// The status says what is actually queued: edits after Submit are "Changed" again.screen.Q<Label>("budget-status").text = queuedShares != null ? (Same(draft, queuedShares) ? text["budget.queued"] : text["budget.unsaved"])diff --git a/unity/Assets/Scripts/UI/CabinetPresenter.cs b/unity/Assets/Scripts/UI/CabinetPresenter.csindex 20b015f45..9d2e36d75 100644--- a/unity/Assets/Scripts/UI/CabinetPresenter.cs+++ b/unity/Assets/Scripts/UI/CabinetPresenter.cs@@ -46,7 +46,7 @@ namespace Statecraft.Game.UIvar gov = Offices.Government(c, s.Date);var (seats, size) = PoliticsSystem.CoalitionSeats(c, s.Date);screen.Q<Label>("cabinet-government").text = gov?.Name ?? "";- screen.Q<Label>("cabinet-coalition").text = text.Format("cabinet.coalition", seats, size, s.CoalitionStability * 100);+ screen.Q<Label>("cabinet-coalition").text = text.Format("cabinet.coalition", seats, size, PlayerText.Percent(s.CoalitionStability));var list = screen.Q<ScrollView>("cabinet-seats");list.Clear();var lineup = Cabinet.Lineup(c, s);diff --git a/unity/Assets/Scripts/UI/DefencePresenter.cs b/unity/Assets/Scripts/UI/DefencePresenter.csindex ae9ceecbf..1c7b7df3f 100644--- a/unity/Assets/Scripts/UI/DefencePresenter.cs+++ b/unity/Assets/Scripts/UI/DefencePresenter.cs@@ -109,8 +109,8 @@ namespace Statecraft.Game.UIscreen.Q<Label>("order-pending").text = delta == 0 ? "" : text.Format("defence.order", s.Rung, target);var floor = SecuritySystem.MinMobilization(c, target);var proposed = EffectiveAt(ProposedMobilization); // what the call-up will be: the sim raises a lower order to the minimum- screen.Q<Label>("mob-level").text = text.Format("defence.mob", proposed * 100, target, floor * 100);- screen.Q<Label>("mob-cost").text = text.Format("defence.mob_cost", c.Rules.MobilizationCostPerYear * proposed);+ screen.Q<Label>("mob-level").text = text.Format("defence.mob", PlayerText.Percent(proposed), target, PlayerText.Percent(floor));+ screen.Q<Label>("mob-cost").text = text.Format("defence.mob_cost", PlayerText.Money(c, "treasury", c.Rules.MobilizationCostPerYear * proposed));screen.Q<Button>("escalate").SetEnabled(target < 5);screen.Q<Button>("de-escalate").SetEnabled(target > 1);}diff --git a/unity/Assets/Scripts/UI/HudModel.cs b/unity/Assets/Scripts/UI/HudModel.csindex c7ede0f8b..6d6a74471 100644--- a/unity/Assets/Scripts/UI/HudModel.cs+++ b/unity/Assets/Scripts/UI/HudModel.cs@@ -27,13 +27,30 @@ namespace Statecraft.Game.UIpublic static HudModel From(SimBridge b, UiText t){var c = b.Content; var s = b.State; var prev = b.Session.Previous;- Meter M(double now, double? before, string valueKey, string deltaKey)+ // Each meter: its value and, after the first turn, the change rounded as shown (a change that rounds to zero is+ // not shown). Money comes with its currency (PlayerText.Money: IL or $ from content); the 0..1 values are on the+ // 0-100 scale with "%" (PlayerText.Scale), as everywhere the player sees them (fix round 1, I2).+ Meter Money(string id, double now, double? before){- if (before == null) return new Meter(t.Format(valueKey, now), "", 0);- var d = Math.Round(now - before.Value, deltaKey == "hud.delta_money" ? 1 : 0, MidpointRounding.AwayFromZero);- return d == 0 ? new Meter(t.Format(valueKey, now), "", 0) : new Meter(t.Format(valueKey, now), t.Format(deltaKey, d), Math.Sign(d));+ var value = PlayerText.Money(c, id, now);+ if (before == null) return new Meter(value, "", 0);+ var d = Math.Round(now - before.Value, 1, MidpointRounding.AwayFromZero);+ return d == 0 ? new Meter(value, "", 0) : new Meter(value, PlayerText.MoneyChange(c, id, d), Math.Sign(d));+ }+ Meter Points(double now, double? before)+ {+ var v = Math.Round(PlayerText.Scale(now), MidpointRounding.AwayFromZero);+ var value = t.Format("hud.percent", v);+ if (before == null) return new Meter(value, "", 0);+ var d = v - Math.Round(PlayerText.Scale(before.Value), MidpointRounding.AwayFromZero);+ return d == 0 ? new Meter(value, "", 0) : new Meter(value, t.Format("hud.delta_percent", d), Math.Sign(d));+ }+ Meter People(double now, double? before)+ {+ if (before == null) return new Meter(t.Format("hud.people", now), "", 0);+ var d = Math.Round(now - before.Value, 0, MidpointRounding.AwayFromZero);+ return d == 0 ? new Meter(t.Format("hud.people", now), "", 0) : new Meter(t.Format("hud.people", now), t.Format("hud.delta_people", d), Math.Sign(d));}- double Pct(GameState x, string id) => Math.Round(x.Indicators[id] * 100, MidpointRounding.AwayFromZero);return new HudModel{Year = s.Date.Year.ToString(System.Globalization.CultureInfo.InvariantCulture),@@ -41,12 +58,12 @@ namespace Statecraft.Game.UIDate = 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"),- Immigration = M(Arrivals(b.Session.Last), b.BeforeLast == null ? (double?)null : Arrivals(b.BeforeLast), "hud.people", "hud.delta_people"),- Security = M(Pct(s, "security"), prev == null ? (double?)null : Pct(prev, "security"), "hud.percent", "hud.delta"),- Support = M(Math.Round(EffectsSystem.Approval(c, s) * 100, MidpointRounding.AwayFromZero), prev == null ? (double?)null : Math.Round(EffectsSystem.Approval(c, prev) * 100, MidpointRounding.AwayFromZero), "hud.percent", "hud.delta"),- Standing = M(Pct(s, "intl_standing"), prev == null ? (double?)null : Pct(prev, "intl_standing"), "hud.percent", "hud.delta"),- Fx = M(s.FxReserves, prev?.FxReserves, "hud.fx", "hud.delta_money"),+ Treasury = Money("treasury", s.Treasury - s.Debt, prev == null ? (double?)null : prev.Treasury - prev.Debt),+ Immigration = People(Arrivals(b.Session.Last), b.BeforeLast == null ? (double?)null : Arrivals(b.BeforeLast)),+ Security = Points(s.Indicators["security"], prev?.Indicators["security"]),+ Support = Points(EffectsSystem.Approval(c, s), prev == null ? (double?)null : EffectsSystem.Approval(c, prev)),+ Standing = Points(s.Indicators["intl_standing"], prev?.Indicators["intl_standing"]),+ Fx = Money("fx_reserves", s.FxReserves, prev?.FxReserves),};}}diff --git a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs b/unity/Assets/Scripts/UI/InfoPanelPresenter.csindex dadf8f6f4..15fe703ac 100644--- a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs+++ b/unity/Assets/Scripts/UI/InfoPanelPresenter.cs@@ -69,8 +69,8 @@ namespace Statecraft.Game.UIcamp.style.display = DisplayStyle.Flex; housing.style.display = DisplayStyle.Flex;camp.SetEnabled(campWhy == null); housing.SetEnabled(housingWhy == null);// with no rule for an action there is no cost to show (it is disabled with the sim's reason anyway)- camp.text = c.Rules.MapActions.TryGetValue(MapActions.TransitCamp, out var cr) ? text.Format("info.build_camp", cr.Cost) : text["info.build_camp_plain"];- housing.text = c.Rules.MapActions.TryGetValue(MapActions.Housing, out var hr) ? text.Format("info.build_housing", hr.Cost) : text["info.build_housing_plain"];+ camp.text = c.Rules.MapActions.TryGetValue(MapActions.TransitCamp, out var cr) ? text.Format("info.build_camp", PlayerText.Money(c, "treasury", cr.Cost)) : text["info.build_camp_plain"];+ housing.text = c.Rules.MapActions.TryGetValue(MapActions.Housing, out var hr) ? text.Format("info.build_housing", PlayerText.Money(c, "treasury", hr.Cost)) : text["info.build_housing_plain"];reason.text = string.Join("\n", new[] { campWhy, housingWhy }.Where(x => x != null).Distinct()); // the sim's reasons, each once}}diff --git a/unity/Assets/Tests/EditMode/CabinetScreenTests.cs b/unity/Assets/Tests/EditMode/CabinetScreenTests.csindex 12be68441..f158c23ec 100644--- a/unity/Assets/Tests/EditMode/CabinetScreenTests.cs+++ b/unity/Assets/Tests/EditMode/CabinetScreenTests.cs@@ -30,6 +30,7 @@ public class CabinetScreenTestsvar cabinet = new CabinetPresenter(ui.Root, bridge, Text, null);Assert.AreEqual("First Government", ui.Q<Label>("cabinet-government").text);StringAssert.StartsWith("Coalition: 73 of 120 seats", ui.Q<Label>("cabinet-coalition").text);+ StringAssert.IsMatch(@"stability \d+%$", ui.Q<Label>("cabinet-coalition").text); // fix round 1, I2: the unitAssert.AreEqual("Minister of Finance: Eliezer Kaplan · Mapai · competence 8, loyalty 9", ui.Q<Label>("seat-finance_minister-holder").text);UiTestKit.Press(ui.Q<Button>("seat-finance_minister"));Assert.AreEqual("finance_minister", cabinet.Selected);diff --git a/unity/Assets/Tests/EditMode/HudTests.cs b/unity/Assets/Tests/EditMode/HudTests.csindex c29baa5b1..01184155a 100644--- a/unity/Assets/Tests/EditMode/HudTests.cs+++ b/unity/Assets/Tests/EditMode/HudTests.cs@@ -25,6 +25,9 @@ public class HudTestsAssert.AreEqual("15 May 1948", m.Date);Assert.AreEqual("IL 20.0m", m.Treasury.Value); // Israeli pounds (playtest 1, item 7)Assert.AreEqual("$40.0m", m.Fx.Value);+ Assert.AreEqual("30%", m.Security.Value); // the 0-100 scale, with its unit (fix round 1, I2)+ Assert.AreEqual("50%", m.Standing.Value);+ StringAssert.EndsWith("%", m.Support.Value);Assert.AreEqual("Level 5 of 5", m.SecurityLevel);Assert.AreEqual("Attention 4.0 of 4.0", m.Attention);Assert.AreEqual("", m.Treasury.Delta); // no previous turn yet@@ -45,7 +48,7 @@ public class HudTestsvar s0 = bridge.Session.Previous!; var s1 = bridge.State;var d = System.Math.Round((s1.Treasury - s1.Debt) - (s0.Treasury - s0.Debt), 1, System.MidpointRounding.AwayFromZero);Assert.AreNotEqual(0.0, d, "the test needs a week with a treasury change");- Assert.AreEqual(d.ToString("+0.0;-0.0", System.Globalization.CultureInfo.InvariantCulture), ui.Q<Label>("treasury-delta").text);+ Assert.AreEqual(PlayerText.MoneyChange(C, "treasury", d), ui.Q<Label>("treasury-delta").text);Assert.AreEqual(d < 0, ui.Q<Label>("treasury-delta").ClassListContains("delta-down"));Assert.AreEqual(d > 0, ui.Q<Label>("treasury-delta").ClassListContains("delta-up"));}@@ -194,7 +197,7 @@ public class HudTestsvar now = bridge.State;prev.Treasury = now.Treasury - now.Debt + prev.Debt - 5; // up by 5hud.Render();- Assert.AreEqual("+5.0", ui.Q<Label>("treasury-delta").text);+ Assert.AreEqual("+IL 5.0m", ui.Q<Label>("treasury-delta").text);Assert.IsTrue(ui.Q<Label>("treasury-delta").ClassListContains("delta-up"));Assert.IsFalse(ui.Q<Label>("treasury-delta").ClassListContains("delta-down"));prev.Treasury = now.Treasury - now.Debt + prev.Debt + 0.04; // down by 0.04: rounds to zero, never "-0.0"@@ -309,4 +312,47 @@ public class HudTests}finally { Object.DestroyImmediate(portraits); }}++ /// <summary>Fix round 1, I2: the top-bar changes carry their unit: IL for the treasury, $ for foreign currency, % for+ /// the 0-100 meters.</summary>+ [Test]+ public void EveryTopBarChangeCarriesItsUnit()+ {+ var bridge = NewBridge();+ bridge.EndTurn();+ var prev = bridge.Session.Previous!;+ var now = bridge.State;+ prev.FxReserves = now.FxReserves + 2; // down by 2+ prev.Indicators["security"] = now.Indicators["security"] - 0.05; // up 5 points+ prev.Treasury = now.Treasury - now.Debt + prev.Debt + 3; // down by 3+ var m = HudModel.From(bridge, Text);+ Assert.AreEqual("-$2.0m", m.Fx.Delta);+ Assert.AreEqual("+5%", m.Security.Delta);+ Assert.AreEqual("-IL 3.0m", m.Treasury.Delta);+ }++ /// <summary>Fix round 1, I2: Unity never rescales a sim number itself; 0..1 values go through PlayerText.Scale or+ /// PlayerText.Percent (the minimap's layout percentages are not numbers the player reads).</summary>+ [Test]+ public void TheUiNeverMultipliesBy100Itself()+ {+ foreach (var f in System.IO.Directory.GetFiles("Assets/Scripts/UI", "*.cs"))+ foreach (var line in System.IO.File.ReadAllLines(f))+ if (System.Text.RegularExpressions.Regex.IsMatch(line, @"\*\s*100\b") && !line.Contains("Length.Percent"))+ Assert.Fail($"{System.IO.Path.GetFileName(f)}: {line.Trim()}");+ }++ /// <summary>Fix round 1, M3: the top-bar captions are the content names in title case (a deliberate casing for+ /// captions); Immigration and Public Support are UI quantities with no content name.</summary>+ [Test]+ public void TopBarCaptionsAreTheContentNamesInTitleCase()+ {+ using var ui = new UiTestKit();+ string Caption(string meter) => ui.Q<VisualElement>(meter).Q<Label>(className: "meter-name").text;+ string Title(string name) => System.Globalization.CultureInfo.InvariantCulture.TextInfo.ToTitleCase(name);+ Assert.AreEqual(Title(PlayerText.Target(C, "treasury")), Caption("meter-treasury"));+ Assert.AreEqual(Title(PlayerText.Target(C, "security")), Caption("meter-security"));+ Assert.AreEqual(Title(PlayerText.Target(C, "intl_standing")), Caption("meter-standing"));+ Assert.AreEqual(Title(PlayerText.Target(C, "fx_reserves")), Caption("meter-fx"));+ }}diff --git a/unity/Assets/UI/Game.uxml b/unity/Assets/UI/Game.uxmlindex 696c5d046..ae4b53d23 100644--- a/unity/Assets/UI/Game.uxml+++ b/unity/Assets/UI/Game.uxml@@ -9,6 +9,9 @@<ui:Label name="date" class="muted" /></ui:VisualElement></ui:VisualElement>+ <!-- Meter captions are the content display names in title case, a deliberate casing for captions (Treasury and+ Foreign Currency: model.yaml money; Security and International Standing: model.yaml indicators;+ HudTests.TopBarCaptionsAreTheContentNamesInTitleCase). Immigration and Public Support are UI quantities. --><ui:VisualElement name="meters" class="meters"><ui:VisualElement name="meter-treasury" class="meter"><ui:Label text="Treasury" class="meter-name" />diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yamlindex 09edb4026..5db3d5a12 100644--- a/unity/Assets/UI/strings.en.yaml+++ b/unity/Assets/UI/strings.en.yaml@@ -1,18 +1,16 @@# 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".+# Money arrives formatted by PlayerText.Money / MoneyChange, its currency from content (model.yaml money): "IL 18.6m",+# "$41.5m", "+IL 1.2m". Shares and 0..1 indicators arrive on the 0-100 scale (PlayerText.Scale / Percent) and show "%".hud.turn: "Turn {0}"hud.date: "{0}"hud.attention: "Attention {0:0.0} of {1:0.0}"-hud.money: "IL {0:0.0}m"hud.people: "{0:N0}"-hud.percent: "{0:0}"-hud.fx: "${0:0.0}m"+hud.percent: "{0:0}%"hud.level: "Level {0} of 5"-hud.delta: "{0:+0;-0}"+hud.delta_percent: "{0:+0;-0}%"hud.delta_people: "{0:+#,##0;-#,##0}"-hud.delta_money: "{0:+0.0;-0.0}"toast.refused: "Not done: {0}"event.office: "{0}: {1}"event.more: "{0} more decision(s) waiting"@@ -32,18 +30,18 @@ defence.turn_week: "turns of a week"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 IL {0:0.0}m a year in pay and lost work"+defence.mob: "{0} of reserves called up (level {1} needs at least {2})"+defence.mob_cost: "Costs {0} 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.share: "{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 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.money: "Treasury {0} · debt {1} · foreign currency {2}"+budget.flow: "Taxes {0}, spending {1} and reserve call-up {2} a year"budget.queued: "Submitted: takes effect at End Turn"budget.unsaved: "Changed: submit to put it to the vote"why.turn: "{0} to {1}"@@ -60,7 +58,7 @@ why.effects: "Ongoing effects"why.situations: "Situations"why.other: "Other"why.nothing: "Nothing notable happened this turn."-cabinet.coalition: "Coalition: {0} of {1} seats · stability {2:0}"+cabinet.coalition: "Coalition: {0} of {1} seats · stability {2}"cabinet.seat: "{0}: {1}"cabinet.vacant: "(vacant)"cabinet.person: "{0} · {1} · competence {2}, loyalty {3}"@@ -76,8 +74,8 @@ 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 (IL {0:0.0}m)"-info.build_housing: "Build housing (IL {0:0.0}m)"+info.build_camp: "Place a transit camp ({0})"+info.build_housing: "Build housing ({0})"info.build_camp_plain: "Place a transit camp"info.build_housing_plain: "Build housing"info.biome.sea: "Sea"