A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Orders refusals: a sim constant each, shown in the UI's language (Refs #2040) (#2059)
Beri6fc2808d0d9e
diff --git a/changelog.d/laneOD-orders-refusals.md b/changelog.d/laneOD-orders-refusals.mdnew file mode 100644index 000000000..257d92f72--- /dev/null+++ b/changelog.d/laneOD-orders-refusals.md@@ -0,0 +1,6 @@+### Fixed+- The unit card's standing-order refusals ("Artillery does not hold ground" and the five others `Orders.Check` gives)+ now read in the UI's language: each is a public `Orders.Refused*` constant in the sim, with its English unchanged,+ and `SimBridge.ReasonText` maps it to a `unit.order_refused.*` string for the card, the order queue and the+ end-of-turn toast. The Hebrew lines wait for the native-speaker read (#564). Saves and goldens did not move+ (Refs #2040).diff --git a/sim/Statecraft.Sim/Orders.cs b/sim/Statecraft.Sim/Orders.csindex 97b9d2ba0..26c7d3971 100644--- a/sim/Statecraft.Sim/Orders.cs+++ b/sim/Statecraft.Sim/Orders.cs@@ -17,6 +17,15 @@ namespace Statecraft.Sim/// (resolver step 2) runs before that step, so it never sees a fortify given the same turn.</summary>public const string Fortifying = "fortifying";+ /// <summary><see cref="Check"/>'s refusals (#2045): the UI maps each to its own string (SimBridge.ReasonText). The+ /// English is the reason a turn's Rejected list and a save carry, so it does not change.</summary>+ public const string RefusedUnknownOrder = "That order is not known";+ public const string RefusedNoUnit = "There is no such unit";+ public const string RefusedNotMilitary = "Only a military unit takes that order";+ public const string RefusedNotYours = "That unit is not yours";+ public const string RefusedArtilleryHold = "Artillery does not hold ground";+ public const string RefusedAlready = "That unit already has that order";+/// <summary>The player's side (units_1948.yaml's id). Only the player's military units take orders.</summary>const string PlayerSide = "israel";@@ -34,13 +43,13 @@ namespace Statecraft.Sim/// does not give it.</summary>public static string? Check(Content c, GameState s, int unitId, string order, bool enemy = false){- if (order != Fortify && order != Hold) return "That order is not known";- if (!s.Units.TryGetValue(unitId, out var u)) return "There is no such unit";- if (u.Side == "") return "Only a military unit takes that order";- if ((u.Side != PlayerSide) != enemy) return "That unit is not yours";- if (order == Hold && c.UnitTypes.FirstOrDefault(t => t.Id == u.Type)?.Class == Combat.ArtilleryClass) return "Artillery does not hold ground";+ if (order != Fortify && order != Hold) return RefusedUnknownOrder;+ if (!s.Units.TryGetValue(unitId, out var u)) return RefusedNoUnit;+ if (u.Side == "") return RefusedNotMilitary;+ if ((u.Side != PlayerSide) != enemy) return RefusedNotYours;+ if (order == Hold && c.UnitTypes.FirstOrDefault(t => t.Id == u.Type)?.Class == Combat.ArtilleryClass) return RefusedArtilleryHold;var already = order == Hold ? u.Order == Hold : (u.Order == Fortify || u.Order == Fortifying) && u.OrderTarget == Hex(u);- return already ? "That unit already has that order" : null;+ return already ? RefusedAlready : null;}/// <summary>R-ORDER-001: gives the unit its standing order, replacing any other. Fortify names the unit's hex and startsdiff --git a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs b/unity/Assets/Scripts/UI/InfoPanelPresenter.csindex 443a749d4..10cd25464 100644--- a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs+++ b/unity/Assets/Scripts/UI/InfoPanelPresenter.cs@@ -749,8 +749,8 @@ namespace Statecraft.Game.UIshowReachable?.Invoke(hexes);}moveButton.style.display = moves != null ? DisplayStyle.Flex : DisplayStyle.None;- // Fortify and Hold (#754): each offered only where the sim's Orders.Check takes it; else the sim's reason, as given,- // on Israel's units only (an enemy's card would only repeat the sim's English "That unit is not yours").+ // Fortify and Hold (#754): each offered only where the sim's Orders.Check takes it; else the sim's reason, in the UI's+ // language (#2045), on Israel's units only (an enemy's card would only repeat "That unit is not yours").var orderUnit = OrderUnit(); var shownUnit = ShownUnit();var own = unit?.Token.Unit.Side == UnitData.Israel;var refusals = new List<string>();@@ -758,7 +758,7 @@ namespace Statecraft.Game.UI{var why = orderUnit is int ou ? Orders.Check(c, s, ou, order) : null;button.style.display = orderUnit != null && why == null ? DisplayStyle.Flex : DisplayStyle.None;- if (why != null && own && !refusals.Contains(why)) refusals.Add(why);+ if (why != null && own && SimBridge.ReasonText(text, why) is var said && !refusals.Contains(said)) refusals.Add(said);}// Attack (#754): offered where the sim's Combat.Check takes some hex; its refusals in reach show as the others'.var attacks = AttackTargets();diff --git a/unity/Assets/Scripts/UI/SimBridge.cs b/unity/Assets/Scripts/UI/SimBridge.csindex 63505d196..65f0be270 100644--- a/unity/Assets/Scripts/UI/SimBridge.cs+++ b/unity/Assets/Scripts/UI/SimBridge.cs@@ -211,7 +211,25 @@ namespace Statecraft.Game.UI}}- string? Refuse(string reason) { if (reason == Movement.MissingArtilleryMovement) reason = text["unit.artillery_move_missing"]; Refused?.Invoke(reason); return reason; }+ /// <summary>The sim's English refusals that have a UI string: Movement's artillery refusal and Orders.Check's (#2045).+ /// Keyed on the English, so the same words from another check (Movement, Combat, Training, Demobilization give "That+ /// unit is not yours", "There is no such unit" too) read in the UI's language as well.</summary>+ static readonly Dictionary<string, string> ReasonKeys = new Dictionary<string, string>+ {+ [Movement.MissingArtilleryMovement] = "unit.artillery_move_missing",+ [Orders.RefusedUnknownOrder] = "unit.order_refused.unknown_order",+ [Orders.RefusedNoUnit] = "unit.order_refused.no_unit",+ [Orders.RefusedNotMilitary] = "unit.order_refused.not_military",+ [Orders.RefusedNotYours] = "unit.order_refused.not_yours",+ [Orders.RefusedArtilleryHold] = "unit.order_refused.artillery_hold",+ [Orders.RefusedAlready] = "unit.order_refused.already",+ };++ /// <summary>A sim refusal in the UI's language where it has a string (<see cref="ReasonKeys"/>), else the sim's English as+ /// given. The queue's refusals, the unit card's (InfoPanelPresenter) and the end of turn's (ToastPresenter) go through it.</summary>+ public static string ReasonText(UiText text, string reason) => ReasonKeys.TryGetValue(reason, out var key) ? text[key] : reason;++ string? Refuse(string reason) { reason = ReasonText(text, reason); Refused?.Invoke(reason); return reason; }static void Notify(Action? handlers){diff --git a/unity/Assets/Scripts/UI/ToastPresenter.cs b/unity/Assets/Scripts/UI/ToastPresenter.csindex bb66d3ee7..9fc6d0a57 100644--- a/unity/Assets/Scripts/UI/ToastPresenter.cs+++ b/unity/Assets/Scripts/UI/ToastPresenter.cs@@ -26,7 +26,7 @@ namespace Statecraft.Game.UIpublic ToastPresenter(VisualElement root, SimBridge bridge, UiText text){label = root.Q<Label>("toast"); this.text = text; this.bridge = bridge;- onTurnEnded = r => Show(r.Select(x => text.Format("toast.refused", x.Reason)));+ onTurnEnded = r => Show(r.Select(x => text.Format("toast.refused", SimBridge.ReasonText(text, x.Reason))));onCommitted = why => Show(why.Where(x => WhyKeys.All.Contains(x.Key)) // unit lines only: a call-up order's line (B1 key) is no toast.Select(x => UnitNames.Line(x, bridge.Content, units, text, TownNamesHe)));onRouteStep = _ =>diff --git a/unity/Assets/Tests/EditMode/HebrewUiTests.cs b/unity/Assets/Tests/EditMode/HebrewUiTests.csindex a3a1a2fcc..464132cc7 100644--- a/unity/Assets/Tests/EditMode/HebrewUiTests.cs+++ b/unity/Assets/Tests/EditMode/HebrewUiTests.cs@@ -73,6 +73,23 @@ public class HebrewUiTestsstatic VisualElement Ui => Object.FindFirstObjectByType<UIDocument>().rootVisualElement;+ // #2045: every Orders.Check refusal (its Refused* constants) has a string in both files, and the Hebrew one is Hebrew,+ // not the sim's English. A missing key throws in UiText's lookup.+ [Test]+ public void EveryStandingOrderRefusalHasAStringInBothLanguages()+ {+ var refusals = typeof(Statecraft.Sim.Orders).GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static)+ .Where(f => f.IsLiteral && f.Name.StartsWith("Refused")).Select(f => (string)f.GetRawConstantValue()).ToList();+ Assert.That(refusals, Is.Not.Empty);+ foreach (var reason in refusals)+ {+ Assert.AreEqual(reason, SimBridge.ReasonText(En, reason), "the English string is the sim's own");+ var he = SimBridge.ReasonText(He, reason);+ Assert.AreNotEqual(reason, he, "no Hebrew string for: " + reason);+ StringAssert.IsMatch("[\u05D0-\u05EA]", he, reason);+ }+ }+[Test]public void TheGameIsEnglishUnlessHebrewIsAskedFor(){diff --git a/unity/Assets/Tests/EditMode/InfoPanelLayoutTests.cs b/unity/Assets/Tests/EditMode/InfoPanelLayoutTests.csindex 97b34c5fb..573a2f0b8 100644--- a/unity/Assets/Tests/EditMode/InfoPanelLayoutTests.cs+++ b/unity/Assets/Tests/EditMode/InfoPanelLayoutTests.cs@@ -923,4 +923,19 @@ public class InfoPanelLayoutTests},text:text,hebrew:hebrew,unit:()=>f.token);}+ // #2045: the gun's card says why it is offered no Hold (Orders.Check: artillery never holds ground) in the UI's language,+ // not in the sim's English.+ [UnityTest]+ public IEnumerator Gdd03GunCardRefusesHoldInTheUiLanguage([Values(false,true)] bool hebrew)+ {+ var f=MilitaryFixture(Combat.ArtilleryClass);var g=f.session;+ var text=UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(hebrew?UiPaths.StringsHebrew:UiPaths.Strings).text);+ Assert.AreEqual(Orders.RefusedArtilleryHold,Orders.Check(g.Content,g.State,f.id,Orders.Hold));+ yield return Rendered(1512,982,g,(root,info)=>info.ShowUnit(),root=> {+ var reason=root.Q<Label>("info-reason").text;+ StringAssert.Contains(text["unit.order_refused.artillery_hold"],reason);+ if (hebrew) StringAssert.DoesNotContain(Orders.RefusedArtilleryHold,reason);+ },text:text,hebrew:hebrew,unit:()=>f.token);+ }+}diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yamlindex f082e1727..152825008 100644--- a/unity/Assets/UI/strings.en.yaml+++ b/unity/Assets/UI/strings.en.yaml@@ -916,6 +916,14 @@ unit.artillery_move_missing: "Artillery cannot move yet: its movement points havunit.fire_ready: "Fire available"unit.fire_spent: "Fired this turn"+# #2045 standing-order refusals (Orders.Check), shown on the unit card.+unit.order_refused.unknown_order: "That order is not known"+unit.order_refused.no_unit: "There is no such unit"+unit.order_refused.not_military: "Only a military unit takes that order"+unit.order_refused.not_yours: "That unit is not yours"+unit.order_refused.artillery_hold: "Artillery does not hold ground"+unit.order_refused.already: "That unit already has that order"+# #1682 remaining Cause producers. English report wording preserved.why.cause.workers_assigned: "{0}: {1} groups in work"why.cause.wages_paid: "{0}: jobs paid {1}"diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yamlindex 1f63fba45..4636914c0 100644--- a/unity/Assets/UI/strings.he.yaml+++ b/unity/Assets/UI/strings.he.yaml@@ -1018,6 +1018,15 @@ unit.artillery_move_missing: "לא ניתן להזיז ארטילריה עדייunit.fire_ready: "ניתן לירות"unit.fire_spent: "הירי בוצע בתור הזה"+# #2045 standing-order refusals (Orders.Check), shown on the unit card.+# For the native reviewer (#564).+unit.order_refused.unknown_order: "הפקודה אינה מוכרת"+unit.order_refused.no_unit: "אין יחידה כזאת"+unit.order_refused.not_military: "רק יחידה צבאית מקבלת פקודה זו"+unit.order_refused.not_yours: "היחידה אינה שלך"+unit.order_refused.artillery_hold: "ארטילריה אינה מחזיקה בשטח"+unit.order_refused.already: "היחידה כבר קיבלה פקודה זו"+# #1682 remaining Cause producers. Agent-drafted Hebrew: native-review-pending (#564).# SENSITIVE: capture, displacement, Deport, annexation and occupation also await sensitivity review.why.cause.workers_assigned: "{0}: קבוצות בעבודה: {1}"