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.

Start screen: save notices survive a language switch, in the new language; delete_failed says when it is replaced (Fixes #2552) (#2582)

Eyal Golan3d404dcec034
diff --git a/changelog.d/2552-save-notices-language.md b/changelog.d/2552-save-notices-language.md
new file mode 100644
index 000000000..3495a265c
--- /dev/null
+++ b/changelog.d/2552-save-notices-language.md
@@ -0,0 +1,3 @@
+### Fixed
+
+- Save notices remain visible in the selected language when the start screen's language changes.
diff --git a/docs/WRITING_UI.md b/docs/WRITING_UI.md
index 609df5912..1bd072049 100644
--- a/docs/WRITING_UI.md
+++ b/docs/WRITING_UI.md
@@ -75,7 +75,7 @@ Check: a pattern search over the strings files.
### UI-05 A refusal says what, why and what next
Status: proposed (observed in the save and start-up strings). Reason: NN/g and GOV.UK agree that an error message should name the specific problem and say how to fix it. Neither requires a separate "why", but in a game the reason is a rule the player can act on, so it is kept. Where nothing can be done, say what happens instead.
-- Good: "The old saved game could not be removed; it will be replaced after your next turn." (`newgame.delete_failed`): what happened and what happens next.
+- Good: "The old saved game could not be removed; it will be replaced the next time the game saves." (`newgame.delete_failed`): what happened and what happens next.
- Good: "Statecraft could not start: {0}. Reload the page." (`boot.failed`): what happened and what to do.
- Good: "Your saved game could not be loaded ({0}). A new game has started." (`save.unreadable`).
- Mixed: "Not enough attention (need {0:0.0}, have {1:0.0})" (`order.no_attention`) gives the rule and the numbers but no next step. It is also shown after "Not done: " (`toast.refused`), so the player reads "Not done: Not enough attention (...)".
@@ -167,7 +167,7 @@ Check: manual.
| Key | String | Verdict | Rule |
|---|---|---|---|
-| `newgame.delete_failed` | The old saved game could not be removed; it will be replaced after your next turn. | Good | UI-05 |
+| `newgame.delete_failed` | The old saved game could not be removed; it will be replaced the next time the game saves. | Good | UI-05 |
| `boot.failed` | Statecraft could not start: {0}. Reload the page. | Good (the `{0}` is the fixed `boot.reason_other`, #705) | UI-05, UI-07 |
| `save.reason_other` | the file could not be read or replayed | Good, a fixed player reason | UI-07 |
| `why.empty` | Nothing has happened yet: end the turn to see its causes. | Good, empty state with a next step | UI-10 |
diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.cs
index d74eb18e2..599d5577b 100644
--- a/unity/Assets/Scripts/UI/GameRoot.cs
+++ b/unity/Assets/Scripts/UI/GameRoot.cs
@@ -86,6 +86,11 @@ namespace Statecraft.Game.UI
bool endClosed;
/// <summary>Set by SwitchLanguage for its Begin (#2054): whether the start screen it rebuilds offered Continue.</summary>
bool keptResumed = true;
+ /// <summary>The save notices of <see cref="saveNoticeSession"/>, the session Begin last started, as language-independent
+ /// keys, so a language switch can say them again in the new language (#2552). A New game replaces the bridge's session
+ /// without Begin, so the keys are said only while the kept session is still the one that raised them.</summary>
+ readonly List<string> saveNoticeKeys = new List<string>();
+ GameSession? saveNoticeSession;
AdvisorPresenter? advisor;
CabinetPresenter? cabinet;
EncyclopediaPresenter? encyclopedia;
@@ -255,7 +260,7 @@ namespace Statecraft.Game.UI
/// (with <paramref name="smokeOrders"/>, the smoke-orders run's one turn instead);
/// <paramref name="startScreen"/> shows the start screen first (never in a smoke run, which has no New Game).
/// <paramref name="keep"/> (Settings' language switch) goes on with that bridge's game and its queued orders instead
- /// of loading the autosave.</summary>
+ /// of loading the autosave; when rebuilding the start screen, its save notices are rendered in the new language.</summary>
internal void Begin(GameInputs inputs, int smoke, bool startScreen = false, SimBridge? keep = null, bool smokeOrders = false)
{
if (inputs == null) throw new ArgumentNullException(nameof(inputs));
@@ -273,13 +278,19 @@ namespace Statecraft.Game.UI
var text = Strings(inputs.Content);
var store = Store ?? SaveStore.ForPlatform();
- var notes = new List<string>();
+ if (keep == null) saveNoticeKeys.Clear();
+ var notes = keep != null && startScreen && ReferenceEquals(keep.Session, saveNoticeSession)
+ ? saveNoticeKeys.Select(key => GameStart.NoticeText(text, key)).ToList()
+ : new List<string>();
// A smoke run is reproducible: a fresh game with the golden seed, never the player's autosave.
bool resumed = keep == null || keptResumed; // a language switch offers Continue as the start screen it rebuilds did
keptResumed = true;
var session = keep?.Session ?? (smoke > 0
- ? GameStart.Begin(inputs.Content, store, () => GoldenRun.Seed, notes, text, out resumed, fresh: true)
- : GameStart.Begin(inputs.Content, store, GameStart.NewSeed, notes, text, out resumed));
+ ? GameStart.Begin(inputs.Content, store, () => GoldenRun.Seed, notes, text, out resumed,
+ fresh: true, noticeKeys: saveNoticeKeys)
+ : GameStart.Begin(inputs.Content, store, GameStart.NewSeed, notes, text, out resumed,
+ noticeKeys: saveNoticeKeys));
+ if (keep == null) saveNoticeSession = session;
DiagLog.BootPhase($"session started (turn {session.State.Turn}, replayed)");
var bridge = Bridge = new SimBridge(session, text);
var oldFixedNorth = cameraController.FixedNorth;
@@ -760,8 +771,8 @@ namespace Statecraft.Game.UI
/// <summary>The language switch of Settings (#1036) and of the start screen (#2054): every screen again in
/// <paramref name="language"/> at once, no reload, over the same game with this turn's orders (Begin's keep), and the
/// place it was pressed in open again with the focus on the choice just made (for a mouse press too: the rebuilt UI
- /// has no focus to keep): the start screen, offering Continue only if it did, or else Settings. Not in a smoke run
- /// (smokeRun).</summary>
+ /// has no focus to keep): the start screen, offering Continue only if it did and repeating its save notices in the
+ /// new language, or else Settings. Not in a smoke run (smokeRun).</summary>
void SwitchLanguage(GameInputs inputs, string language)
{
if (Bridge == null || smokeRun) return;
diff --git a/unity/Assets/Scripts/UI/GameStart.cs b/unity/Assets/Scripts/UI/GameStart.cs
index 27e1c5845..eb5a0f3df 100644
--- a/unity/Assets/Scripts/UI/GameStart.cs
+++ b/unity/Assets/Scripts/UI/GameStart.cs
@@ -16,6 +16,12 @@ namespace Statecraft.Game.UI
public static ulong NewSeed() => (ulong)DateTime.UtcNow.Ticks;
+ /// <summary>Renders a language-independent save-notice key in the current UI language.</summary>
+ internal static string NoticeText(UiText text, string key) =>
+ key == "save.unreadable"
+ ? text.Format(key, text["save.reason_other"])
+ : text[key];
+
public static GameSession Begin(Content c, SaveStore store, Func<ulong> newSeed, List<string> notes, UiText text, bool fresh = false) =>
Begin(c, store, newSeed, notes, text, out _, fresh);
@@ -23,8 +29,14 @@ namespace Statecraft.Game.UI
/// new game, whether there was no save, the save was set aside, or <paramref name="fresh"/> ignored it. The start
/// screen offers Continue only when it is true.</summary>
public static GameSession Begin(Content c, SaveStore store, Func<ulong> newSeed, List<string> notes, UiText text, out bool resumed,
- bool fresh = false)
+ bool fresh = false, List<string>? noticeKeys = null)
{
+ void Note(string key)
+ {
+ noticeKeys?.Add(key);
+ notes.Add(NoticeText(text, key));
+ }
+
resumed = false;
if (!fresh)
{
@@ -38,7 +50,8 @@ namespace Statecraft.Game.UI
foreach (var kind in warnings)
{
UnityEngine.Debug.LogWarning("Autosave loaded with a warning: " + kind);
- if (text.Has("save.warning." + kind)) notes.Add(text["save.warning." + kind]);
+ var key = "save.warning." + kind;
+ if (text.Has(key)) Note(key);
}
resumed = true;
return loaded;
@@ -52,9 +65,13 @@ namespace Statecraft.Game.UI
// A refusal with a code (a save from before the GDD cutover, or from a newer version: R-SAVE-001, R-SAVE-002)
// is said once, in the player's language (N4); anything else, and a code with no string, gets one short
// localised reason (#631): this path never throws, so the start is never blocked.
- if (e is SaveException refused && refused.Code != null && text.Has("save.refused." + refused.Code))
- notes.Add(text["save.refused." + refused.Code]);
- else notes.Add(text.Format("save.unreadable", text["save.reason_other"]));
+ var refusedKey = e is SaveException refused && refused.Code != null
+ ? "save.refused." + refused.Code
+ : null;
+ if (refusedKey != null && text.Has(refusedKey))
+ Note(refusedKey);
+ else
+ Note("save.unreadable");
}
}
return GameSession.New(c, newSeed(), Mode.Historical);
diff --git a/unity/Assets/Scripts/UI/NewGamePresenter.cs b/unity/Assets/Scripts/UI/NewGamePresenter.cs
index a90f327eb..f0afe4c49 100644
--- a/unity/Assets/Scripts/UI/NewGamePresenter.cs
+++ b/unity/Assets/Scripts/UI/NewGamePresenter.cs
@@ -48,7 +48,7 @@ namespace Statecraft.Game.UI
if (!Armed) { Armed = true; toast.Show(text["newgame.confirm"]); return; }
Armed = false;
bool deleted = true;
- // An old autosave that cannot be deleted is overwritten by the next turn's autosave anyway, so the new game still starts.
+ // An old autosave that cannot be deleted is overwritten by the next autosave anyway (after the next order or turn), so the new game still starts.
try { store.DeleteAutosave(); } catch (Exception e) { deleted = false; UnityEngine.Debug.LogWarning("Autosave could not be deleted: " + e); }
bridge.Replace(GameSession.New(bridge.Content, seed(), Mode.Historical));
if (deleted) toast.Clear(); else toast.Show(text["newgame.delete_failed"]);
diff --git a/unity/Assets/Tests/EditMode/HebrewUiTests.cs b/unity/Assets/Tests/EditMode/HebrewUiTests.cs
index b53f4f9e3..0b5ef2d5d 100644
--- a/unity/Assets/Tests/EditMode/HebrewUiTests.cs
+++ b/unity/Assets/Tests/EditMode/HebrewUiTests.cs
@@ -316,6 +316,85 @@ public class HebrewUiTests
Assert.IsFalse(Marked("start-language-en"));
}
+ /// <summary>#2552: a save notice belongs to the session as a language-independent key. Rebuilding the open start
+ /// screen through its language choice keeps the notice and renders it in the newly selected language.</summary>
+ [TestCase(UiLanguage.English, UiLanguage.Hebrew)]
+ [TestCase(UiLanguage.Hebrew, UiLanguage.English)]
+ public void AStartScreenSaveNoticeSurvivesALanguageSwitchInTheNewLanguage(string from, string to)
+ {
+ Directory.CreateDirectory(saveDir);
+ File.WriteAllText(Path.Combine(saveDir, SaveStore.AutosaveName), "not a save");
+ LogAssert.Expect(LogType.Warning, new Regex("Autosave (rejected|could not be loaded)")); // either path gives save.unreadable
+ var game = BootWithStartScreen(new SettingsStore(Path.Combine(saveDir, "settings")), from);
+ var session = game.Bridge!.Session;
+ var fromText = from == UiLanguage.Hebrew ? He : En;
+ var toText = to == UiLanguage.Hebrew ? He : En;
+ Assert.AreEqual(fromText.Format("save.unreadable", fromText["save.reason_other"]), Ui.Q<Label>("toast").text,
+ "the notice is raised in the starting language");
+
+ UiTestKit.Press(Ui.Q<Button>("start-language-" + to));
+
+ Assert.AreSame(session, game.Bridge!.Session, "the language switch keeps the session that owns the notice");
+ Assert.IsTrue(StartOpen, "the language switch rebuilds the open start screen");
+ Assert.AreEqual(toText.Format("save.unreadable", toText["save.reason_other"]), Ui.Q<Label>("toast").text,
+ "the retained key is rendered in the new language, not kept as already-rendered text");
+ }
+
+ /// <summary>#2552: a New game replaces the bridge's session without Begin, so the old session's save notice must not come
+ /// back when a language switch then rebuilds the start screen over the new game (Begin with keep, as SwitchLanguage
+ /// calls it). The UI can't reach this today (a New game closes the start screen, so a later switch rebuilds without it),
+ /// so the test drives the two steps directly to pin the invariant. Red-first: without the session check the old
+ /// "could not be loaded" notice is shown again.</summary>
+ [Test]
+ public void ANewGameDropsTheOldSessionsSaveNoticeOnALanguageSwitch()
+ {
+ Directory.CreateDirectory(saveDir);
+ File.WriteAllText(Path.Combine(saveDir, SaveStore.AutosaveName), "not a save");
+ LogAssert.Expect(LogType.Warning, new Regex("Autosave (rejected|could not be loaded)"));
+ var game = BootWithStartScreen(new SettingsStore(Path.Combine(saveDir, "settings")), UiLanguage.English);
+ var stale = En.Format("save.unreadable", En["save.reason_other"]);
+ Assert.AreEqual(stale, Ui.Q<Label>("toast").text, "precondition: the first session raised the notice");
+
+ game.Bridge!.Replace(Statecraft.Sim.GameSession.New(Inputs.Content, 1, Statecraft.Sim.Mode.Historical)); // as NewGamePresenter.Press
+ game.Language = UiLanguage.Hebrew;
+ game.Begin(Inputs, 0, startScreen: true, keep: game.Bridge);
+
+ var toast = Ui.Q<Label>("toast");
+ Assert.AreEqual("", toast.text, "the new game's start screen shows no save notice at all");
+ Assert.AreEqual(DisplayStyle.None, toast.style.display.value, "and the toast is hidden");
+ }
+
+ /// <summary>#2552, the player's route beside the test above: after New game replaces a warned-about saved session, a
+ /// language switch must not bring that session's save notice back. Both start-screen New Game presses, then Settings'
+ /// language choice after the start screen closes. It passes with or without the session check (a closed start screen
+ /// rebuilds with no notices), so it pins the visible behaviour, and the test above pins the check itself.</summary>
+ [Test]
+ public void ANewGameFromTheStartScreenShowsNoOldNoticeAfterALanguageSwitch()
+ {
+ Directory.CreateDirectory(saveDir);
+ var saved = Statecraft.Sim.GameSession.New(Inputs.Content, 9, Statecraft.Sim.Mode.Historical).Save.Write()
+ .Replace("content " + Inputs.Content.Hash, "content " + new string('0', Inputs.Content.Hash.Length));
+ new SaveStore(saveDir).WriteAutosave(saved);
+ LogAssert.Expect(LogType.Warning, "Autosave loaded with a warning: " + Statecraft.Sim.GameSession.ContentChanged);
+ var game = BootWithStartScreen(new SettingsStore(Path.Combine(saveDir, "settings")), UiLanguage.English);
+ var oldSession = game.Bridge!.Session;
+ var stale = En["save.warning." + Statecraft.Sim.GameSession.ContentChanged];
+ Assert.AreEqual(stale, Ui.Q<Label>("toast").text, "precondition: the first session raised the notice");
+
+ UiTestKit.Press(Ui.Q<Button>("start-new-game"));
+ Assert.AreEqual(En["newgame.confirm"], Ui.Q<Label>("toast").text, "the first press arms New Game");
+ UiTestKit.Press(Ui.Q<Button>("start-new-game"));
+ Assert.AreNotSame(oldSession, game.Bridge!.Session, "the second press started a new game");
+ Assert.IsFalse(StartOpen, "NewGamePresenter.Started closes the start screen");
+
+ UiTestKit.Press(Ui.Q<Button>("nav-settings"));
+ UiTestKit.Press(Ui.Q<Button>("settings-language-he"));
+
+ var toast = Ui.Q<Label>("toast");
+ Assert.AreEqual("", toast.text, "the new game shows no notice from the replaced saved session");
+ Assert.AreEqual(DisplayStyle.None, toast.style.display.value, "and the toast is hidden");
+ }
+
/// <summary>A choice on the start screen goes through Settings' own switch: the UI changes at once over the same game,
/// the start screen stays up (Continue still only with a save) with the focus on the choice, the choice is kept under
/// Settings' key, and Settings shows it. The other way round, a choice in Settings is what the next start screen
diff --git a/unity/Assets/Tests/EditMode/SaveUiTests.cs b/unity/Assets/Tests/EditMode/SaveUiTests.cs
index ff5496839..37beb21bb 100644
--- a/unity/Assets/Tests/EditMode/SaveUiTests.cs
+++ b/unity/Assets/Tests/EditMode/SaveUiTests.cs
@@ -449,7 +449,9 @@ public class SaveUiTests
ui.Press("new-game");
Assert.DoesNotThrow(() => ui.Press("new-game"));
Assert.AreEqual(0, bridge.State.Turn);
- StringAssert.StartsWith("The old saved game could not be removed", ui.Q<Label>("toast").text);
+ Assert.AreEqual("The old saved game could not be removed; it will be replaced the next time the game saves.",
+ ui.Q<Label>("toast").text,
+ "was 'The old saved game could not be removed; it will be replaced after your next turn.'; autosave also runs after committed orders");
}
sealed class DeleteFailsStore : SaveStore
diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yaml
index b0a858618..cc25f9f88 100644
--- a/unity/Assets/UI/strings.en.yaml
+++ b/unity/Assets/UI/strings.en.yaml
@@ -748,7 +748,7 @@ unit.send_home_queued: "Send home ordered: the unit goes home when you end the t
unit.order.reinforce: "Reinforce +{0}"
unit.reinforce_queued: "Reinforce ordered: the replacements start training when you end the turn"
newgame.confirm: "Press New game again to abandon this game and start over."
-newgame.delete_failed: "The old saved game could not be removed; it will be replaced after your next turn."
+newgame.delete_failed: "The old saved game could not be removed; it will be replaced the next time the game saves."
save.unreadable: "Your saved game could not be loaded ({0}). A new game has started."
save.reason_other: "the file could not be read or replayed"
save.refused.older_rules: "Your saved game was made with an earlier version of the game's rules and cannot be continued. A new game has started."
diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yaml
index ce9769074..eb9ec41d0 100644
--- a/unity/Assets/UI/strings.he.yaml
+++ b/unity/Assets/UI/strings.he.yaml
@@ -872,7 +872,8 @@ unit.send_home_queued: "ניתנה פקודת שליחה הביתה: היחיד
unit.order.reinforce: "תגבור +{0}"
unit.reinforce_queued: "ניתנה פקודת תגבור: כוח ההשלמה יתחיל באימון בסיום התור"
newgame.confirm: "יש ללחוץ שוב על משחק חדש כדי לעזוב את המשחק הזה ולהתחיל מחדש."
-newgame.delete_failed: "לא ניתן היה להסיר את השמירה הקודמת; היא תוחלף אחרי התור הבא."
+# For the native reviewer (#564): agent-drafted, #2552
+newgame.delete_failed: "לא ניתן היה להסיר את השמירה הקודמת; היא תוחלף בפעם הבאה שהמשחק יישמר."
save.unreadable: "לא ניתן היה לטעון את המשחק השמור ({0}). משחק חדש התחיל."
save.reason_other: "לא ניתן היה לקרוא את הקובץ או לשחזר את המשחק"
save.refused.older_rules: "המשחק השמור נוצר בגרסה קודמת של חוקי המשחק ואי אפשר להמשיך אותו. משחק חדש התחיל."