A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Prepare localized event-option effect previews (#1158)
Aviel Cohen7653b23374f0
diff --git a/changelog.d/1125-event-effects-preview.md b/changelog.d/1125-event-effects-preview.mdnew file mode 100644index 000000000..57e936974--- /dev/null+++ b/changelog.d/1125-event-effects-preview.md@@ -0,0 +1 @@+- Prepare localized event-option effect preview data and text formatting for the pending card integration (Refs #1125, #811).diff --git a/sim/Statecraft.Sim.Tests/OptionEffectPreviewTests.cs b/sim/Statecraft.Sim.Tests/OptionEffectPreviewTests.csnew file mode 100644index 000000000..44ed2abe8--- /dev/null+++ b/sim/Statecraft.Sim.Tests/OptionEffectPreviewTests.cs@@ -0,0 +1,168 @@+using System;+using System.Collections.Generic;+using System.Globalization;+using System.Linq;+using Statecraft.Sim;++/// <summary>R-EVT-005: presentation context decorates the existing preview without changing its effects or state.</summary>+public class OptionEffectPreviewTests+{+ static Content Content()+ {+ var model = Fixture.Files["model.yaml"]+ .Replace("indicators:\n", "indicators:\n - { id: halutz, base: 0.2, name: Test readiness }\n - { id: retired_test, base: 0, name: Retired test, to: 1948-05-15 }\n")+ .Replace("policies:\n", "policies:\n - { id: retired_policy, default: 0, office: finance_minister, name: Retired policy, to: 1948-05-15 }\n");+ return ContentLoader.Load(Fixture.Write(Fixture.Gdd(new Dictionary<string, string>+ {+ ["model.yaml"] = model,+ ["map/settlement_hexes.yaml"] = "settlements:\n - { id: town_a, q: 1, r: 0 }\n - { id: town_b, q: 2, r: 1 }\n",+ ["map/settlements_1948.yaml"] = Fixture.Files["map/settlements_1948.yaml"]+ + " - { id: town_b, name: Town B, lon: 34.42, lat: 33.28, type: town, founded: 1900, pre_modern: false }\n",+ ["cities.yaml"] = "cities:\n" + Fixture.City("town_a", 12, 8, 10, 6, "[military_camp, hakhshara]") + Fixture.City("town_b", 5, 2, 2, 1),+ }), new Dictionary<string, string>+ {+ ["preview_record.yaml"] = "id: preview_record\ntitle: Recorded {prime_minister}\ntext: A fictional fixture record.\nfrom: 1950-01-01\noptions:\n - { id: keep, text: Keep, historical: true }\n",+ }));+ }++ static EventOption EveryKind() => new EventOption+ {+ Id = "preview",+ Effects = new List<OptionEffect>+ {+ new OptionEffect { Target = "halutz", Delta = 0.041 },+ new OptionEffect { Target = "treasury", Delta = -1.25 },+ // Direct formatting contract: the existing helper rounds whole-stock display half away from zero.+ new OptionEffect { Target = "food", Delta = 2.5 },+ new OptionEffect { Target = "arms", Delta = -100 },+ new OptionEffect { Target = "retired_test", Delta = 1 },+ },+ GrantUnits = new List<UnitGrant>+ {+ new UnitGrant { Type = "halutz", N = 2 },+ new UnitGrant { Type = "halutz", N = 1, At = "town_b" },+ new UnitGrant { Type = "veteran_halutz", N = 3, At = "town_a" },+ },+ CityEffects = new List<CityEffect>+ {+ new CityEffect { City = "town_a", Field = "housing_capacity", Delta = 3 },+ new CityEffect { City = "town_a", Field = "job_slots", Delta = -100 },+ new CityEffect { City = "town_b", Field = "condition", Delta = 0.051 },+ },+ SetPolicy = new Dictionary<string, double> { ["rationing"] = 0.75, ["maabarot"] = 0.2, ["retired_policy"] = 0.9 },+ SetRung = 4,+ Rejoin = "preview_record",+ };++ // R-EVT-005: exact source order/values, duplicates and resolved destinations, without choosing the option.+ [Theory]+ [InlineData("en-US")]+ [InlineData("de-DE")]+ [InlineData("ar-SA")]+ public void ContextKeepsEveryHelperEntryAndItsSimFormattedAmount(string culture)+ {+ var previous = CultureInfo.CurrentCulture;+ try+ {+ CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo(culture);+ var c = Content();+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ var option = EveryKind();+ var hash = s.Hash();+ var source = EventSystem.OptionEffects(c, s, option);+ var rows = EventSystem.OptionEffectPreviews(c, s, option);+ Assert.Equal(14, rows.Count);+ Assert.Equal(source.Select(x => (x.System, x.Target, x.Delta, x.Message)),+ rows.Select(x => (x.Cause.System, x.Cause.Target, x.Cause.Delta, x.Cause.Message)));+ Assert.Equal(new[] { "halutz", "treasury", "food", "arms", "halutz", "halutz", "veteran_halutz", "town_a.housing_capacity", "town_a.job_slots", "town_b.condition", "maabarot", "rationing", "rung", "rejoin" },+ rows.Select(x => x.Cause.Target));+ Assert.Equal(new[] { "+4.1%", "IL -1.3m", "+3", "-100", "2", "1", "3", "+3", "-100", "+5.1%", "20%", "75%", "4", "" },+ rows.Select(x => x.Amount));+ Assert.Equal(new[] { "halutz", "treasury", "food", "arms", "town_a", "town_b", "town_a", "town_a", "town_a", "town_b", "maabarot", "rationing", "", "preview_record" },+ rows.Select(x => x.ContextId));+ Assert.Equal(new[] { "Test readiness", "Treasury", "Food", "Arms", "Town A", "Town B", "Town A", "Town A", "Town A", "Town B", "Transit camps", "Rationing", "", "Recorded Pm One" },+ rows.Select(x => x.ContextName));+ Assert.Equal("housing_capacity", rows[7].Field);+ Assert.Equal("job_slots", rows[8].Field);+ Assert.Equal("condition", rows[9].Field);+ Assert.Equal(hash, s.Hash());+ }+ finally { CultureInfo.CurrentCulture = previous; }+ }++ // A type and indicator may have the same id; neither category nor destination is guessed in Unity from that id.+ [Fact]+ public void TheSimDistinguishesAnIndicatorFromARepeatedGrantOfTheSameId()+ {+ var c = Content();+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ var rows = EventSystem.OptionEffectPreviews(c, s, EveryKind());+ Assert.Equal(rows[0].Cause.Target, rows[4].Cause.Target);+ Assert.Equal(OptionEffectPreviewKind.Amount, rows[0].Kind);+ Assert.Equal(OptionEffectPreviewKind.UnitGrant, rows[4].Kind);+ Assert.Equal(OptionEffectPreviewKind.UnitGrant, rows[5].Kind);+ Assert.Equal(("town_a", "town_b"), (rows[4].ContextId, rows[5].ContextId));+ Assert.Equal(OptionEffectPreviewKind.Stock, rows[2].Kind);+ Assert.Equal(OptionEffectPreviewKind.City, rows[7].Kind);+ Assert.Equal(OptionEffectPreviewKind.SetPolicy, rows[10].Kind);+ Assert.Equal(OptionEffectPreviewKind.SetRung, rows[12].Kind);+ Assert.Equal(OptionEffectPreviewKind.Rejoin, rows[13].Kind);+ }++ // One walk builds both lists (#1158 review): each row's own message carries the name and the amount it was built with,+ // for every option in the shipped content and for every kind the fixture can express, a project unlock included.+ [Fact]+ public void EveryRowAgreesWithItsOwnEffectInTheShippedContentAndTheFixture()+ {+ var real = ContentLoader.Load(RealContentTests.ContentRoot());+ var fixture = ContentLoader.Load(Fixture.Write(Fixture.Gdd(new Dictionary<string, string>+ {+ ["projects.yaml"] = Fixture.GddProjects.Replace("job_slots: 3 }", "job_slots: 3, locked: true }"),+ })));+ var unlock = new EventOption { UnlockProjects = new List<string> { "industry" } };+ var cases = new List<(Content c, EventOption o)>(real.Events.SelectMany(e => e.Options).Select(o => (real, o)))+ {+ (fixture, unlock), (Content(), EveryKind()),+ };+ Assert.Contains(cases, x => x.o.Effects.Count > 0);+ var checkedRows = 0;+ foreach (var (c, o) in cases)+ {+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ var effects = EventSystem.OptionEffects(c, s, o);+ var rows = EventSystem.OptionEffectPreviews(c, s, o);+ Assert.Equal(effects.Select(x => (x.System, x.Target, x.Delta, x.Message)),+ rows.Select(x => (x.Cause.System, x.Cause.Target, x.Cause.Delta, x.Cause.Message)));+ foreach (var r in rows)+ {+ Assert.Contains(r.Amount, r.Cause.Message);+ Assert.Contains(r.ContextName, r.Cause.Message);+ checkedRows++;+ }+ }+ Assert.True(checkedRows > cases.Count, $"only {checkedRows} rows over {cases.Count} options");++ var row = Assert.Single(EventSystem.OptionEffectPreviews(fixture, Simulation.NewGame(fixture, 1, Mode.Historical), unlock));+ Assert.Equal((OptionEffectPreviewKind.ProjectUnlock, "industry", "An industry project", ""), (row.Kind, row.ContextId, row.ContextName, row.Amount));+ Assert.Equal("An industry project can now be built", row.Cause.Message);+ }++ [Fact]+ public void AnEmptyOptionHasNoInventedEffects()+ {+ var c = Content();+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ Assert.Empty(EventSystem.OptionEffectPreviews(c, s, new EventOption()));+ }++ [Fact]+ public void CallersCannotReorderThePreview()+ {+ var c = Content();+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ var rows = EventSystem.OptionEffectPreviews(c, s, EveryKind());+ var list = Assert.IsAssignableFrom<IList<OptionEffectPreview>>(rows);+ Assert.True(list.IsReadOnly);+ Assert.Throws<NotSupportedException>(() => list.RemoveAt(0));+ }+}diff --git a/sim/Statecraft.Sim/EventSystem.cs b/sim/Statecraft.Sim/EventSystem.csindex 503fbb47d..dbcc429f9 100644--- a/sim/Statecraft.Sim/EventSystem.cs+++ b/sim/Statecraft.Sim/EventSystem.cs@@ -163,11 +163,14 @@ namespace Statecraft.Sim/// hex of the one city with the military camp (the loader checks each exists).</summary>static (string Name, int Q, int R) GrantPlace(Content c, UnitGrant g){- var city = g.At != "" ? g.At : c.Cities.Single(x => x.Facilities.Contains(MilitaryCamp)).Id;+ var city = GrantCity(c, g);var hex = c.SettlementHexes.First(h => h.Id == city); // every settlement has one (ValidateMap)return (PlayerText.Settlement(c, city), hex.Q, hex.R);}+ static string GrantCity(Content c, UnitGrant g) =>+ g.At != "" ? g.At : c.Cities.Single(x => x.Facilities.Contains(MilitaryCamp)).Id;+static string Granted(UnitGrant g, string place) =>FormattableString.Invariant($"{g.N} {g.Type} unit{(g.N == 1 ? "" : "s")} at {place}");@@ -180,23 +183,69 @@ namespace Statecraft.Sim: FormattableString.Invariant($"{PlayerText.Settlement(c, city)}: {field.Replace('_', ' ')} {(delta > 0 ? "+" : "")}{delta}");/// <summary>R-EVT-005: every effect of an option, in the order choosing it applies them (Resolve): the numeric- /// effects, the unit grants and city effects (R-EFX-006), the policies it sets (by id), the security level, then rejoin.- /// Each amount is the option's own; Resolve may apply less where an indicator meets its bound or the Food or Arms stock its floor, and rounds both to whole units. The- /// event card will read this list (Q-EVT-4, owner 17 October 2026; Phase 7 PR 8), so no number is computed in Unity.</summary>- public static List<Cause> OptionEffects(Content c, GameState s, EventOption o)+ /// effects, the unit grants, city effects and project unlocks (R-EFX-006), the policies it sets (by id), the security+ /// level, then rejoin. Each amount is the option's own; Resolve may apply less where an indicator meets its bound or+ /// the Food or Arms stock its floor, and rounds both to whole units. The event card will read this list (Q-EVT-4,+ /// owner 17 October 2026; Phase 7 PR 8), so no number is computed in Unity.</summary>+ public static List<Cause> OptionEffects(Content c, GameState s, EventOption o) =>+ OptionEffectRows(c, s, o).Select(r => r.Cause).ToList();++ /// <summary>R-EVT-005: the same entries as <see cref="OptionEffects"/>, in the same order, each with read-only+ /// presentation context: its category, the place or row it names and its amount already formatted by the sim. A+ /// localized UI supplies nouns, not game rules. Both come from one walk of the option's effects, so they cannot drift.</summary>+ public static IReadOnlyList<OptionEffectPreview> OptionEffectPreviews(Content c, GameState s, EventOption o) =>+ OptionEffectRows(c, s, o).AsReadOnly();++ static List<OptionEffectPreview> OptionEffectRows(Content c, GameState s, EventOption o){- var lines = o.Effects.Where(fx => Reaches(s, fx.Target))- .Select(fx => new Cause("events", fx.Target, fx.Delta, PlayerText.Change(c, fx.Target, fx.Delta))).ToList();- lines.AddRange(o.GrantUnits.Select(g => new Cause("events", g.Type, g.N, Granted(g, GrantPlace(c, g).Name))));- lines.AddRange(o.CityEffects.Select(x => new Cause("events", x.City + "." + x.Field, x.Delta, CityChange(c, x.City, x.Field, x.Delta))));- lines.AddRange(o.UnlockProjects.Select(k => new Cause("events", k, 1, Unlocked(c, k))));- lines.AddRange(o.SetPolicy.Where(k => s.Policies.ContainsKey(k.Key)).OrderBy(k => k.Key, StringComparer.Ordinal)- .Select(k => new Cause("events", k.Key, k.Value, $"{PlayerText.Target(c, k.Key)} set to {PlayerText.Percent(k.Value)}")));- if (o.SetRung.HasValue) lines.Add(new Cause("events", "rung", o.SetRung.Value, FormattableString.Invariant($"Security level set to {o.SetRung.Value}")));+ var rows = new List<OptionEffectPreview>();+ void Add(OptionEffectPreviewKind kind, string target, double delta, string message, string contextId, string contextName,+ string amount, string field = "") =>+ rows.Add(new OptionEffectPreview(new Cause("events", target, delta, message), kind, contextId, contextName, amount, field));++ foreach (var fx in o.Effects.Where(fx => Reaches(s, fx.Target)))+ {+ var stock = fx.Target == Pools.FoodTarget || fx.Target == Pools.ArmsTarget;+ var name = stock ? (fx.Target == Pools.FoodTarget ? "Food" : "Arms") : PlayerText.Target(c, fx.Target);+ var amount = stock ? PlayerText.UnitsChangeNumber(fx.Delta)+ : PlayerText.IsMoney(c, fx.Target) ? PlayerText.MoneyChange(c, fx.Target, fx.Delta) : PlayerText.PercentChange(fx.Delta);+ Add(stock ? OptionEffectPreviewKind.Stock : OptionEffectPreviewKind.Amount, fx.Target, fx.Delta,+ PlayerText.Change(c, fx.Target, fx.Delta), fx.Target, name, amount);+ }+ foreach (var g in o.GrantUnits)+ {+ var place = GrantPlace(c, g).Name;+ Add(OptionEffectPreviewKind.UnitGrant, g.Type, g.N, Granted(g, place), GrantCity(c, g), place,+ FormattableString.Invariant($"{g.N}"));+ }+ foreach (var x in o.CityEffects)+ {+ var amount = x.Field == ConditionField ? PlayerText.PercentChange(x.Delta)+ : FormattableString.Invariant($"{(x.Delta > 0 ? "+" : "")}{x.Delta}");+ Add(OptionEffectPreviewKind.City, x.City + "." + x.Field, x.Delta, CityChange(c, x.City, x.Field, x.Delta),+ x.City, PlayerText.Settlement(c, x.City), amount, x.Field);+ }+ foreach (var k in o.UnlockProjects)+ Add(OptionEffectPreviewKind.ProjectUnlock, k, 1, Unlocked(c, k), k,+ PlayerText.Capitalised(c.ProjectKinds.First(x => x.Id == k).Name), "");+ foreach (var kv in o.SetPolicy.Where(k => s.Policies.ContainsKey(k.Key)).OrderBy(k => k.Key, StringComparer.Ordinal))+ {+ var name = PlayerText.Target(c, kv.Key);+ var amount = PlayerText.Percent(kv.Value);+ Add(OptionEffectPreviewKind.SetPolicy, kv.Key, kv.Value, $"{name} set to {amount}", kv.Key, name, amount);+ }+ if (o.SetRung is int rung)+ {+ var amount = FormattableString.Invariant($"{rung}");+ Add(OptionEffectPreviewKind.SetRung, "rung", rung, $"Security level set to {amount}", "", "", amount);+ }// R-ALT-009: the way back to the record is shown with the other effects (R-EVT-005).if (o.Rejoin != "")- lines.Add(new Cause("events", "rejoin", 0, $"Returns to the recorded course: {Cabinet.Fill(c, s, c.Events.First(x => x.Id == o.Rejoin).Title, s.Date)}"));- return lines;+ {+ var title = Cabinet.Fill(c, s, c.Events.First(x => x.Id == o.Rejoin).Title, s.Date);+ Add(OptionEffectPreviewKind.Rejoin, "rejoin", 0, $"Returns to the recorded course: {title}", o.Rejoin, title, "");+ }+ return rows;}/// <summary>The minister <see cref="Delegate"/> hands the event to in this state: its office's holder today, or nulldiff --git a/sim/Statecraft.Sim/OptionEffectPreview.cs b/sim/Statecraft.Sim/OptionEffectPreview.csnew file mode 100644index 000000000..c1fa919f5--- /dev/null+++ b/sim/Statecraft.Sim/OptionEffectPreview.cs@@ -0,0 +1,22 @@+namespace Statecraft.Sim+{+ /// <summary>Presentation categories of the effects the existing option helper returns; no additional rules.</summary>+ public enum OptionEffectPreviewKind { Amount, Stock, UnitGrant, City, ProjectUnlock, SetPolicy, SetRung, Rejoin }++ /// <summary>Read-only presentation context for an actual OptionEffects entry. Amount is already formatted by the sim.</summary>+ public sealed class OptionEffectPreview+ {+ public Cause Cause { get; }+ public OptionEffectPreviewKind Kind { get; }+ public string ContextId { get; }+ public string ContextName { get; }+ public string Field { get; }+ public string Amount { get; }++ internal OptionEffectPreview(Cause cause, OptionEffectPreviewKind kind, string contextId, string contextName,+ string amount, string field = "")+ {+ Cause = cause; Kind = kind; ContextId = contextId; ContextName = contextName; Amount = amount; Field = field;+ }+ }+}diff --git a/sim/Statecraft.Sim/PlayerText.cs b/sim/Statecraft.Sim/PlayerText.csindex e332fa6c4..8feeda521 100644--- a/sim/Statecraft.Sim/PlayerText.cs+++ b/sim/Statecraft.Sim/PlayerText.cs@@ -125,10 +125,13 @@ namespace Statecraft.Sim}/// <summary>"+5 units" for a change to a whole-unit national stock (the Food and Arms pools; R-EFX-001).</summary>- public static string UnitsChange(double change)+ public static string UnitsChange(double change) => UnitsChangeNumber(change) + " units";++ /// <summary>The same signed, rounded whole-stock number without an English noun, for localized UI templates.</summary>+ public static string UnitsChangeNumber(double change){var r = Math.Round(Finite(change, nameof(change)), 0, MidpointRounding.AwayFromZero);- return Signed(r, "", Fixed(Math.Abs(r), 0) + " units", signed: true);+ return Signed(r, "", Fixed(Math.Abs(r), 0), signed: true);}/// <summary>"Morale +4.1%" or "Treasury IL -2.0m": the name and the change, in the target's unit.</summary>diff --git a/unity/Assets/Scripts/UI/EventEffectText.cs b/unity/Assets/Scripts/UI/EventEffectText.csnew file mode 100644index 000000000..78ba3ace8--- /dev/null+++ b/unity/Assets/Scripts/UI/EventEffectText.cs@@ -0,0 +1,59 @@+#nullable enable+using System;+using Statecraft.Sim;++namespace Statecraft.Game.UI+{+ /// <summary>Localized words around the sim's already formatted option-effect amounts. Not yet wired to the card.</summary>+ public static class EventEffectText+ {+ /// <param name="contextName">Optional localized indicator, money, city, project kind, policy or event name from the caller.+ /// Empty or null uses the sim's English data name. Current model/city rows have no Hebrew name field.</param>+ public static string Format(OptionEffectPreview row, UiText text, string? contextName = null)+ {+ var name = string.IsNullOrEmpty(contextName) ? row.ContextName : contextName;+ switch (row.Kind)+ {+ case OptionEffectPreviewKind.Amount:+ return text.Format("event.effect.amount", name, row.Amount);+ case OptionEffectPreviewKind.Stock:+ if (string.IsNullOrEmpty(contextName))+ name = text[row.Cause.Target switch+ {+ Pools.FoodTarget => "event.effect.food",+ Pools.ArmsTarget => "event.effect.arms",+ _ => throw new ArgumentOutOfRangeException(nameof(row), "Unknown stock presentation label"),+ }];+ return text.Format("event.effect.stock", name, row.Amount);+ case OptionEffectPreviewKind.UnitGrant:+ var role = text[row.Cause.Target switch+ {+ "halutz" => "city.track_halutz",+ "recruit" => "city.track_recruit",+ "veteran_halutz" => "event.effect.veteran_halutz",+ _ => "event.effect.units", // UnitType has no display name; never expose an unknown internal id.+ }];+ return text.Format("event.effect.grant", role, row.Amount, name);+ case OptionEffectPreviewKind.City:+ var field = text[row.Field switch+ {+ EventSystem.HousingField => "event.effect.housing_capacity",+ EventSystem.JobsField => "event.effect.job_slots",+ EventSystem.ConditionField => "event.effect.condition",+ _ => throw new ArgumentOutOfRangeException(nameof(row), "Unknown city-field presentation label"),+ }];+ return text.Format("event.effect.city", name, field, row.Amount);+ case OptionEffectPreviewKind.ProjectUnlock:+ return text.Format("event.effect.unlock", name);+ case OptionEffectPreviewKind.SetPolicy:+ return text.Format("event.effect.policy", name, row.Amount);+ case OptionEffectPreviewKind.SetRung:+ return text.Format("event.effect.rung", row.Amount);+ case OptionEffectPreviewKind.Rejoin:+ return text.Format("event.effect.rejoin", name);+ default:+ throw new ArgumentOutOfRangeException(nameof(row), "Unknown effect presentation category");+ }+ }+ }+}diff --git a/unity/Assets/Scripts/UI/EventEffectText.cs.meta b/unity/Assets/Scripts/UI/EventEffectText.cs.metanew file mode 100644index 000000000..249a17572--- /dev/null+++ b/unity/Assets/Scripts/UI/EventEffectText.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: ccac4be1dbb346b7952ed01f51145e51diff --git a/unity/Assets/Tests/EditMode/EventEffectTextTests.cs b/unity/Assets/Tests/EditMode/EventEffectTextTests.csnew file mode 100644index 000000000..ae95992af--- /dev/null+++ b/unity/Assets/Tests/EditMode/EventEffectTextTests.cs@@ -0,0 +1,144 @@+#nullable enable+using System;+using System.Collections.Generic;+using System.Globalization;+using System.Linq;+using NUnit.Framework;+using Statecraft.Game;+using Statecraft.Game.UI;+using Statecraft.Sim;+using UnityEditor;+using UnityEngine;++/// <summary>R-EVT-005: independent formatter tests; production card integration and its layout/focus gates follow #1091/#1105.</summary>+public class EventEffectTextTests+{+ static readonly Content C = ContentLoader.Load(Paths.Content);+ static UiText Text(bool hebrew) => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(+ hebrew ? UiPaths.StringsHebrew : UiPaths.Strings).text);+ static string Plain(string value) => value.Replace(UiText.LeftToRightMark.ToString(), "");+ static readonly string City = C.Cities.First().Id;+ static readonly string Place = PlayerText.Settlement(C, City);+ static readonly string Rejoin = C.Events.First().Id;++ // Direct helper inputs exercise current presentation categories, not new authored content or grant rules.+ static EventOption Option() => new EventOption+ {+ Effects = new List<OptionEffect>+ {+ new OptionEffect { Target = "morale", Delta = .041 },+ new OptionEffect { Target = "treasury", Delta = -1.25 },+ new OptionEffect { Target = "food", Delta = 2.5 },+ new OptionEffect { Target = "arms", Delta = -100 },+ },+ GrantUnits = new List<UnitGrant>+ {+ new UnitGrant { Type = "halutz", N = 2, At = City },+ new UnitGrant { Type = "recruit", N = 1, At = City },+ new UnitGrant { Type = "veteran_halutz", N = 3, At = City },+ new UnitGrant { Type = "untranslated_role_internal_id", N = 4, At = City },+ },+ CityEffects = new List<CityEffect>+ {+ new CityEffect { City = City, Field = EventSystem.HousingField, Delta = 3 },+ new CityEffect { City = City, Field = EventSystem.JobsField, Delta = -100 },+ new CityEffect { City = City, Field = EventSystem.ConditionField, Delta = .051 },+ },+ SetPolicy = new Dictionary<string, double> { ["rationing"] = .75 }, SetRung = 4, Rejoin = Rejoin,+ };++ [TestCase(false, "en-US")]+ [TestCase(false, "de-DE")]+ [TestCase(false, "ar-SA")]+ [TestCase(true, "en-US")]+ [TestCase(true, "de-DE")]+ [TestCase(true, "ar-SA")]+ public void EveryExistingCategoryReadsTheSimAmountsInEitherLanguage(bool hebrew, string culture)+ {+ var previous = CultureInfo.CurrentCulture;+ try+ {+ CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo(culture);+ var s = Simulation.NewGame(C, GoldenRun.Seed, Mode.Historical);+ var hash = s.Hash();+ var option = Option();+ var causes = EventSystem.OptionEffects(C, s, option);+ var rows = EventSystem.OptionEffectPreviews(C, s, option);+ Assert.AreEqual(causes.Select(x => (x.System, x.Target, x.Delta, x.Message)),+ rows.Select(x => (x.Cause.System, x.Cause.Target, x.Cause.Delta, x.Cause.Message)));+ var actual = rows.Select(x => Plain(EventEffectText.Format(x, Text(hebrew)))).ToArray();+ var title = Cabinet.Fill(C, s, C.Events.First(x => x.Id == Rejoin).Title, s.Date);+ // English data names are deliberate fallbacks: current indicator/city/policy rows have no Hebrew field.+ var expected = hebrew ? new[]+ {+ "Social cohesion: שינוי +4.1%", "Money: שינוי IL -1.3m", "מזון +3 יחידות", "נשק -100 יחידות",+ "חלוצים: 2, מיקום: " + Place, "מגויסים: 1, מיקום: " + Place,+ "חלוצים ותיקים: 3, מיקום: " + Place, "יחידות: 4, מיקום: " + Place,+ Place + ": קיבולת דיור, שינוי +3", Place + ": מקומות עבודה, שינוי -100", Place + ": מצב הדיור, שינוי +5.1%",+ "Rationing: ערך חדש 75%", "רמת הביטחון תיקבע ל־4", "חזרה למסלול ההיסטורי: " + title,+ } : new[]+ {+ "Social cohesion +4.1%", "Money IL -1.3m", "Food +3 units", "Arms -100 units",+ "Halutzim: 2 at " + Place, "Recruits: 1 at " + Place,+ "Veteran Halutzim: 3 at " + Place, "Units: 4 at " + Place,+ Place + ": housing capacity +3", Place + ": job slots -100", Place + ": housing condition +5.1%",+ "Rationing set to 75%", "Security level set to 4", "Returns to the recorded course: " + title,+ };+ CollectionAssert.AreEqual(expected, actual);+ Assert.AreEqual(hash, s.Hash(), "formatting must not choose, spend, queue or mutate state");+ StringAssert.DoesNotContain("untranslated_role_internal_id", string.Join(" / ", actual));+ }+ finally { CultureInfo.CurrentCulture = previous; }+ }++ [TestCase(0, "לכידות", "לכידות: שינוי +4.1%")]+ [TestCase(4, "עיר לדוגמה", "חלוצים: 2, מיקום: עיר לדוגמה")]+ [TestCase(8, "עיר לדוגמה", "עיר לדוגמה: קיבולת דיור, שינוי +3")]+ [TestCase(11, "קיצוב", "קיצוב: ערך חדש 75%")]+ [TestCase(13, "כותרת מתורגמת", "חזרה למסלול ההיסטורי: כותרת מתורגמת")]+ public void TheCallerMaySupplyALocalizedNameWithoutChangingTheSim(int index, string name, string expected)+ {+ var s = Simulation.NewGame(C, GoldenRun.Seed, Mode.Historical);+ var row = EventSystem.OptionEffectPreviews(C, s, Option())[index];+ var original = (row.ContextName, row.Amount, row.Cause.Message);+ Assert.AreEqual(expected, Plain(EventEffectText.Format(row, Text(true), name)));+ Assert.AreEqual(original, (row.ContextName, row.Amount, row.Cause.Message), "formatting preserves the sim context");+ Assert.AreEqual(EventEffectText.Format(row, Text(false)), EventEffectText.Format(row, Text(false), ""));+ }++ [Test]+ public void HebrewTemplatesKeepTheSignedAmountTogetherUsingTheExistingBidiFormatter()+ {+ var s = Simulation.NewGame(C, GoldenRun.Seed, Mode.Historical);+ var rows = EventSystem.OptionEffectPreviews(C, s, Option());+ var mark = UiText.LeftToRightMark.ToString();+ StringAssert.Contains(mark + "-100" + mark, EventEffectText.Format(rows[3], Text(true)));+ StringAssert.Contains(mark + "+5.1%" + mark, EventEffectText.Format(rows[10], Text(true)));+ StringAssert.Contains(mark + "IL -1.3m" + mark, EventEffectText.Format(rows[1], Text(true), "אוצר"));+ }++ // A project unlock (R-EFX-008) is one of the helper's entries too, so it has a template; the Hebrew kind name comes+ // from the caller (ContentNames.Of), as the other content names do.+ [TestCase(false, null, "{0} can now be built")]+ [TestCase(true, null, "אפשר לבנות עכשיו: {0}")]+ [TestCase(true, "שיכון", "אפשר לבנות עכשיו: שיכון")]+ public void AProjectUnlockReadsInEitherLanguage(bool hebrew, string? name, string expected)+ {+ var s = Simulation.NewGame(C, GoldenRun.Seed, Mode.Historical);+ var kind = C.ProjectKinds.First();+ var row = EventSystem.OptionEffectPreviews(C, s, new EventOption { UnlockProjects = new List<string> { kind.Id } }).Single();+ Assert.AreEqual(OptionEffectPreviewKind.ProjectUnlock, row.Kind);+ Assert.AreEqual(string.Format(expected, PlayerText.Capitalised(kind.Name)), Plain(EventEffectText.Format(row, Text(hebrew), name)));+ if (!hebrew) Assert.AreEqual(row.Cause.Message, Plain(EventEffectText.Format(row, Text(false))));+ }++ [Test]+ public void AnUnrecognizedCityFieldFailsInsteadOfLeakingItsInternalId()+ {+ var s = Simulation.NewGame(C, GoldenRun.Seed, Mode.Historical);+ var option = new EventOption { CityEffects = new List<CityEffect>+ { new CityEffect { City = City, Field = "unsupported_internal_field", Delta = 1 } } };+ var row = EventSystem.OptionEffectPreviews(C, s, option).Single();+ Assert.Throws<ArgumentOutOfRangeException>(() => EventEffectText.Format(row, Text(false)));+ }+}diff --git a/unity/Assets/Tests/EditMode/EventEffectTextTests.cs.meta b/unity/Assets/Tests/EditMode/EventEffectTextTests.cs.metanew file mode 100644index 000000000..791405014--- /dev/null+++ b/unity/Assets/Tests/EditMode/EventEffectTextTests.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 99a0009c474d4899bf755d49f4447e47diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yamlindex 3dc89d090..1c42f2486 100644--- a/unity/Assets/UI/strings.en.yaml+++ b/unity/Assets/UI/strings.en.yaml@@ -556,3 +556,20 @@ nav.timeline: "Timeline"timeline.alt_proposed: "Not adopted. Proposed by {0}, {1}."timeline.alt_debated: "Not adopted. Debated by {0}, {1}."timeline.alt_design: "Design assumption."++# #1125 independent option-effect formatter; no production card hookup yet.+event.effect.amount: "{0} {1}"+event.effect.stock: "{0} {1} units"+event.effect.grant: "{0}: {1} at {2}"+event.effect.city: "{0}: {1} {2}"+event.effect.policy: "{0} set to {1}"+event.effect.rung: "Security level set to {0}"+event.effect.rejoin: "Returns to the recorded course: {0}"+event.effect.unlock: "{0} can now be built"+event.effect.food: "Food"+event.effect.arms: "Arms"+event.effect.units: "Units"+event.effect.veteran_halutz: "Veteran Halutzim"+event.effect.housing_capacity: "housing capacity"+event.effect.job_slots: "job slots"+event.effect.condition: "housing condition"diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yamlindex 10f3ed969..425054982 100644--- a/unity/Assets/UI/strings.he.yaml+++ b/unity/Assets/UI/strings.he.yaml@@ -599,3 +599,21 @@ nav.timeline: "ציר הזמן"timeline.alt_proposed: "לא אומץ. הוצע בידי {0}, {1}."timeline.alt_debated: "לא אומץ. נדון בידי {0}, {1}."timeline.alt_design: "הנחת תכנון."++# #1125 independent option-effect formatter; no production card hookup yet.+# Agent-checked draft wording only; native-speaker review remains pending (#564).+event.effect.amount: "{0}: שינוי {1}"+event.effect.stock: "{0} {1} יחידות"+event.effect.grant: "{0}: {1}, מיקום: {2}"+event.effect.city: "{0}: {1}, שינוי {2}"+event.effect.policy: "{0}: ערך חדש {1}"+event.effect.rung: "רמת הביטחון תיקבע ל־{0}"+event.effect.rejoin: "חזרה למסלול ההיסטורי: {0}"+event.effect.unlock: "אפשר לבנות עכשיו: {0}"+event.effect.food: "מזון"+event.effect.arms: "נשק"+event.effect.units: "יחידות"+event.effect.veteran_halutz: "חלוצים ותיקים"+event.effect.housing_capacity: "קיבולת דיור"+event.effect.job_slots: "מקומות עבודה"+event.effect.condition: "מצב הדיור"