A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
UI: the Hebrew date plate shows the date in Hebrew (refs #687) (#696)
Eyal Golan9d1b1ef2cb4e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 0fa17e433..6c1906ad0 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -695,6 +695,8 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIBIt decodes to the same bytes, so the terrain is unchanged (#44).### Fixed+- In the Hebrew UI the top bar's date plate shows the date in Hebrew, "15 במאי 1948", through the same `date.*` strings+ as the map's front-line date (refs #687). Before, it read "15 May 1948". English is unchanged.- Map labels (refs #599): close over Jaffa's harbour the "Tel Aviv" and "Jaffa" pills no longer read swapped. Every pillis now nearer its own settlement's marker than any other visible marker (by more than 4 px), in every placing pass,since two sprawling kits' screen rectangles overlap and a spot against one's edge could sit by the other town. A citydiff --git a/unity/Assets/Scripts/Map/Control1948.cs b/unity/Assets/Scripts/Map/Control1948.csindex 4780bbba4..4a7b9b623 100644--- a/unity/Assets/Scripts/Map/Control1948.cs+++ b/unity/Assets/Scripts/Map/Control1948.cs@@ -189,10 +189,15 @@ namespace Statecraft.Game.Map{string F(string key, params object[] a) => string.Format(CultureInfo.InvariantCulture, text(key), a);if (DateTime.TryParseExact(lineDate, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out var d))- return F("date.day_month_year", d.Day, text("date.month_" + d.Month), d.Year);+ return DateText(d, text);if (DateTime.TryParseExact(lineDate, "yyyy-MM", CultureInfo.InvariantCulture, DateTimeStyles.None, out var m))return F("date.month_year", text("date.month_" + m.Month), m.Year);return lineDate;}++ /// <summary>A day as players read it, in the UI's language through <paramref name="text"/> (date.day_month_year,+ /// date.month_1..12): "15 May 1948" / "15 במאי 1948". The map's line date and the top bar's date plate (#687).</summary>+ public static string DateText(DateTime d, Func<string, string> text) =>+ string.Format(CultureInfo.InvariantCulture, text("date.day_month_year"), d.Day, text("date.month_" + d.Month), d.Year);}}diff --git a/unity/Assets/Scripts/UI/HudModel.cs b/unity/Assets/Scripts/UI/HudModel.csindex 9adffcb13..cec31f0a4 100644--- a/unity/Assets/Scripts/UI/HudModel.cs+++ b/unity/Assets/Scripts/UI/HudModel.cs@@ -75,7 +75,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", PlayerText.Date(s.Date)),+ Date = t.Format("hud.date", Statecraft.Game.Map.Control1948.DateText(s.Date, k => t[k])), // the UI's language (#687)Attention = t.Format("hud.attention", b.AttentionLeft, c.RulesAt(s.Date).AttentionPerTurn),SecurityLevel = t.Format("hud.level", s.Rung),Score = c.IsGdd ? t.Format("hud.score", s.Score) : "", // the GDD loop only (#380); PR 6 moves itdiff --git a/unity/Assets/Tests/EditMode/HebrewUiTests.cs b/unity/Assets/Tests/EditMode/HebrewUiTests.csindex dc37df90c..e4f0bb2b4 100644--- a/unity/Assets/Tests/EditMode/HebrewUiTests.cs+++ b/unity/Assets/Tests/EditMode/HebrewUiTests.cs@@ -122,13 +122,13 @@ public class HebrewUiTests}/// <summary>In Hebrew each text takes its paragraph direction from its own words: the Hebrew strings right to left, the- /// English date and the numbers left to right (so "15 May 1948" is not reordered), and a text that changes follows.</summary>+ /// numbers left to right (so "1948" is not reordered), the date in Hebrew right to left (#687), and a text that changes follows.</summary>[Test]public void InHebrewEachTextTakesItsDirectionFromItsOwnWords(){var game = Boot(UiLanguage.Hebrew);Assert.AreEqual(LanguageDirection.RTL, Ui.Q<Label>("turn").languageDirection, "turn: Hebrew");- Assert.AreEqual(LanguageDirection.LTR, Ui.Q<Label>("date").languageDirection, "the date is still English (#55)");+ Assert.AreEqual(LanguageDirection.RTL, Ui.Q<Label>("date").languageDirection, "the date is in Hebrew (#687)");Assert.AreEqual(LanguageDirection.LTR, Ui.Q<Label>("year").languageDirection, "digits alone");foreach (var t in Ui.Query<TextElement>().ToList().Where(t => !t.ClassListContains("start-he")))Assert.AreEqual(UiDirection.RightToLeft(t.text) ? LanguageDirection.RTL : LanguageDirection.LTR, t.languageDirection, $"'{t.name}': {t.text}");@@ -141,7 +141,7 @@ public class HebrewUiTests// After a turn the texts the turn rewrote keep the direction of their new words.game.Bridge!.EndTurn();Assert.AreEqual(LanguageDirection.RTL, turn.languageDirection, turn.text);- Assert.AreEqual(LanguageDirection.LTR, Ui.Q<Label>("date").languageDirection, Ui.Q<Label>("date").text);+ Assert.AreEqual(LanguageDirection.RTL, Ui.Q<Label>("date").languageDirection, Ui.Q<Label>("date").text);}/// <summary>Many texts a presenter builds after boot get their words before they are on the panel (new Label(text)), sodiff --git a/unity/Assets/Tests/EditMode/HudTests.cs b/unity/Assets/Tests/EditMode/HudTests.csindex 3f057f612..a1c5e5567 100644--- a/unity/Assets/Tests/EditMode/HudTests.cs+++ b/unity/Assets/Tests/EditMode/HudTests.cs@@ -33,6 +33,48 @@ public class HudTestsAssert.AreEqual("", m.Treasury.Delta); // no previous turn yet}+ /// <summary>#687: the plate's date is in the UI's language, through the date.* strings as the map's front-line date+ /// (Control1948.LineDateText): "15 במאי 1948" in Hebrew, every month with its Hebrew name and no Latin letter.</summary>+ [Test]+ public void TheDatePlateIsInHebrewInTheHebrewUi()+ {+ var bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), He);+ Assert.AreEqual("15 במאי 1948", HudModel.From(bridge, He).Date);+ var months = new[] { "ינואר", "פברואר", "מרץ", "אפריל", "מאי", "יוני", "יולי", "אוגוסט", "ספטמבר", "אוקטובר", "נובמבר", "דצמבר" };+ for (int m = 1; m <= 12; m++)+ {+ bridge.State.Date = new System.DateTime(1950, m, 1);+ var date = HudModel.From(bridge, He).Date;+ Assert.AreEqual($"1 ב{months[m - 1]} 1950", date);+ Assert.IsFalse(System.Text.RegularExpressions.Regex.IsMatch(date, "[A-Za-z]"), date);+ }+ }++ /// <summary>#687: English is unchanged, PlayerText.Date's "15 May 1948" on every day of a leap year (every month, every+ /// day number).</summary>+ [Test]+ public void TheDatePlateInEnglishIsUnchanged()+ {+ var bridge = NewBridge();+ for (var d = new System.DateTime(1948, 1, 1); d.Year == 1948; d = d.AddDays(1))+ {+ bridge.State.Date = d;+ Assert.AreEqual(PlayerText.Date(d), HudModel.From(bridge, Text).Date);+ }+ }++ /// <summary>#687, fail-open check: a Hebrew strings file without a month's name does not fall back to English or show+ /// nothing; the lookup throws naming the file and the key.</summary>+ [Test]+ public void AMissingMonthNameThrowsRatherThanShowingEnglish()+ {+ var yaml = AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.StringsHebrew).text;+ var noMay = UiText.Parse(string.Join("\n", yaml.Split('\n').Where(l => !l.StartsWith("date.month_5:"))), "strings.he.yaml");+ var e = Assert.Throws<System.Collections.Generic.KeyNotFoundException>(() =>+ HudModel.From(new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), He), noMay));+ StringAssert.Contains("date.month_5", e!.Message);+ }+/// <summary>T71: the top bar's Treasury is the net position, cash minus debt (HudModel.From; M3 plan: "with deficits/// borrowed, cash alone is always 0"). The sim keeps cash at 0 or above (R-MONEY-003), so a negative reading is debt,/// not a negative Treasury: after four monthly turns with no orders, 0 cash and the debt read as minus the debt.</summary>diff --git a/unity/Assets/Tests/EditMode/TopBarScoreLayoutTests.cs b/unity/Assets/Tests/EditMode/TopBarScoreLayoutTests.csindex a562014cf..d4f7fd656 100644--- a/unity/Assets/Tests/EditMode/TopBarScoreLayoutTests.cs+++ b/unity/Assets/Tests/EditMode/TopBarScoreLayoutTests.cs@@ -21,8 +21,10 @@ public class TopBarScoreLayoutTests/// <summary>Five digits with the thousands separator: well past what a Phase 1 or MVP run can score.</summary>const int WorstScore = 99999;- /// <summary>The widest date line the box was sized for ("Turn 120 30 September 1956", Statecraft.uss .date-box).</summary>- static readonly System.DateTime WorstDate = new System.DateTime(1956, 9, 30);+ /// <summary>The widest date line the box was sized for ("Turn 120 30 September 1956", Statecraft.uss .date-box). In Hebrew+ /// (#687) the widest month is October, "31 באוקטובר 1956", 109.8 px at the plate's 15 px in Frank Ruhl Libre Medium+ /// against 109.0 for "30 בספטמבר 1956" (Pillow's advance widths over the twelve months).</summary>+ public static System.DateTime WorstDate(bool hebrew) => hebrew ? new System.DateTime(1956, 10, 31) : new System.DateTime(1956, 9, 30);const int WorstTurn = 120;static Rect ContentBox(VisualElement e)@@ -69,7 +71,7 @@ public class TopBarScoreLayoutTestsroot.Q("root").EnableInClassList(UiLanguage.HebrewClass, hebrew);var bridge = new SimBridge(GameSession.New(Gdd, GoldenRun.Seed, Mode.Historical), text);bridge.State.Score = WorstScore;- bridge.State.Date = WorstDate;+ bridge.State.Date = WorstDate(hebrew);bridge.State.Turn = WorstTurn;var hud = new HudPresenter(root, bridge, text);try@@ -79,7 +81,7 @@ public class TopBarScoreLayoutTestsfor (int i = 0; i < 3; i++) yield return null; // the bar's tier classes settle after the first layoutvar at = $"{language} {w}x{h}";Assert.AreEqual(text.Format("hud.score", WorstScore), score.text, $"{at}: precondition: the worst score shows");- Assert.AreEqual(text.Format("hud.date", PlayerText.Date(WorstDate)), root.Q<Label>("date").text, $"{at}: precondition: the widest date shows");+ Assert.AreEqual(text.Format("hud.date", Statecraft.Game.Map.Control1948.DateText(WorstDate(hebrew), k => text[k])), root.Q<Label>("date").text, $"{at}: precondition: the widest date shows");var box = root.Q(className: "date-box");if (!Inside(score.worldBound, ContentBox(box))) problems.Add($"{at}: '{score.text}' {score.worldBound} leaves the date box's frame {ContentBox(box)}");if (!Whole(score)) problems.Add($"{at}: '{score.text}' is clipped in {score.contentRect}");diff --git a/unity/Assets/Tests/EditMode/TopBarTests.cs b/unity/Assets/Tests/EditMode/TopBarTests.csindex b4b7a82d9..a9a6d4e95 100644--- a/unity/Assets/Tests/EditMode/TopBarTests.cs+++ b/unity/Assets/Tests/EditMode/TopBarTests.cs@@ -97,7 +97,7 @@ public class TopBarTestsroot.Q<Label>(name + "-value").text = value;root.Q<Label>("security-level").text = text.Format("hud.level", 5);root.Q<Label>("turn").text = text.Format("hud.turn", 120);- root.Q<Label>("date").text = text.Format("hud.date", PlayerText.Date(new System.DateTime(1956, 9, 30)));+ root.Q<Label>("date").text = text.Format("hud.date", Statecraft.Game.Map.Control1948.DateText(TopBarScoreLayoutTests.WorstDate(hebrew), k => text[k]));root.Q<Label>("attention").text = text.Format("hud.attention", 4.0, 4.0);}dir?.Apply();