A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
End screen: show the end date and the population anchor's sources (Refs #2545) (#2715)
Berif75e51ea7eef
diff --git a/changelog.d/2545.md b/changelog.d/2545.mdnew file mode 100644index 000000000..61174e88e--- /dev/null+++ b/changelog.d/2545.md@@ -0,0 +1,2 @@+- The end screen gives the date the game ended on and, under the population, the sources of its CBS figure (R-END-005,+ R-END-006, #2545). Its Hebrew "Ended on" line is an agent draft awaiting a native read (#564).diff --git a/unity/Assets/Scripts/UI/EndScreenPresenter.cs b/unity/Assets/Scripts/UI/EndScreenPresenter.csindex 2f6d3ee4c..c007f6b8d 100644--- a/unity/Assets/Scripts/UI/EndScreenPresenter.cs+++ b/unity/Assets/Scripts/UI/EndScreenPresenter.cs@@ -77,10 +77,10 @@ namespace Statecraft.Game.UI/// <summary>True in the frame the screen closed (GameRoot's Escape poll, as TurnReportPresenter.ClosedThisFrame).</summary>public bool ClosedThisFrame => closedAt == UnityEngine.Time.frameCount;- /// <summary>The screen's lines for an ended game, in order: the outcome, its history note when it has one, the score,- /// the reference score, one per objective, each Deport card that never fired (its title, then its text), Social- /// cohesion, International Support, the population with its CBS anchor and, when some went home, the prisoners- /// returned. Every value is the report's.</summary>+ /// <summary>The screen's lines for an ended game, in order: the outcome, its history note when it has one, the end+ /// date, the score, the reference score, one per objective, each Deport card that never fired (its title, then its+ /// text), Social cohesion, International Support, the population with its CBS anchor, that anchor's sources and, when+ /// some went home, the prisoners returned. Every value is the report's.</summary>public static IReadOnlyList<(string Name, string Text)> Lines(Content c, GameState s, UiText t){var r = EndReport.For(c, s);@@ -103,6 +103,7 @@ namespace Statecraft.Game.UI// and only under that cause's own line, never under the generic one.var note = "end.note." + r.Outcome;if (t.Has(outcome) && t.Has(note)) lines.Add(("note", t[note]));+ lines.Add(("date", t.Format("end.date", Date(r.Date)))); // R-END-005 (#2545)lines.Add(("score", t.Format("hud.score", r.Score)));// Q-SCORE-2: beside the score, what a run on the historical dates scores (the sim's number; nothing computed here).if (r.ReferenceScore > 0) lines.Add(("score-reference", t.Format("end.reference_score", r.ReferenceScore)));@@ -131,6 +132,11 @@ namespace Statecraft.Game.UIlines.Add(("population", r.PopulationHistory is PopulationAnchor a? t.Format("end.population_history", People(r.Population), Date(a.Date), People(a.Jews)): t.Format("end.population", People(r.Population))));+ // R-END-006 (#2545): the anchor's sources, by host as the unit card gives its own (UnitCard, unit.sources). The loader+ // checks no population source, so a row with none (or no readable URL) gets no line rather than a bare "Sources:".+ var hosts = (r.PopulationHistory?.Sources ?? new List<Source>()).Select(x => Uri.TryCreate(x.Url, UriKind.Absolute, out var u) ? u.Host : "")+ .Where(h => h != "").Distinct(StringComparer.Ordinal).OrderBy(h => h, StringComparer.Ordinal).ToList();+ if (hosts.Count > 0) lines.Add(("population-sources", t.Format("unit.sources", string.Join(", ", hosts))));if (r.PrisonersReturned > 0) lines.Add(("prisoners", t.Format("defence.prisoners_returned", r.PrisonersReturned))); // Q-END-3; Defence's own stringreturn lines;}diff --git a/unity/Assets/Tests/EditMode/EndScreenTests.cs b/unity/Assets/Tests/EditMode/EndScreenTests.csindex bffa771a5..4800d9646 100644--- a/unity/Assets/Tests/EditMode/EndScreenTests.cs+++ b/unity/Assets/Tests/EditMode/EndScreenTests.cs@@ -247,10 +247,12 @@ public class EndScreenTestsAssert.IsTrue(k.End.IsOpen, "a loaded ended game opens on its end screen");var s = k.Bridge.State; var r = EndReport.For(C, s);var names = k.Ui.Q<ScrollView>("end-screen-rows").Children().Select(x => x.name).ToList();- var expected = new[] { "outcome", "score", "score-reference" }.Concat(r.Objectives.Select(o => "objective-" + o.Id))- .Concat(new[] { "cohesion", "standing", "population" }).Select(n => "end-screen-" + n);+ var expected = new[] { "outcome", "date", "score", "score-reference" }.Concat(r.Objectives.Select(o => "objective-" + o.Id))+ .Concat(new[] { "cohesion", "standing", "population", "population-sources" }).Select(n => "end-screen-" + n);CollectionAssert.AreEqual(expected, names, "the report's parts, in order");Assert.AreEqual(En["end.outcome.mvp_ended"], k.Line("outcome"));+ string Date(System.DateTime d) => En.Format("date.day_month_year", d.Day, En["date.month_" + d.Month], d.Year);+ Assert.AreEqual(En.Format("end.date", Date(r.Date)), k.Line("date"), "the end date (R-END-005, #2545)");Assert.AreEqual(En.Format("hud.score", s.Score), k.Line("score"));Assert.Greater(s.Score, 0);Assert.AreEqual(200, r.ReferenceScore, "the reference is the sim's number (Q-SCORE-2)");@@ -258,7 +260,6 @@ public class EndScreenTestsStringAssert.Contains("200", k.Line("score-reference"));// The first objective: the card's title, the player's date and the historical date (Q-END-1).var first = C.Objectives.Single(o => o.Id == "absorb_immigrants"); // by id: the first in id order, as before R-OBJ-007- string Date(System.DateTime d) => En.Format("date.day_month_year", d.Day, En["date.month_" + d.Month], d.Year);var title = EventSystem.Title(C, s, C.Events.First(e => e.Id == first.Card));Assert.AreEqual(En.Format("end.objective_done", title, Date(first.ReferenceDate.AddMonths(-1)), Date(first.ReferenceDate)), k.Line("objective-" + first.Id));foreach (var o in C.Objectives.Where(o => o.Id != first.Id))@@ -269,6 +270,26 @@ public class EndScreenTestsvar anchor = r.PopulationHistory!;Assert.AreEqual(En.Format("end.population_history", r.Population.ToString("N0", System.Globalization.CultureInfo.InvariantCulture),Date(anchor.Date), anchor.Jews.ToString("N0", System.Globalization.CultureInfo.InvariantCulture)), k.Line("population"));+ // ...and the anchor's sources (R-END-006, #2545), by host as the unit card gives its sources.+ Assert.AreEqual(En.Format("unit.sources", "www.cbs.gov.il"), k.Line("population-sources"));+ }++ /// <summary>#2545 (R-END-006): the sources row follows the anchor. A game that ends before the first anchor has no+ /// comparison and so no sources row, and an anchor with no readable source URL gets no bare "Sources:" row either.</summary>+ [Test]+ public void ThePopulationSourcesRowShowsOnlyAnAnchorsReadableSources()+ {+ using (var early = new Kit(En, s => { s.Date = C.PopulationAnchors.Min(a => a.Date).AddDays(-1); s.GameOver = GameOverCodes.DefeatEconomy; }))+ {+ Assert.IsNull(EndReport.For(C, early.Bridge.State).PopulationHistory, "precondition: before the first anchor");+ CollectionAssert.DoesNotContain(early.Ui.Q<ScrollView>("end-screen-rows").Children().Select(x => x.name), "end-screen-population-sources");+ }+ var unsourced = ContentLoader.Load(Paths.Content);+ foreach (var a in unsourced.PopulationAnchors) { a.Sources.Clear(); a.Sources.Add(new Source { Url = "" }); }+ using var k = new Kit(En, Ended);+ var names = EndScreenPresenter.Lines(unsourced, k.Bridge.State, En).Select(l => l.Name).ToList();+ Assert.IsNotNull(EndReport.For(unsourced, k.Bridge.State).PopulationHistory, "precondition: an anchor applies, so only its sources are dropped");+ CollectionAssert.DoesNotContain(names, "population-sources");}/// <summary>A cause's history note (Q-DEF-4 (b)) sits right under its line when the strings carry one, and nowhere else.@@ -279,7 +300,7 @@ public class EndScreenTestsvar withNote = UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings).text + "\nend.note.defeat_war: \"Fixture note.\"\n");using var k = new Kit(withNote, s => { s.Date = C.End; s.GameOver = GameOverCodes.DefeatWar; });var names = k.Ui.Q<ScrollView>("end-screen-rows").Children().Select(x => x.name).ToList();- CollectionAssert.AreEqual(new[] { "end-screen-outcome", "end-screen-note", "end-screen-score" }, names.Take(3), "the note follows the outcome line");+ CollectionAssert.AreEqual(new[] { "end-screen-outcome", "end-screen-note", "end-screen-date", "end-screen-score" }, names.Take(4), "the note follows the outcome line");Assert.AreEqual("Fixture note.", k.Line("note"));Assert.IsTrue(k.Ui.Q<Label>("end-screen-note").ClassListContains("end-screen-note"));using var ended = new Kit(withNote, Ended);@@ -296,7 +317,7 @@ public class EndScreenTests{using var k = new Kit(text, s => { s.Date = C.End; s.GameOver = GameOverCodes.DefeatWar; });var names = k.Ui.Q<ScrollView>("end-screen-rows").Children().Select(x => x.name).ToList();- CollectionAssert.AreEqual(new[] { "end-screen-outcome", "end-screen-score" }, names.Take(2), "the score follows the outcome line");+ CollectionAssert.AreEqual(new[] { "end-screen-outcome", "end-screen-date", "end-screen-score" }, names.Take(3), "the end date follows the outcome line, then the score");CollectionAssert.DoesNotContain(names, "end-screen-note");}}@@ -311,7 +332,7 @@ public class EndScreenTestsusing var k = new Kit(withNote, s => { s.Date = C.End; s.GameOver = GameOverCodes.CoalitionCollapse; });Assert.AreEqual(withNote["order.game_over"], k.Line("outcome"), "precondition: the generic line shows");var names = k.Ui.Q<ScrollView>("end-screen-rows").Children().Select(x => x.name).ToList();- CollectionAssert.AreEqual(new[] { "end-screen-outcome", "end-screen-score" }, names.Take(2), "the score follows the generic line");+ CollectionAssert.AreEqual(new[] { "end-screen-outcome", "end-screen-date", "end-screen-score" }, names.Take(3), "the end date follows the generic line, then the score");CollectionAssert.DoesNotContain(names, "end-screen-note");}@@ -461,6 +482,7 @@ public class EndScreenTestsAssert.AreEqual(He["report.close"], k.Ui.Q<Button>("end-screen-close").text);Assert.AreEqual(He["hud.new_game"], k.Ui.Q<Button>("end-screen-new-game").text);StringAssert.StartsWith(He["hud.caption.cohesion"] + ":", k.Line("cohesion"));+ Assert.AreEqual(He.Format("unit.sources", "www.cbs.gov.il"), k.Line("population-sources"));}/// <summary>#2060: in Hebrew each date an end-screen line inserts sits between RLE and PDF (U+202B, U+202C), so it@@ -486,6 +508,8 @@ public class EndScreenTestsAssert.IsTrue(string.Equals(openExpected, openLine, System.StringComparison.Ordinal), "expected\n" + Escape(openExpected) + "\nbut was\n" + Escape(openLine));var anchor = EndReport.For(C, k.Bridge.State).PopulationHistory!;Assert.GreaterOrEqual(k.Line("population").IndexOf(Date(anchor.Date), System.StringComparison.Ordinal), 0, "the population line's date too: " + Escape(k.Line("population")));+ var endDate = He.Format("end.date", Date(EndReport.For(C, k.Bridge.State).Date));+ Assert.IsTrue(string.Equals(endDate, k.Line("date"), System.StringComparison.Ordinal), "the end date too: expected\n" + Escape(endDate) + "\nbut was\n" + Escape(k.Line("date")));}/// <summary>The line with its invisible marks spelled out, for a failure message.</summary>diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yamlindex b53234d33..b99620c70 100644--- a/unity/Assets/UI/strings.en.yaml+++ b/unity/Assets/UI/strings.en.yaml@@ -538,6 +538,7 @@ end.objective_open: "{0}: not completed; historically {1}"end.parameter: "{0}: {1}"end.population: "Population: {0}"end.population_history: "Population: {0}; CBS, {1}: {2}"+end.date: "Ended on {0}"cabinet.coalition: "Coalition: {0} of {1} {3} · stability {2}"cabinet.vacant: "(vacant)"cabinet.person: "{0} · {1} · competence {2}, loyalty {3}"diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yamlindex ac1717065..ce7731b2d 100644--- a/unity/Assets/UI/strings.he.yaml+++ b/unity/Assets/UI/strings.he.yaml@@ -627,6 +627,9 @@ end.objective_open: "יעד {0}: לא הושלם; בהיסטוריה ב־{1}"end.parameter: "{0}: {1}"end.population: "אוכלוסייה: {0}"end.population_history: "אוכלוסייה: {0}; לפי הלמ״ס {2} ב־{1}"+# For the native reviewer (#564): the end screen's end date (#2545).+end.date: "הסתיים ב־{0}"+# For the native reviewer (#564)cabinet.coalition: "קואליציה: {0} מתוך {1} {3} · יציבות {2}"cabinet.vacant: "(פנוי)"