Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

Unity: outcome clip caption uses the option's Hebrew text in Hebrew (Fixes #1210) (#1217)

Bericae8ba80be33
diff --git a/changelog.d/ui-outcome-caption-he-1210.md b/changelog.d/ui-outcome-caption-he-1210.md
new file mode 100644
index 000000000..1b95d6a85
--- /dev/null
+++ b/changelog.d/ui-outcome-caption-he-1210.md
@@ -0,0 +1,3 @@
+### Fixed
+- In Hebrew the outcome clip's caption ("הפקודה שלך: ...") shows the option's Hebrew text, the way the event card shows
+ it; an option with no Hebrew keeps its English (#1210).
diff --git a/unity/Assets/Scripts/UI/ContentNames.cs b/unity/Assets/Scripts/UI/ContentNames.cs
index 1fbf0499a..30f8aad3c 100644
--- a/unity/Assets/Scripts/UI/ContentNames.cs
+++ b/unity/Assets/Scripts/UI/ContentNames.cs
@@ -1,4 +1,5 @@
#nullable enable
+using System;
using Statecraft.Sim;
namespace Statecraft.Game.UI
@@ -19,5 +20,11 @@ namespace Statecraft.Game.UI
/// the row's feminine title_he_f, which every office with a Hebrew title has (owner on #861: "Move to content"), so
/// the UI derives no form; an office with no Hebrew title for her keeps the English.</summary>
public static string Of(UiText text, Office o, Person? holder) => Pick(text, o.Title, o.TitleHeFor(holder));
+
+ /// <summary>A content text in the UI's language, the one rule the event card and the outcome caption share (#1064,
+ /// #1210): in Hebrew the row's Hebrew <paramref name="hebrew"/> with the ministers' Hebrew names in its placeholders;
+ /// <paramref name="english"/> (already filled) wherever the row has no Hebrew text, and always in English.</summary>
+ public static string Fill(UiText text, Content c, GameState s, DateTime date, string english, string hebrew) =>
+ hebrew != "" && text["ui.lang"] == UiLanguage.Hebrew ? Cabinet.Fill(c, s, hebrew, date, p => Of(text, p)) : english;
}
}
diff --git a/unity/Assets/Scripts/UI/EventCardPresenter.cs b/unity/Assets/Scripts/UI/EventCardPresenter.cs
index b6649a7d4..9b32e42ed 100644
--- a/unity/Assets/Scripts/UI/EventCardPresenter.cs
+++ b/unity/Assets/Scripts/UI/EventCardPresenter.cs
@@ -248,8 +248,7 @@ namespace Statecraft.Game.UI
// the ministers' Hebrew names in its placeholders, and the English where it has none (fail open). A variant
// (R-ALT-010) has no Hebrew, so a card on a road not taken keeps its variant's English.
var variant = Timeline.Variant(c, s, e);
- bool hebrew = text["ui.lang"] == UiLanguage.Hebrew;
- string Local(string english, string he) => hebrew && he != "" ? Cabinet.Fill(c, s, he, date, p => ContentNames.Of(text, p)) : english;
+ string Local(string english, string he) => ContentNames.Fill(text, c, s, date, english, he);
card.Q<Label>("event-title").text = Local(EventSystem.Title(c, s, e), variant == null || variant.Title == "" ? e.TitleHe : "");
var banner = card.Q<Label>("event-alt-banner"); // a consequence card's road (#954); none on any other card
banner.text = OriginLine(c, s, e, text);
diff --git a/unity/Assets/Scripts/UI/OutcomePresenter.cs b/unity/Assets/Scripts/UI/OutcomePresenter.cs
index 3b6a75a13..f83a8c503 100644
--- a/unity/Assets/Scripts/UI/OutcomePresenter.cs
+++ b/unity/Assets/Scripts/UI/OutcomePresenter.cs
@@ -120,7 +120,12 @@ namespace Statecraft.Game.UI
var option = ev?.Options.FirstOrDefault(o => o.Id == order.OptionId);
if (ev == null || option == null || !option.Historical) continue; // the mapping refuses this too
string words;
- try { words = Cabinet.Fill(c, s, option.Text, EventSystem.FillDate(ev, bridge.LastBatchDate)); } // the card's date
+ try
+ {
+ var date = EventSystem.FillDate(ev, bridge.LastBatchDate); // the card's date
+ // The option as the card shows it (#1210): its text_he in Hebrew, the English when it has none.
+ words = ContentNames.Fill(text, c, s, date, Cabinet.Fill(c, s, option.Text, date), option.TextHe);
+ }
catch (Exception e) // never let a caption break the turn's other TurnEnded work (the autosave)
{
UnityEngine.Debug.LogWarning($"VIDEO outcome caption for {order.EventId}/{order.OptionId}: {e.Message}");
diff --git a/unity/Assets/Tests/EditMode/HebrewUiTests.cs b/unity/Assets/Tests/EditMode/HebrewUiTests.cs
index 6532c8afc..7cbd89ebf 100644
--- a/unity/Assets/Tests/EditMode/HebrewUiTests.cs
+++ b/unity/Assets/Tests/EditMode/HebrewUiTests.cs
@@ -630,4 +630,18 @@ public class HebrewUiTests
}
finally { Object.DestroyImmediate(go); Object.DestroyImmediate(ps); rt.Release(); Object.DestroyImmediate(rt); }
}
+
+ /// <summary>#1210: the one rule the event card and the outcome caption share. In Hebrew a text with a Hebrew form shows
+ /// it, a text without one falls back to the English (fail open); in English the English always.</summary>
+ [Test]
+ public void ContentNamesFillPicksTheHebrewTextOnlyInHebrewAndWhereThereIsOne()
+ {
+ var c = Inputs.Content;
+ var s = Statecraft.Sim.Simulation.NewGame(c, 1, Statecraft.Sim.Mode.Historical);
+ var option = c.Events.First(e => e.Id == "maabarot_policy").Options.First(o => o.Id == "maabarot");
+ StringAssert.DoesNotContain("{", option.TextHe, "precondition: no placeholder, so the Hebrew shows as written");
+ Assert.AreEqual(option.TextHe, ContentNames.Fill(He, c, s, s.Date, option.Text, option.TextHe));
+ Assert.AreEqual(option.Text, ContentNames.Fill(He, c, s, s.Date, option.Text, ""), "no text_he: the English");
+ Assert.AreEqual(option.Text, ContentNames.Fill(En, c, s, s.Date, option.Text, option.TextHe), "English UI: the English");
+ }
}
diff --git a/unity/Assets/Tests/EditMode/OutcomeClipTests.cs b/unity/Assets/Tests/EditMode/OutcomeClipTests.cs
index fc0d9b3c4..ce907d6f8 100644
--- a/unity/Assets/Tests/EditMode/OutcomeClipTests.cs
+++ b/unity/Assets/Tests/EditMode/OutcomeClipTests.cs
@@ -24,6 +24,7 @@ public class OutcomeClipTests
{
static readonly Content C = ContentLoader.Load(Paths.Content);
static UiText Text => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings).text);
+ static UiText He => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.StringsHebrew).text, "strings.he.yaml");
static string Yaml => File.ReadAllText(EventVideoMapping.Path);
[Test]
@@ -59,8 +60,9 @@ public class OutcomeClipTests
public int Closed;
readonly GameObject go; readonly PanelSettings ps; readonly RenderTexture rt; readonly List<IDisposable> owned = new List<IDisposable>();
- public Rig(string[] events, Func<GameSession, IReadOnlyList<Command>, StepResult>? step = null)
+ public Rig(string[] events, Func<GameSession, IReadOnlyList<Command>, StepResult>? step = null, UiText? text = null, Content? content = null)
{
+ var t = text ?? Text; var c = content ?? C;
rt = new RenderTexture(1920, 1080, 0);
ps = Object.Instantiate(AssetDatabase.LoadAssetAtPath<PanelSettings>(UiPaths.Panel));
ps.targetTexture = rt;
@@ -72,14 +74,14 @@ public class OutcomeClipTests
go.SetActive(true);
Root = doc.rootVisualElement;
Root.Q("root").RemoveFromClassList("loading");
- var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);
- g.State.Date = C.Events.First(e => e.Id == events[0]).From;
+ var g = GameSession.New(c, GoldenRun.Seed, Mode.Historical);
+ g.State.Date = c.Events.First(e => e.Id == events[0]).From;
g.State.PendingEvents.Clear(); g.State.PendingEvents.AddRange(events);
- Bridge = new SimBridge(g, Text, step);
- owned.Add(new HudPresenter(Root, Bridge, Text));
+ Bridge = new SimBridge(g, t, step);
+ owned.Add(new HudPresenter(Root, Bridge, t));
Nav = new ScreenNav(Root); owned.Add(Nav);
- Card = new EventCardPresenter(Root, Bridge, Text, null, null, CardPlayer, _ => null); owned.Add(Card);
- Outcomes = new OutcomePresenter(Root, Bridge, Text, OutcomePlayer, EventVideoMapping.ParseOutcomes(Yaml), () => Closed++, () => Nav.Close());
+ Card = new EventCardPresenter(Root, Bridge, t, null, null, CardPlayer, _ => null); owned.Add(Card);
+ Outcomes = new OutcomePresenter(Root, Bridge, t, OutcomePlayer, EventVideoMapping.ParseOutcomes(Yaml), () => Closed++, () => Nav.Close());
owned.Add(Outcomes);
owned.Add(CardPlayer); owned.Add(OutcomePlayer);
}
@@ -118,6 +120,32 @@ public class OutcomeClipTests
Assert.AreEqual("AI-generated illustration", r.Root.Q<Label>("outcome-label").text);
}
+ /// <summary>#1210: in Hebrew the caption is the order in the option's text_he, the way the event card shows it; an
+ /// option with no Hebrew falls back to its English text (fail open, like the card).</summary>
+ [Test]
+ public void InHebrewTheCaptionUsesTheOptionsHebrewTextAndFallsBackToEnglish()
+ {
+ LogAssert.ignoreFailingMessages = true;
+ var he = He;
+ var option = C.Events.First(e => e.Id == "maabarot_policy").Options.First(o => o.Id == "maabarot");
+ Assert.IsNotEmpty(option.TextHe, "precondition: the option has Hebrew text");
+ using (var r = new Rig(new[] { "maabarot_policy" }, text: he))
+ {
+ r.Order("maabarot_policy", "maabarot");
+ r.Bridge.EndTurn();
+ Assert.AreEqual(he.Format("outcome.order", option.TextHe), r.Outcomes.Caption);
+ StringAssert.DoesNotContain(option.Text, r.Outcomes.Caption, "no English in the Hebrew caption");
+ }
+ var c = ContentLoader.Load(Paths.Content);
+ c.Events.First(e => e.Id == "maabarot_policy").Options.First(o => o.Id == "maabarot").TextHe = "";
+ using (var r = new Rig(new[] { "maabarot_policy" }, text: he, content: c))
+ {
+ r.Order("maabarot_policy", "maabarot");
+ r.Bridge.EndTurn();
+ Assert.AreEqual(he.Format("outcome.order", option.Text), r.Outcomes.Caption, "no text_he: the English");
+ }
+ }
+
/// <summary>Scenario A of the review: a screen is open at End Turn. The clip closes it and is drawn over the screens
/// (it comes after them in the tree). Scenario B: something changes under it (bridge.Changed); the card re-renders,
/// but it has its own player, so the outcome clip plays on.</summary>