A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
ui: a Hebrew UI preview behind ?lang=he: strings, face, direction per text, mirrored layout (refs #193) (#506)
Eyal Golan5f08ade56d6d
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex eba301256..bf2a084f8 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -49,6 +49,11 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIBIt is kept for a later accessibility layer: no screen reader reads a runtime tooltip yet. A resumed game now showsthe same changes as before the reload on all six meters: `GameSession` keeps the step before the last(`BeforeLast`), so Immigration's change survives a load too. Not part of the state or the save: no golden moves.+- A Hebrew UI preview, asked for by hand: "?lang=he" in the page URL or "-lang he" on the desktop command line (#193).+ The UI loads `strings.he.yaml`, sets every text in Frank Ruhl Libre through the advanced text generator, gives each+ text the direction of its own words (dates, money and names are still English, #55), and mirrors the layout: rows,+ bars, the hemicycle, the option signs and End Turn's hourglass. English stays the default and has no visible switch.+ A long Budget office name now wraps in its column, so no row is wider than the screen.- Decision videos, phase 2 (#434 follow-up). On 11 decision cards an Illustration switch over the photograph plays ashort, silent AI-generated loop. It is labelled "AI-generated illustration" in place of the credit and carries a smallburned-in bilingual label. The photograph always shows first; nothing plays until the player asks, and the choice holdsdiff --git a/unity/Assets/Editor/MapCapture.cs b/unity/Assets/Editor/MapCapture.csindex 1117a11a3..2e07b7f56 100644--- a/unity/Assets/Editor/MapCapture.cs+++ b/unity/Assets/Editor/MapCapture.cs@@ -41,7 +41,7 @@ public static class MapCapturevar doc = ui.AddComponent<UIDocument>();doc.panelSettings = Asset<PanelSettings>(UiPaths.Panel);doc.visualTreeAsset = Asset<VisualTreeAsset>(UiPaths.GameUxml);- ui.AddComponent<GameRoot>().Configure(boot, doc, Asset<TextAsset>(UiPaths.Strings),+ ui.AddComponent<GameRoot>().Configure(boot, doc, Asset<TextAsset>(UiPaths.Strings), Asset<TextAsset>(UiPaths.StringsHebrew),Asset<PortraitCatalog>(PortraitImport.CatalogPath), map, placements, pointer, controller);EditorSceneManager.SaveScene(scene, ScenePath);}diff --git a/unity/Assets/Map.unity b/unity/Assets/Map.unityindex de3e40e38..0948bdb07 100644--- a/unity/Assets/Map.unity+++ b/unity/Assets/Map.unity@@ -435,6 +435,7 @@ MonoBehaviour:boot: {fileID: 309119767}document: {fileID: 1912926282}strings: {fileID: 4900000, guid: 1c2724b5422584e3dbeef4ab44d2e9da, type: 3}+ stringsHe: {fileID: 4900000, guid: 27f3faa05a8e4dbab9c8563cd9461548, type: 3}portraits: {fileID: 11400000, guid: 57539449dae8640c6b6848f8c1e433ff, type: 2}map: {fileID: 1195372452}placements: {fileID: 1128708372}diff --git a/unity/Assets/Scripts/UI/BudgetPresenter.cs b/unity/Assets/Scripts/UI/BudgetPresenter.csindex bb80b2912..996dde850 100644--- a/unity/Assets/Scripts/UI/BudgetPresenter.cs+++ b/unity/Assets/Scripts/UI/BudgetPresenter.cs@@ -107,6 +107,7 @@ namespace Statecraft.Game.UIrow.AddToClassList("row");var name = new Label { name = "budget-" + office + "-name" };name.AddToClassList("grow");+ name.AddToClassList("budget-office"); // wraps in its column, so a long office never widens the rowrow.Add(name);row.Add(new Button(() => Change(office, -Step)) { name = "budget-" + office + "-down", text = "-" });row.Add(new Label { name = "budget-" + office + "-share" });diff --git a/unity/Assets/Scripts/UI/CabinetPresenter.cs b/unity/Assets/Scripts/UI/CabinetPresenter.csindex 97855eb45..41b4dca28 100644--- a/unity/Assets/Scripts/UI/CabinetPresenter.cs+++ b/unity/Assets/Scripts/UI/CabinetPresenter.cs@@ -46,6 +46,7 @@ namespace Statecraft.Game.UIlist = screen.Q<ScrollView>("cabinet-seats"); candidates = screen.Q<ScrollView>("cabinet-candidates");pmOffices = screen.Q<VisualElement>("cabinet-pm-offices"); chips = screen.Q<VisualElement>("cabinet-parties");hemicycle = screen.Q<Hemicycle>("cabinet-hemicycle");+ hemicycle.Mirrored = text["ui.lang"] == UiLanguage.Hebrew; // the coalition from the right in a right-to-left UIonPm = () => Select(PrimeMinister);pmCard.clicked += onPm;onPmGeometry = _ => FramePm();diff --git a/unity/Assets/Scripts/UI/EventCardPresenter.cs b/unity/Assets/Scripts/UI/EventCardPresenter.csindex dbdc4960f..3a4fc25a3 100644--- a/unity/Assets/Scripts/UI/EventCardPresenter.cs+++ b/unity/Assets/Scripts/UI/EventCardPresenter.cs@@ -359,11 +359,17 @@ namespace Statecraft.Game.UIpublic string? PhotoAlt { get; private set; }/// <summary>The round sign in an option's left padding (Statecraft.uss .event-option), painted into the button so it- /// stays a leaf whose wrapped text Yoga measures (UiIcon.Paint).</summary>+ /// stays a leaf whose wrapped text Yoga measures (UiIcon.Paint). In the Hebrew UI it sits in the right padding and+ /// points left (#193).</summary>const float SignRadius = 15f, SignLeft = 9f;- static void PaintSign(MeshGenerationContext m) =>- UiIcon.PaintDisc(m, "chevron", new UnityEngine.Vector2(SignLeft + SignRadius, m.visualElement.layout.height / 2f), SignRadius);+ static void PaintSign(MeshGenerationContext m)+ {+ var e = m.visualElement;+ bool rtl = UiLanguage.Within(e);+ var x = rtl ? e.layout.width - SignLeft - SignRadius : SignLeft + SignRadius;+ UiIcon.PaintDisc(m, rtl ? "chevron-back" : "chevron", new UnityEngine.Vector2(x, e.layout.height / 2f), SignRadius);+ }void Choose(GameEvent e, EventOption o){diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.csindex f61d47132..87b3ffe78 100644--- a/unity/Assets/Scripts/UI/GameRoot.cs+++ b/unity/Assets/Scripts/UI/GameRoot.cs@@ -32,6 +32,7 @@ namespace Statecraft.Game.UI[SerializeField] GameBoot boot = null!;[SerializeField] UIDocument document = null!;[SerializeField] TextAsset strings = null!;+ [SerializeField] TextAsset stringsHe = null!;[SerializeField] PortraitCatalog portraits = null!;[SerializeField] MapScene map = null!;[SerializeField] PlacementLayer placements = null!;@@ -55,12 +56,14 @@ namespace Statecraft.Game.UIpublic SimBridge? Bridge { get; private set; }/// <summary>Where the autosave lives; null (the default) = SaveStore.ForPlatform(). Tests set a temporary folder.</summary>internal SaveStore? Store { get; set; }+ /// <summary>The UI's language; null (the default) = UiLanguage.Requested(). Tests set it.</summary>+ internal string? Language { get; set; }- public void Configure(GameBoot boot, UIDocument document, TextAsset strings, PortraitCatalog portraits, MapScene map,- PlacementLayer placements, MapPointer pointer, CameraController cameraController)+ public void Configure(GameBoot boot, UIDocument document, TextAsset strings, TextAsset stringsHe, PortraitCatalog portraits,+ MapScene map, PlacementLayer placements, MapPointer pointer, CameraController cameraController){var oldBoot = this.boot;- this.boot = boot; this.document = document; this.strings = strings; this.portraits = portraits; this.map = map;+ this.boot = boot; this.document = document; this.strings = strings; this.stringsHe = stringsHe; this.portraits = portraits; this.map = map;this.placements = placements; this.pointer = pointer; this.cameraController = cameraController;// An enabled GameRoot is already subscribed to the old boot's Ready (OnEnable): move the subscription.if (!isActiveAndEnabled) return;@@ -74,11 +77,15 @@ namespace Statecraft.Game.UI/// shows (M3 final review I5).</summary>internal void OnBootFailed(string reason){- if (document == null || strings == null) return;+ if (document == null || strings == null || stringsHe == null) return;var line = document.rootVisualElement.Q<Label>("loading");- if (line != null) line.text = UiText.Parse(strings.text).Format("boot.failed", GameBoot.ForPlayer(reason).TrimEnd('.'));+ if (line != null) line.text = Strings().Format("boot.failed", GameBoot.ForPlayer(reason).TrimEnd('.'));}+ /// <summary>The strings of the UI's language (UiLanguage): strings.he.yaml when Hebrew is asked for, else English.</summary>+ UiText Strings() => (Language ?? UiLanguage.Requested()) == UiLanguage.Hebrew+ ? UiText.Parse(stringsHe.text, "strings.he.yaml") : UiText.Parse(strings.text);+void OnDisable(){if (boot != null) { boot.Ready -= Begin; boot.Failed -= OnBootFailed; }@@ -121,13 +128,13 @@ namespace Statecraft.Game.UIinternal void Begin(GameInputs inputs, int smoke, bool startScreen = false){if (inputs == null) throw new ArgumentNullException(nameof(inputs));- foreach (var (value, field) in new (UnityEngine.Object?, string)[] { (document, nameof(document)), (strings, nameof(strings)),+ foreach (var (value, field) in new (UnityEngine.Object?, string)[] { (document, nameof(document)), (strings, nameof(strings)), (stringsHe, nameof(stringsHe)),(map, nameof(map)), (placements, nameof(placements)), (pointer, nameof(pointer)), (cameraController, nameof(cameraController)) })if (value == null) throw new InvalidOperationException($"GameRoot: {field} is not assigned (run MapCapture.MakeScene)");if (map.Terrain == null) throw new InvalidOperationException("GameRoot: the map is not built (GameBoot builds it before Ready)");Shutdown();- var text = UiText.Parse(strings.text);+ var text = Strings();var store = Store ?? SaveStore.ForPlatform();var notes = new List<string>();// A smoke run is reproducible: a fresh game with the golden seed, never the player's autosave.@@ -138,6 +145,10 @@ namespace Statecraft.Game.UIDiagLog.BootPhase($"session started (turn {session.State.Turn}, replayed)");var bridge = Bridge = new SimBridge(session, text);var root = document.rootVisualElement;+ bool hebrew = text["ui.lang"] == UiLanguage.Hebrew;+ // Hebrew: the Hebrew face, the advanced text generator and the mirrored rows (.lang-he); each text's paragraph+ // direction comes from its own text (UiDirection, made below once the presenters have rendered).+ (root.Q("root") ?? root).EnableInClassList(UiLanguage.HebrewClass, hebrew); // on .root, whose face it replaces// The toast first: the autosave (below) must report a failed write after the toast has shown the turn's refusals.var toast = Own(new ToastPresenter(root, bridge, text));@@ -223,7 +234,6 @@ namespace Statecraft.Game.UIvar camRig = rig = cameraController.GetComponent<CameraRig>();Own(new TopBarInset(root, camRig)); // the map is framed below the top barvar mini = minimap = Own(new MinimapPresenter(root, map.Hexes));- bool hebrew = text["ui.lang"] == "he"; // today's name in the UI's language (review M6)labels = Own(new MapLabelsPresenter(root, map, cameraController.GetComponent<Camera>(), null,p => MapLabelsPresenter.TipOf(p, n => text.Format("map.today", n), text["map.mixed"], hebrew),() => unitLayer != null ? unitLayer.KeepClear : null)); // the names keep clear of the unit tokens (issue #197)@@ -259,6 +269,7 @@ namespace Statecraft.Game.UIstart = Own(new StartScreenPresenter(root, newGame, resumed, shown => { if (cam != null) cam.enabled = !shown; }, recording));start.Show();}+ if (hebrew) Own(new UiDirection(root, bridge));root.Q("root")?.RemoveFromClassList("loading"); // ready: the bar, panels and screens may show (P2-1)DiagLog.BootPhase("screens ready");diff --git a/unity/Assets/Scripts/UI/Hemicycle.cs b/unity/Assets/Scripts/UI/Hemicycle.csindex b0b13810c..ea1633f35 100644--- a/unity/Assets/Scripts/UI/Hemicycle.cs+++ b/unity/Assets/Scripts/UI/Hemicycle.cs@@ -41,6 +41,7 @@ namespace Statecraft.Game.UIList<Vector2> boundary = new List<Vector2>();float[] cuts = Array.Empty<float>();float dot;+ bool mirrored;public Hemicycle(){@@ -49,6 +50,13 @@ namespace Statecraft.Game.UI}public IReadOnlyList<Group> Groups => groups;+ /// <summary>Drawn right to left (the Hebrew UI; #193): the first block starts at the right end and the majority line+ /// is counted from the right. The seats and the line are the same picture, mirrored.</summary>+ public bool Mirrored+ {+ get => mirrored;+ set { if (mirrored == value) return; mirrored = value; MarkDirtyRepaint(); }+ }/// <summary>The number of seats in the body.</summary>public int Size => size;/// <summary>Seats needed for a majority: more than half.</summary>@@ -195,6 +203,10 @@ namespace Statecraft.Game.UIreturn Mathf.Min(box.x / (2f + 2f * m), box.y / (1f + 2f * m));}+ /// <summary>A point of the unit half circle (y up) in panel pixels (y down), mirrored about the centre line when asked.</summary>+ public static Vector2 ToBox(Vector2 unit, Vector2 centre, float scale, bool mirrored) =>+ centre + new Vector2(mirrored ? -unit.x : unit.x, -unit.y) * scale;+void Draw(MeshGenerationContext mgc){var box = contentRect;@@ -203,7 +215,7 @@ namespace Statecraft.Game.UIvar margin = Margin(size);var scale = ScaleFor(box.size, size);var centre = new Vector2(box.center.x, box.yMax - margin * scale);- Vector2 At(Vector2 unit) => centre + new Vector2(unit.x, -unit.y) * scale;+ Vector2 At(Vector2 unit) => ToBox(unit, centre, scale, mirrored);var p = mgc.painter2D;for (int i = 0; i < size; i++){diff --git a/unity/Assets/Scripts/UI/HudPresenter.cs b/unity/Assets/Scripts/UI/HudPresenter.csindex 45959f38e..d8e854e8b 100644--- a/unity/Assets/Scripts/UI/HudPresenter.cs+++ b/unity/Assets/Scripts/UI/HudPresenter.cs@@ -132,7 +132,8 @@ namespace Statecraft.Game.UIstatic void PaintHourglass(MeshGenerationContext m){if (!m.visualElement.enabledInHierarchy) return; // no bright sign on a disabled End Turn (game over)- UiIcon.Paint(m, "hourglass", new UnityEngine.Rect(10f, (m.visualElement.layout.height - 22f) / 2f, 22f, 22f), UiIcon.IsFocused(m.visualElement));+ UiIcon.Paint(m, "hourglass", new UnityEngine.Rect(UiLanguage.Within(m.visualElement) ? m.visualElement.layout.width - 32f : 10f,+ (m.visualElement.layout.height - 22f) / 2f, 22f, 22f), UiIcon.IsFocused(m.visualElement)); // the right side in Hebrew (#193)}void Set(string name, string value) => root.Q<Label>(name).text = value;diff --git a/unity/Assets/Scripts/UI/UiDirection.cs b/unity/Assets/Scripts/UI/UiDirection.csnew file mode 100644index 000000000..6f93b479f--- /dev/null+++ b/unity/Assets/Scripts/UI/UiDirection.cs@@ -0,0 +1,70 @@+#nullable enable+using System;+using UnityEngine.UIElements;++namespace Statecraft.Game.UI+{+ /// <summary>The paragraph direction of every text in the Hebrew UI (#193). The UI strings are Hebrew, but dates, money,+ /// names and event text still arrive in English (#55), and UI Toolkit has no "auto" direction: an English line laid out+ /// as a right-to-left paragraph is reordered ("15 May 1948" reads "May 1948 15", "+5%" reads "5%+"). So each text+ /// element takes its direction from its own text, by its first strong character, as HTML's dir="auto" does: Hebrew is+ /// right to left, anything else (and a line of digits and signs alone) left to right. It follows a text when it changes,+ /// and looks at the whole tree again after a turn, a click or a key press, which is when presenters build new elements.+ /// The start screen's Hebrew lines set their own direction in Game.uxml and are left alone.</summary>+ public sealed class UiDirection : IDisposable+ {+ const string OwnDirectionClass = "start-he";+ readonly VisualElement root; readonly SimBridge bridge;+ readonly EventCallback<ChangeEvent<string>> onText;+ readonly EventCallback<ClickEvent> onClick;+ readonly EventCallback<NavigationSubmitEvent> onSubmit;+ readonly Action later;+ IVisualElementScheduledItem? pending;++ public UiDirection(VisualElement root, SimBridge bridge)+ {+ this.root = root; this.bridge = bridge;+ onText = e => { if (e.target is TextElement t) Apply(t, e.newValue); };+ later = () => { pending?.Pause(); pending = root.schedule.Execute(Apply); }; // next frame: after the presenters have rendered+ onClick = _ => later();+ onSubmit = _ => later();+ root.RegisterCallback(onText, TrickleDown.TrickleDown);+ root.RegisterCallback(onClick, TrickleDown.TrickleDown);+ root.RegisterCallback(onSubmit, TrickleDown.TrickleDown);+ bridge.Changed += later;+ Apply();+ }++ /// <summary>Whether a text is laid out right to left: its first letter is Hebrew or Arabic. A text with no letter+ /// (a number, a percentage) is not.</summary>+ public static bool RightToLeft(string? text)+ {+ if (text == null) return false;+ foreach (var c in text)+ {+ if (c >= '' && c <= 'ࣿ' || c >= 'יִ' && c <= '﷿' || c >= 'ﹰ' && c <= '') return true;+ if (char.IsLetter(c)) return false;+ }+ return false;+ }++ static void Apply(TextElement t, string? text)+ {+ if (t.ClassListContains(OwnDirectionClass)) return;+ t.languageDirection = RightToLeft(text) ? LanguageDirection.RTL : LanguageDirection.LTR;+ }++ /// <summary>Sets the direction of every text element under the root from its text.</summary>+ public void Apply() => root.Query<TextElement>().ForEach(t => Apply(t, t.text));++ public void Dispose()+ {+ pending?.Pause(); pending = null;+ bridge.Changed -= later;+ root.UnregisterCallback(onText, TrickleDown.TrickleDown);+ root.UnregisterCallback(onClick, TrickleDown.TrickleDown);+ root.UnregisterCallback(onSubmit, TrickleDown.TrickleDown);+ root.Query<TextElement>().ForEach(t => { if (!t.ClassListContains(OwnDirectionClass)) t.languageDirection = LanguageDirection.Inherit; });+ }+ }+}diff --git a/unity/Assets/Scripts/UI/UiDirection.cs.meta b/unity/Assets/Scripts/UI/UiDirection.cs.metanew file mode 100644index 000000000..40af90f65--- /dev/null+++ b/unity/Assets/Scripts/UI/UiDirection.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 5695e2322a655480dac43c1205ec7c13\ No newline at end of filediff --git a/unity/Assets/Scripts/UI/UiIcon.cs b/unity/Assets/Scripts/UI/UiIcon.csindex 70b525f72..7bac925d5 100644--- a/unity/Assets/Scripts/UI/UiIcon.cs+++ b/unity/Assets/Scripts/UI/UiIcon.cs@@ -42,7 +42,7 @@ namespace Statecraft.Game.UI{["coin"] = Coin, ["people"] = People, ["crowd"] = Crowd, ["shield"] = Shield, ["globe"] = Globe, ["banknote"] = Banknote,["columns"] = Columns, ["scales"] = Scales, ["helmet"] = Helmet, ["question"] = Question, ["restart"] = Restart,- ["chevron"] = Chevron, ["hourglass"] = Hourglass,+ ["chevron"] = Chevron, ["chevron-back"] = ChevronBack, ["hourglass"] = Hourglass,["region"] = Region, ["house"] = House, ["village"] = Village, ["flag"] = Flag,["biome-sea"] = Waves, ["biome-lake"] = Waves, ["biome-coastal_plain"] = Plain, ["biome-hills"] = Hills,["biome-mountains"] = Mountains, ["biome-valley"] = Valley, ["biome-lowland"] = Plain, ["biome-desert"] = Dunes,@@ -249,6 +249,13 @@ namespace Statecraft.Game.UIp.BeginPath(); p.MoveTo(at(9.6f, 6.4f)); p.LineTo(at(15.2f, 12)); p.LineTo(at(9.6f, 17.6f)); p.Stroke();}+ /// <summary>The chevron mirrored, pointing left: the option sign in the Hebrew UI.</summary>+ static void ChevronBack(Painter2D p, Func<float, float, Vector2> at, float s, Color gold)+ {+ p.strokeColor = gold; p.lineWidth = 2.2f * s;+ p.BeginPath(); p.MoveTo(at(14.4f, 6.4f)); p.LineTo(at(8.8f, 12)); p.LineTo(at(14.4f, 17.6f)); p.Stroke();+ }+static void Hourglass(Painter2D p, Func<float, float, Vector2> at, float s, Color gold){p.strokeColor = gold; p.lineWidth = 1.5f * s;diff --git a/unity/Assets/Scripts/UI/UiLanguage.cs b/unity/Assets/Scripts/UI/UiLanguage.csnew file mode 100644index 000000000..cda3c8441--- /dev/null+++ b/unity/Assets/Scripts/UI/UiLanguage.cs@@ -0,0 +1,40 @@+#nullable enable+using System;+using System.Text.RegularExpressions;+using UnityEngine;++namespace Statecraft.Game.UI+{+ /// <summary>The UI's language (#193): English unless Hebrew is asked for by hand, "?lang=he" in the page URL on WebGL or+ /// "-lang he" on the desktop command line. There is no control in the game yet: the content text (events, names) is+ /// English only until #55, so the Hebrew UI is a preview. Any other value, or a bare flag, is English.</summary>+ public static class UiLanguage+ {+ public const string Flag = "lang";+ public const string English = "en", Hebrew = "he";+ /// <summary>On the UI root while the UI is Hebrew: the Hebrew face, the advanced text generator and the mirrored rows+ /// (Statecraft.uss).</summary>+ public const string HebrewClass = "lang-he";++ // A whole query parameter with a whole value (UrlFlags' rule): "?lang=hex" and "?slang=he" are not the flag.+ static readonly Regex HebrewQuery = new Regex(@"[?&]" + Flag + "=" + Hebrew + @"(?=&|#|$)", RegexOptions.CultureInvariant);++ public static string Requested(string? url, string[] args, bool webgl)+ {+ if (webgl) return HebrewQuery.IsMatch(url ?? "") ? Hebrew : English;+ var i = Array.IndexOf(args, "-" + Flag);+ return i >= 0 && i + 1 < args.Length && args[i + 1] == Hebrew ? Hebrew : English;+ }++ /// <summary>Whether <paramref name="e"/> is inside the Hebrew UI (an ancestor carries <see cref="HebrewClass"/>): code+ /// that paints a sign at one side of an element puts it on the other side there.</summary>+ public static bool Within(UnityEngine.UIElements.VisualElement? e)+ {+ for (; e != null; e = e.parent) if (e.ClassListContains(HebrewClass)) return true;+ return false;+ }++ public static string Requested() =>+ Requested(Application.absoluteURL, Environment.GetCommandLineArgs(), Application.platform == RuntimePlatform.WebGLPlayer);+ }+}diff --git a/unity/Assets/Scripts/UI/UiLanguage.cs.meta b/unity/Assets/Scripts/UI/UiLanguage.cs.metanew file mode 100644index 000000000..c919a0b04--- /dev/null+++ b/unity/Assets/Scripts/UI/UiLanguage.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 9e51bce3c6ab3407dbc1d8c6730e9bb2\ No newline at end of filediff --git a/unity/Assets/Scripts/UI/UiPaths.cs b/unity/Assets/Scripts/UI/UiPaths.csindex 247896e59..386bc2720 100644--- a/unity/Assets/Scripts/UI/UiPaths.cs+++ b/unity/Assets/Scripts/UI/UiPaths.cs@@ -10,6 +10,8 @@ namespace Statecraft.Game.UIpublic const string Theme = Folder + "/StatecraftTheme.tss";public const string GameUxml = Folder + "/Game.uxml";public const string Strings = Folder + "/strings.en.yaml";+ /// <summary>The Hebrew strings, loaded when Hebrew is asked for (UiLanguage; #193).</summary>+ public const string StringsHebrew = Folder + "/strings.he.yaml";public const string FontRegular = Folder + "/Fonts/EBGaramond-Regular.ttf";public const string FontSemiBold = Folder + "/Fonts/EBGaramond-SemiBold.ttf";/// <summary>The Hebrew face (EB Garamond has no Hebrew; #193): Frank Ruhl Libre, OFL.</summary>diff --git a/unity/Assets/Tests/EditMode/GameSceneTests.cs b/unity/Assets/Tests/EditMode/GameSceneTests.csindex 102f362c8..fba89c307 100644--- a/unity/Assets/Tests/EditMode/GameSceneTests.cs+++ b/unity/Assets/Tests/EditMode/GameSceneTests.cs@@ -60,7 +60,7 @@ public class GameSceneTestsvar root = Object.FindFirstObjectByType<GameRoot>();Assert.IsNotNull(root, "GameRoot");var so = new SerializedObject(root);- foreach (var field in new[] { "boot", "document", "strings", "portraits", "map", "placements", "pointer", "cameraController" })+ foreach (var field in new[] { "boot", "document", "strings", "stringsHe", "portraits", "map", "placements", "pointer", "cameraController" })Assert.IsNotNull(so.FindProperty(field).objectReferenceValue, field);var boot = Object.FindFirstObjectByType<GameBoot>();Assert.IsNotNull(boot);@@ -405,8 +405,8 @@ public class GameSceneTestsAssert.AreEqual(1, Listeners(old), "subscribed while enabled");var so = new SerializedObject(root);Object R(string f) => so.FindProperty(f).objectReferenceValue;- root.Configure(other, (UIDocument)R("document"), (TextAsset)R("strings"), (PortraitCatalog)R("portraits"), (MapScene)R("map"),- (PlacementLayer)R("placements"), (MapPointer)R("pointer"), (CameraController)R("cameraController"));+ root.Configure(other, (UIDocument)R("document"), (TextAsset)R("strings"), (TextAsset)R("stringsHe"), (PortraitCatalog)R("portraits"),+ (MapScene)R("map"), (PlacementLayer)R("placements"), (MapPointer)R("pointer"), (CameraController)R("cameraController"));Assert.AreEqual(0, Listeners(old));Assert.AreEqual(1, Listeners(other));root.enabled = false;diff --git a/unity/Assets/Tests/EditMode/HebrewUiTests.cs b/unity/Assets/Tests/EditMode/HebrewUiTests.csnew file mode 100644index 000000000..da0153ee5--- /dev/null+++ b/unity/Assets/Tests/EditMode/HebrewUiTests.cs@@ -0,0 +1,347 @@+#nullable enable+using System;+using System.Collections;+using System.Collections.Generic;+using System.IO;+using System.Linq;+using System.Text.RegularExpressions;+using NUnit.Framework;+using Statecraft.Game;+using Statecraft.Game.Boot;+using Statecraft.Game.Map;+using Statecraft.Game.UI;+using UnityEditor;+using UnityEditor.SceneManagement;+using UnityEngine;+using UnityEngine.TestTools;+using UnityEngine.UIElements;+using Object = UnityEngine.Object;++/// <summary>The Hebrew UI (#193): asked for by hand only ("?lang=he", "-lang he"), English otherwise; when asked, GameRoot+/// loads strings.he.yaml and marks the root, and every text is set in the Hebrew face through the advanced text+/// generator.</summary>+public class HebrewUiTests+{+ static GameInputs? inputs;+ static GameInputs Inputs => inputs ??= GameInputs.FromDisk(Paths.Content, Paths.StreamingMap);+ static UiText He => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.StringsHebrew).text, "strings.he.yaml");+ static UiText En => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings).text);++ string saveDir = "";++ [SetUp] public void TempSaves() => saveDir = Path.Combine(Path.GetTempPath(), "statecraft-hebrew-" + Guid.NewGuid().ToString("N"));++ [TearDown]+ public void DiscardScene()+ {+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);+ if (Directory.Exists(saveDir)) Directory.Delete(saveDir, true);+ }++ // --- The flag ---------------------------------------------------------------------------------------------------++ [Test]+ public void HebrewIsOnlyAskedForByHand()+ {+ var none = new string[0];+ foreach (var q in new[] { "?lang=he", "?golden&lang=he", "?lang=he&smoke=5", "?lang=he#top" })+ Assert.AreEqual(UiLanguage.Hebrew, UiLanguage.Requested("http://localhost:8000/index.html" + q, none, webgl: true), q);+ foreach (var q in new[] { "", "?lang", "?lang=", "?lang=en", "?lang=hex", "?lang=HE", "?slang=he", "?lang=fr", "?golden" })+ Assert.AreEqual(UiLanguage.English, UiLanguage.Requested("http://localhost:8000/index.html" + q, none, webgl: true), q);+ Assert.AreEqual(UiLanguage.English, UiLanguage.Requested(null, none, webgl: true));+ Assert.AreEqual(UiLanguage.Hebrew, UiLanguage.Requested(null, new[] { "-batchmode", "-lang", "he" }, webgl: false));+ foreach (var args in new[] { none, new[] { "-lang" }, new[] { "-lang", "en" }, new[] { "-lang", "-smoke" }, new[] { "he" }, new[] { "-language", "he" } })+ Assert.AreEqual(UiLanguage.English, UiLanguage.Requested(null, args, webgl: false), string.Join(" ", args));+ // A flag on the desktop does not count on the web and the other way round (each instrument's own rule).+ Assert.AreEqual(UiLanguage.English, UiLanguage.Requested("http://localhost/index.html", new[] { "-lang", "he" }, webgl: true));+ Assert.AreEqual(UiLanguage.English, UiLanguage.Requested("http://localhost/index.html?lang=he", none, webgl: false));+ }++ // --- The game ---------------------------------------------------------------------------------------------------++ GameRoot Boot(string? language)+ {+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);+ Object.FindFirstObjectByType<MapScene>().Build(Inputs.Map);+ var root = Object.FindFirstObjectByType<GameRoot>();+ root.Store = new SaveStore(saveDir);+ root.Language = language;+ root.Begin(Inputs, 0);+ return root;+ }++ static VisualElement Ui => Object.FindFirstObjectByType<UIDocument>().rootVisualElement;++ [Test]+ public void TheGameIsEnglishUnlessHebrewIsAskedFor()+ {+ var game = Boot(null); // the test run's command line has no "-lang he"+ Assert.IsFalse(Ui.Q("root").ClassListContains(UiLanguage.HebrewClass));+ Assert.AreEqual(En.Format("hud.turn", game.Bridge!.State.Turn), Ui.Q<Label>("turn").text);+ Assert.IsTrue(Ui.Query<TextElement>().ToList().All(t => t.ClassListContains("start-he") || t.languageDirection == LanguageDirection.Inherit),+ "English sets no paragraph direction");+ }++ [Test]+ public void AskedForHebrewTheGameLoadsTheHebrewStringsAndMarksTheRoot()+ {+ var game = Boot(UiLanguage.Hebrew);+ Assert.IsTrue(Ui.Q("root").ClassListContains(UiLanguage.HebrewClass));+ Assert.AreEqual(He.Format("hud.turn", game.Bridge!.State.Turn), Ui.Q<Label>("turn").text);+ StringAssert.Contains("תור", Ui.Q<Label>("turn").text);+ // New Game in Hebrew disposes the old UiDirection and makes a new one; the start screen's Hebrew lines stay right to+ // left through it (neither takes theirs off nor sets it).+ game.Begin(Inputs, 0);+ TheDeclarationStaysRightToLeft("a Hebrew restart");+ // Starting again in English takes the mark and every other direction off (New Game restarts through Begin).+ game.Language = UiLanguage.English;+ game.Begin(Inputs, 0);+ Assert.IsFalse(Ui.Q("root").ClassListContains(UiLanguage.HebrewClass));+ Assert.AreEqual(En.Format("hud.turn", game.Bridge!.State.Turn), Ui.Q<Label>("turn").text);+ Assert.IsTrue(Ui.Query<TextElement>().ToList().All(t => t.ClassListContains("start-he") || t.languageDirection == LanguageDirection.Inherit));+ TheDeclarationStaysRightToLeft("an English restart");+ }++ static void TheDeclarationStaysRightToLeft(string after)+ {+ var lines = Ui.Query<TextElement>(className: "start-he").ToList();+ Assert.IsNotEmpty(lines, "Game.uxml's Hebrew start lines");+ foreach (var t in lines) Assert.AreEqual(LanguageDirection.RTL, t.languageDirection, $"after {after}: '{t.name}'");+ }++ // --- The direction ----------------------------------------------------------------------------------------------++ [Test]+ public void ATextIsRightToLeftWhenItsFirstLetterIsHebrew()+ {+ foreach (var s in new[] { "תור 1", "5 מלחמה כוללת", "קואליציה: 30 מתוך 37", "…אנו", "العربية" })+ Assert.IsTrue(UiDirection.RightToLeft(s), s);+ foreach (var s in new[] { "15 May 1948", "IL 20.0m", "+5%", "-5%", "30%", "", "David Ben-Gurion", "Mapai :מפלגה", "$40.0m", "1948" })+ Assert.IsFalse(UiDirection.RightToLeft(s), s);+ Assert.IsFalse(UiDirection.RightToLeft(null));+ }++ /// <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>+ [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.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}");+ // A text that changes takes its new direction at once.+ var turn = Ui.Q<Label>("turn");+ turn.text = "Turn 7";+ Assert.AreEqual(LanguageDirection.LTR, turn.languageDirection);+ turn.text = "תור 7";+ Assert.AreEqual(LanguageDirection.RTL, turn.languageDirection);+ // 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);+ }++ /// <summary>Many texts a presenter builds after boot get their words before they are on the panel (new Label(text)), so+ /// no text change reaches UiDirection: they take their direction when it walks the tree again, on the next frame after+ /// a submit, a click or a turn. Here: a label added before a submit, one added before a click, and the Why rows End+ /// Turn rebuilds (Hebrew headers, English lines).</summary>+ [UnityTest]+ public IEnumerator InHebrewTextsBuiltAfterBootTakeTheirDirectionAfterASubmitAClickOrATurn()+ {+ var restore = OnTexture(1920, 1080);+ try+ {+ var game = Object.FindFirstObjectByType<GameRoot>();+ game.Store = new SaveStore(saveDir);+ game.Language = UiLanguage.Hebrew;+ game.Begin(Inputs, 0);+ for (int i = 0; i < 2; i++) yield return null;++ // A submit and a click: a label added with its words already set has no direction until the next frame.+ var submitted = new Label(He["budget.vacant"]);+ Ui.Q("root").Add(submitted);+ Assert.AreEqual(LanguageDirection.Inherit, submitted.languageDirection);+ using (var e = NavigationSubmitEvent.GetPooled()) { e.target = submitted; submitted.SendEvent(e); }+ for (int i = 0; i < 2; i++) yield return null;+ Directed(new TextElement[] { submitted }, "a submit");+ var clicked = new Label("15 May 1948");+ Ui.Q("root").Add(clicked);+ Assert.AreEqual(LanguageDirection.Inherit, clicked.languageDirection);+ using (var e = ClickEvent.GetPooled()) { e.target = clicked; clicked.SendEvent(e); }+ for (int i = 0; i < 2; i++) yield return null;+ Directed(new TextElement[] { clicked }, "a click");++ // A turn: End Turn rebuilds the Why rows.+ game.Bridge!.EndTurn();+ var built = Ui.Q<ScrollView>("why-rows").contentContainer.Query<TextElement>().ToList();+ Assert.IsTrue(built.All(t => t.languageDirection == LanguageDirection.Inherit), "the new rows have no direction before the next frame");+ for (int i = 0; i < 2; i++) yield return null;+ Directed(built, "a turn");+ Assert.IsTrue(built.Any(t => t.languageDirection == LanguageDirection.RTL) && built.Any(t => t.languageDirection == LanguageDirection.LTR),+ "the rows mix Hebrew (the headers) and English (the lines, #55)");+ }+ finally { restore(); }+ }++ static void Directed(IList<TextElement> texts, string after)+ {+ Assert.IsNotEmpty(texts, after);+ foreach (var t in texts)+ Assert.AreEqual(UiDirection.RightToLeft(t.text) ? LanguageDirection.RTL : LanguageDirection.LTR, t.languageDirection, $"after {after}: '{t.name}': {t.text}");+ }++ /// <summary>Opens the map scene with its panel drawn into a texture of this size; the action it returns puts the panel back.</summary>+ static Action OnTexture(int width, int height)+ {+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);+ Object.FindFirstObjectByType<MapScene>().Build(Inputs.Map);+ var doc = Object.FindFirstObjectByType<UIDocument>();+ var rt = new RenderTexture(width, height, 0);+ var ps = Object.Instantiate(doc.panelSettings);+ ps.targetTexture = rt;+ doc.panelSettings = ps;+ return () => { doc.panelSettings = AssetDatabase.LoadAssetAtPath<PanelSettings>(UiPaths.Panel); Object.DestroyImmediate(ps); rt.Release(); Object.DestroyImmediate(rt); };+ }++ // --- The house ---------------------------------------------------------------------------------------------------++ /// <summary>In Hebrew the half circle is the same picture mirrored (#199): the first seat, the coalition's, is at the+ /// right end and the last at the left, at the same height. English keeps the first seat on the left.</summary>+ [Test]+ public void TheHemicycleIsMirroredInHebrewOnly()+ {+ var centre = new Vector2(160, 150);+ const float Scale = 100f;+ var seats = Hemicycle.Layout(120);+ Vector2 first = seats[0], last = seats[seats.Count - 1];+ Assert.Less(Hemicycle.ToBox(first, centre, Scale, mirrored: false).x, centre.x, "English: the first seat on the left");+ Assert.Greater(Hemicycle.ToBox(first, centre, Scale, mirrored: true).x, centre.x, "Hebrew: the first seat on the right");+ Assert.Less(Hemicycle.ToBox(last, centre, Scale, mirrored: true).x, centre.x);+ foreach (var seat in seats)+ {+ Vector2 ltr = Hemicycle.ToBox(seat, centre, Scale, false), rtl = Hemicycle.ToBox(seat, centre, Scale, true);+ Assert.AreEqual(2 * centre.x - ltr.x, rtl.x, 1e-3f, "mirrored about the centre line");+ Assert.AreEqual(ltr.y, rtl.y, "the same height");+ }++ using var ui = new UiTestKit();+ var c = Inputs.Content;+ SimBridge Game(UiText t) => new SimBridge(Statecraft.Sim.GameSession.New(c, Statecraft.Sim.GoldenRun.Seed, Statecraft.Sim.Mode.Historical), t);+ using (new CabinetPresenter(ui.Root, Game(En), En, null))+ Assert.IsFalse(ui.Q<Hemicycle>("cabinet-hemicycle").Mirrored, "English");+ using (new CabinetPresenter(ui.Root, Game(He), He, null))+ Assert.IsTrue(ui.Q<Hemicycle>("cabinet-hemicycle").Mirrored, "Hebrew");+ using (new CabinetPresenter(ui.Root, Game(En), En, null))+ Assert.IsFalse(ui.Q<Hemicycle>("cabinet-hemicycle").Mirrored, "English again: the mark does not stick");+ }++ // --- The Budget rows --------------------------------------------------------------------------------------------++ /// <summary>No Budget row is wider than the screen, in either language, at the widest and the narrowest window: the+ /// office name wraps in its column (in Hebrew a row with a Hebrew phrase inside an English office was wider than the+ /// screen at 1920x1080, and the screen scrolled sideways).</summary>+ [UnityTest]+ public IEnumerator NoBudgetRowIsWiderThanItsScreen(+ [Values(UiLanguage.Hebrew, UiLanguage.English)] string language, [Values(1920, 390)] int width)+ {+ var restore = OnTexture(width, width == 1920 ? 1080 : 844);+ try+ {+ var game = Object.FindFirstObjectByType<GameRoot>();+ game.Store = new SaveStore(saveDir);+ game.Language = language;+ game.Begin(Inputs, 0);+ UiTestKit.Press(Ui.Q<Button>("nav-budget"));+ for (int i = 0; i < 4; i++) yield return null; // layout needs a few passes+ var list = Ui.Q<ScrollView>("budget-rows");+ var room = list.contentViewport.layout.width;+ Assert.Greater(room, 100f, "the Budget screen is open");+ var rows = list.contentContainer.Children().ToList();+ Assert.Greater(rows.Count, 3);+ foreach (var row in rows)+ {+ Assert.LessOrEqual(row.layout.width, room + 0.5f, $"{language} {width}: '{row[0].name}' is wider than the screen");+ foreach (var part in row.Children())+ {+ Assert.LessOrEqual(part.layout.xMax, row.layout.width + 0.5f, $"{language} {width}: '{part.name}' runs past its row's end");+ Assert.GreaterOrEqual(part.layout.xMin, -0.5f, $"{language} {width}: '{part.name}' runs past its row's start");+ }+ }+ Assert.LessOrEqual(list.contentContainer.layout.width, room + 0.5f, $"{language} {width}: the rows scroll sideways");+ // The control: without the wrapping class the long Hebrew row is wider than the screen at 1920 (so this test can fail).+ if (language == UiLanguage.Hebrew && width == 1920)+ {+ foreach (var row in rows) row[0].RemoveFromClassList("budget-office");+ for (int i = 0; i < 4; i++) yield return null;+ Assert.IsTrue(rows.Any(r => r.layout.width > room + 0.5f || r.Children().Any(x => x.layout.xMin < -0.5f || x.layout.xMax > r.layout.width + 0.5f)),+ "control: without the class a row overflows (in Hebrew the row runs right to left, so it spills past the start)");+ }+ }+ finally { restore(); }+ }++ // --- The face ---------------------------------------------------------------------------------------------------++ /// <summary>The classes a rule of Statecraft.uss sets in EB Garamond (".year", ".why-group"); type selectors are left out.</summary>+ static string[] GaramondClasses()+ {+ var uss = Regex.Replace(File.ReadAllText(UiPaths.Folder + "/Statecraft.uss"), @"/\*.*?\*/", "", RegexOptions.Singleline);+ return Regex.Matches(uss, @"([^{}]+)\{([^{}]*)\}").Cast<Match>().Where(m => m.Groups[2].Value.Contains("EBGaramond"))+ .SelectMany(m => Regex.Matches(m.Groups[1].Value, @"\.([\w-]+)").Cast<Match>().Select(c => c.Groups[1].Value)).Distinct().ToArray();+ }++ /// <summary>With .lang-he on the root every text element of Game.uxml resolves Frank Ruhl Libre and the advanced+ /// generator, whatever rule styles it; without it (the control) the same elements resolve EB Garamond. So do labels+ /// with the classes only presenters add (the Why headers, the person cards, the map labels).</summary>+ [UnityTest]+ public IEnumerator InHebrewEveryTextIsSetInTheHebrewFaceThroughTheAdvancedGenerator()+ {+ var rt = new RenderTexture(1920, 1080, 0);+ var ps = Object.Instantiate(AssetDatabase.LoadAssetAtPath<PanelSettings>(UiPaths.Panel));+ ps.targetTexture = rt;+ var go = new GameObject("HebrewUiTest");+ go.SetActive(false);+ var doc = go.AddComponent<UIDocument>();+ doc.panelSettings = ps;+ doc.visualTreeAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(UiPaths.GameUxml);+ go.SetActive(true);+ try+ {+ var hebrew = AssetDatabase.LoadAssetAtPath<Font>(UiPaths.FontHebrew);+ Assert.IsNotNull(hebrew, UiPaths.FontHebrew);+ var root = doc.rootVisualElement.Q("root");+ static Font? FontOf(TextElement e)+ {+ var d = e.resolvedStyle.unityFontDefinition;+ return d.fontAsset != null ? d.fontAsset.sourceFontFile : d.font;+ }+ // A class a rule sets in EB Garamond that no element of Game.uxml carries is added at runtime: a label carries it.+ var classes = GaramondClasses();+ Assert.Contains("why-group", classes, "the rules are read");+ foreach (var c in classes.Where(c => root.Q(className: c) == null))+ {+ var l = new Label("א") { name = "runtime-" + c };+ l.AddToClassList(c);+ root.Add(l);+ }+ // The start screen's Hebrew lines are Hebrew in both languages (the Declaration's own text).+ var texts = root.Query<TextElement>().ToList().Where(e => !e.ClassListContains("start-he")).ToList();+ Assert.Greater(texts.Count, 30, "Game.uxml's labels and buttons");+ for (int i = 0; i < 3; i++) yield return null; // resolved styles need a style pass+ foreach (var e in texts)+ Assert.AreNotSame(hebrew, FontOf(e), $"English: '{e.name}' ({string.Join(" ", e.GetClasses())})");+ root.AddToClassList(UiLanguage.HebrewClass);+ for (int i = 0; i < 3; i++) yield return null;+ foreach (var e in texts)+ {+ var what = $"'{e.name}' ({string.Join(" ", e.GetClasses())})";+ Assert.AreSame(hebrew, FontOf(e), what);+ Assert.AreEqual("Advanced", e.resolvedStyle.unityTextGenerator.ToString(), what);+ }+ }+ finally { Object.DestroyImmediate(go); Object.DestroyImmediate(ps); rt.Release(); Object.DestroyImmediate(rt); }+ }+}diff --git a/unity/Assets/Tests/EditMode/HebrewUiTests.cs.meta b/unity/Assets/Tests/EditMode/HebrewUiTests.cs.metanew file mode 100644index 000000000..626bb0a51--- /dev/null+++ b/unity/Assets/Tests/EditMode/HebrewUiTests.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 8d8f0b5cb4240447aa8c4a3155570010\ No newline at end of filediff --git a/unity/Assets/Tests/EditMode/LocalityNameTests.cs b/unity/Assets/Tests/EditMode/LocalityNameTests.csindex 58cb22bab..cac6fd1ca 100644--- a/unity/Assets/Tests/EditMode/LocalityNameTests.cs+++ b/unity/Assets/Tests/EditMode/LocalityNameTests.cs@@ -20,7 +20,7 @@ public class LocalityNameTestsstatic readonly Content C = ContentLoader.Load(Paths.Content);MapScene map = null!;static UiText En => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings).text);- static UiText He => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings.Replace("strings.en.yaml", "strings.he.yaml")).text, "strings.he.yaml");+ static UiText He => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.StringsHebrew).text, "strings.he.yaml");[SetUp]public void Open() { EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single); map = Object.FindFirstObjectByType<MapScene>(); map.Build(); }diff --git a/unity/Assets/UI/Statecraft.uss b/unity/Assets/UI/Statecraft.ussindex d221acd3f..5e65eb991 100644--- a/unity/Assets/UI/Statecraft.uss+++ b/unity/Assets/UI/Statecraft.uss@@ -446,6 +446,9 @@ Button:disabled { color: var(--ink-dim); border-color: rgba(120, 120, 120, 0.4);.defence-budget { flex-direction: row; align-items: center; }.budget-title { margin: 0 18px 0 0; }.budget-share { margin-left: 16px; font-size: 18px; }+/* A Budget row's office name wraps within the room its buttons leave, so no row is wider than the screen (the+ longest, "Minister of Education and Culture (no office until 10 March 1949)", in either language). */+.budget-office { white-space: normal; flex-shrink: 1; min-width: 0; }/* A wide screen's header wraps its subtitle under the title when the window is narrow. *//* Square and narrower windows: a slimmer side column leaves room for two columns of cards. */.hud-two-row .cabinet-side { width: 250px; }@@ -563,3 +566,61 @@ Button:disabled { color: var(--ink-dim); border-color: rgba(120, 120, 120, 0.4);.start-caption-en { font-size: 19px; color: var(--ink); white-space: normal; -unity-text-align: middle-center; margin: 4px 0 0 0; }/* New Game's prompt (the toast) shows at the top of the start screen, clear of the panel. */.start-open .toast { top: 24px; left: 25%; right: 25%; width: auto; }++/* --- The Hebrew UI (#193; UiLanguage, "?lang=he") -------------------------------------------------------------------+ GameRoot puts .lang-he on the root. Every text is then set in Frank Ruhl Libre (EB Garamond has no Hebrew; one weight,+ so headings lose the semi-bold) through the advanced text generator, which orders right-to-left text and the numbers+ in it. Each rule above that names EB Garamond is listed here; HebrewUiTests fails for one that is missed, including the+ classes only presenters add (it gives a label each). */+.lang-he, .lang-he .title, .lang-he .button, .lang-he Button, .lang-he .year, .lang-he .end-turn, .lang-he .draft,+.lang-he .why-group, .lang-he .section-title, .lang-he .card-initials, .lang-he .card-name, .lang-he .house-size,+.lang-he .big-figure, .lang-he .map-label, .lang-he .map-label-tooltip, .lang-he .start-title, .lang-he .start-button {+ -unity-font-definition: url("project://database/Assets/UI/Fonts/FrankRuhlLibre/FrankRuhlLibre-Medium.ttf");+ -unity-text-generator: advanced;+}+/* Mirrored for a right-to-left reader: text is set from the right, every row runs right to left (so a caption's value,+ a card's bars and a button's neighbours follow it on its left), and the side margins swap. What is placed by the map+ stays where it is: the minimap column, the info panel, the toast and the screens' position. Each text's paragraph+ direction is set in code from its own words (UiDirection), because dates, money and names are still English (#55). */+.lang-he { -unity-text-align: upper-right; }+.lang-he .button, .lang-he Button, .lang-he #event-options Button { -unity-text-align: middle-right; }+/* The buttons and cards whose text is centred stay centred (the rule above is the more specific one). */+.lang-he .nav-button, .lang-he .seat { -unity-text-align: upper-center; }+.lang-he .event-reopen, .lang-he .event-hide, .lang-he .event-illustration, .lang-he .start-button, .lang-he .start-listen { -unity-text-align: middle-center; }+.lang-he .card-stat-name { -unity-text-align: middle-right; }+.lang-he .card-stat-value { -unity-text-align: middle-left; }+.lang-he .top-bar, .lang-he .date-row, .lang-he .meters, .lang-he .meter, .lang-he .meter-row, .lang-he .nav, .lang-he .row,+.lang-he .event-foot, .lang-he .event-head, .lang-he .info-panel, .lang-he .info-row, .lang-he .card-stat, .lang-he .pm-offices,+.lang-he .cabinet-house, .lang-he .party-chips, .lang-he .party-chip, .lang-he .defence-row, .lang-he .leaders, .lang-he .rung,+.lang-he .defence-budget, .lang-he #cabinet-seats .unity-scroll-view__content-container { flex-direction: row-reverse; }+.lang-he.hud-narrow .meter-row { flex-direction: column; align-items: flex-end; }+.lang-he .turn-box { align-items: flex-start; }+.lang-he .top-bar { padding: 0 8px 0 14px; }+.lang-he .date-box { margin-right: 0; margin-left: 10px; padding: 0 12px 0 10px; }+.lang-he .date-row Label { margin-right: 0; margin-left: 8px; }+.lang-he .meter { border-right-width: 0; border-left-width: 1px; padding: 0 6px 0 7px; }+.lang-he .meter-icon { margin-right: 0; margin-left: 5px; }+.lang-he .meter-delta { margin-left: 0; margin-right: 7px; }+.lang-he.hud-narrow .meter-delta { margin-right: 0; }+.lang-he .event-hide { margin: 2px 12px 0 0; }+.lang-he .event-image { margin-right: 0; margin-left: 12px; }+.lang-he .info-thumb { margin-right: 0; margin-left: 14px; }+.lang-he .info-row-sign { margin: 3px 0 0 10px; }+.lang-he .info-body > .row Button { margin-right: 0; margin-left: 6px; }+.lang-he .why-line { padding-left: 0; padding-right: 12px; }+.lang-he .section-title { margin: 0 2px 8px 0; }+.lang-he .cabinet-side { margin-right: 0; margin-left: 14px; }+.lang-he .pm-office { margin: 0 0 4px 6px; }+.lang-he .hemicycle-box { margin-right: 0; margin-left: 18px; }+.lang-he .party-chip { margin: 0 0 2px 12px; }+.lang-he .party-swatch { margin-right: 0; margin-left: 5px; }+.lang-he .rung { border-left-width: 0; border-right-width: 3px; }+.lang-he .rung-target { border-left-width: 1px; border-right-width: 3px; }+.lang-he .rung-turn { margin-left: 0; margin-right: 8px; }+.lang-he .budget-title { margin: 0 0 0 18px; }+.lang-he .budget-share { margin-left: 0; margin-right: 16px; }+/* The option's round sign and End Turn's hourglass are painted on the right in Hebrew (EventCardPresenter, HudPresenter). */+.lang-he .event-option { padding: 5px 46px 5px 12px; }+.lang-he .end-turn { padding: 4px 40px 4px 14px; }+/* A bar fills from the right: the whole bar is flipped, so its fill and its mark (placed from the left in code) follow. */+.lang-he .ui-bar { scale: -1 1; }diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yamlindex ba4398597..d807c9682 100644--- a/unity/Assets/UI/strings.he.yaml+++ b/unity/Assets/UI/strings.he.yaml@@ -1,5 +1,5 @@-# Hebrew UI translation data for #12, not yet loaded by the game. Runtime language switch, Hebrew font and-# Advanced Text Generator/RTL mixed-direction layout need Unity review before enabling this file.+# UI strings (Hebrew, #12). GameRoot loads them in place of strings.en.yaml only when Hebrew is asked for by hand+# ("?lang=he" on the web, "-lang he" on the desktop; UiLanguage, #193); there is no visible switch yet.# Keep logical Hebrew order, never reverse strings. Exact string.Format tokens match strings.en.yaml;# dates, money, names and content still arrive from the current English content/PlayerText paths.hud.turn: "תור {0}"