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.

Toast: a recording failure no longer replaces the start-up notes (Refs #2707, stacked on #2909) (#2913)

Berif67c9c2f05c2
diff --git a/changelog.d/2707-recording-retry.md b/changelog.d/2707-recording-retry.md
new file mode 100644
index 000000000..6a72934fd
--- /dev/null
+++ b/changelog.d/2707-recording-retry.md
@@ -0,0 +1,5 @@
+### Fixed
+
+- When the start screen's recording cannot be played, "The recording could not be played." now appears under the
+ start-up notes (such as an unreadable saved game) instead of replacing them, and it goes away when you press the
+ button again.
diff --git a/unity/Assets/Scripts/UI/DeclarationRecording.cs b/unity/Assets/Scripts/UI/DeclarationRecording.cs
index c31efce97..d45fa8dfe 100644
--- a/unity/Assets/Scripts/UI/DeclarationRecording.cs
+++ b/unity/Assets/Scripts/UI/DeclarationRecording.cs
@@ -59,7 +59,7 @@ namespace Statecraft.Game.UI
public enum Phase { Idle, Loading, Playing }
readonly Button button; readonly VisualElement caption, row; readonly UiText text;
- readonly Action onPress; readonly Action<string> say; readonly Fetch fetch; readonly IOutput output;
+ readonly Action onPress; readonly Action<string> say; readonly Action? retry; readonly Fetch fetch; readonly IOutput output;
AudioClip? clip; IRequest? request; IVisualElementScheduledItem? timer;
bool heard, started; int waitedMs, stalledMs, generation; ulong bytesSeen;
@@ -70,11 +70,12 @@ namespace Statecraft.Game.UI
public bool Playing => State != Phase.Idle;
/// <param name="say">Shows a message (the toast) when the recording cannot be played.</param>
+ /// <param name="retry">Called when a press starts a new load, so the toast can drop the last failure's line.</param>
/// <param name="fetch">Test seam; null fetches with UnityWebRequestMultimedia.</param>
/// <param name="output">Test seam; null plays through an AudioSource.</param>
- public DeclarationRecording(VisualElement root, UiText text, Action<string> say, Fetch? fetch = null, IOutput? output = null)
+ public DeclarationRecording(VisualElement root, UiText text, Action<string> say, Fetch? fetch = null, IOutput? output = null, Action? retry = null)
{
- this.text = text; this.say = say;
+ this.text = text; this.say = say; this.retry = retry;
this.fetch = fetch ?? WebFetch;
this.output = output ?? new SourceOutput();
row = root.Q<VisualElement>("start-recording");
@@ -99,6 +100,7 @@ namespace Statecraft.Game.UI
public void Toggle()
{
if (Playing) { Stop(); return; }
+ retry?.Invoke();
State = Phase.Loading;
button.text = text["start.loading"];
waitedMs = 0; stalledMs = 0; bytesSeen = 0; heard = false; started = false;
diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.cs
index cfa1fc807..0d627cf36 100644
--- a/unity/Assets/Scripts/UI/GameRoot.cs
+++ b/unity/Assets/Scripts/UI/GameRoot.cs
@@ -678,7 +678,7 @@ namespace Statecraft.Game.UI
if (showsStart) // newGame is made above whenever smoke == 0
{
var cam = cameraController;
- var recording = Own(new DeclarationRecording(root, text, toast.Show)); // never built in automated runs (Skipped)
+ var recording = Own(new DeclarationRecording(root, text, toast.RecordingFailed, retry: toast.RecordingRetried)); // never built in automated runs (Skipped)
if (music != null) music.Duck = () => recording.Playing; // the theme drops low under Ben-Gurion's voice
start = Own(new StartScreenPresenter(root, newGame!, resumed, shown =>
{
diff --git a/unity/Assets/Scripts/UI/ToastPresenter.cs b/unity/Assets/Scripts/UI/ToastPresenter.cs
index dbe27f994..53e3e884a 100644
--- a/unity/Assets/Scripts/UI/ToastPresenter.cs
+++ b/unity/Assets/Scripts/UI/ToastPresenter.cs
@@ -19,6 +19,7 @@ namespace Statecraft.Game.UI
IReadOnlyList<UnitEntry> units = Array.Empty<UnitEntry>();
string shown = ""; // the lines Show and Append set; Clear and the next order replace them
string? saveFailure; // SaveFailed's line, kept until SaveSucceeded
+ string? recordingFailure; // RecordingFailed's line, kept until the retry or the next order
/// <summary>The units_1948.yaml rows that name starting forces in the committed orders' Why lines (GameRoot sets
/// them once the map has read them, as for WhyPresenter); without them a starting force is named by its type.</summary>
@@ -49,11 +50,11 @@ namespace Statecraft.Game.UI
public void Dispose() { bridge.TurnEnded -= onTurnEnded; bridge.TurnEnded -= onRouteStep; bridge.Refused -= Refuse; bridge.Changed -= Clear; bridge.Committed -= onCommitted; }
- /// <summary>Shows the lines as they are, a failed save's line under them (none of either = hide).</summary>
+ /// <summary>Shows the lines as they are, a failed recording's line and a failed save's line under them (none of either = hide).</summary>
public void Show(IEnumerable<string> lines)
{
shown = string.Join("\n", lines);
- var all = new[] { shown, saveFailure ?? "" }.Where(x => x.Length > 0).ToList();
+ var all = new[] { shown, recordingFailure ?? "", saveFailure ?? "" }.Where(x => x.Length > 0).ToList();
label.text = string.Join("\n", all);
label.style.display = all.Count > 0 ? DisplayStyle.Flex : DisplayStyle.None;
}
@@ -68,6 +69,18 @@ namespace Statecraft.Game.UI
/// <see cref="SaveSucceeded"/> (autosave and New Game, and on WebGL the IndexedDB result).</summary>
public void SaveFailed(string line) { saveFailure = line; Show(shown); }
+ /// <summary>The start screen's recording could not be played: its line goes under the lines shown (the start-up
+ /// notes), not in place of them, until the next press of its button or the next change, such as an order (#2707).</summary>
+ public void RecordingFailed(string line) { recordingFailure = line; Show(shown); }
+
+ /// <summary>The recording's button was pressed again: its failure line goes; the other lines stay.</summary>
+ public void RecordingRetried()
+ {
+ if (recordingFailure == null) return;
+ recordingFailure = null;
+ Show(shown);
+ }
+
/// <summary>A save succeeded: a failed save's line goes; the other lines stay.</summary>
public void SaveSucceeded()
{
@@ -79,6 +92,6 @@ namespace Statecraft.Game.UI
/// <summary>Shows why an order was refused ("Not done: ...").</summary>
public void Refuse(string reason) => Show(text.Format("toast.refused", reason));
- public void Clear() => Show(new string[0]);
+ public void Clear() { recordingFailure = null; Show(new string[0]); }
}
}
diff --git a/unity/Assets/Tests/EditMode/StartScreenTests.cs b/unity/Assets/Tests/EditMode/StartScreenTests.cs
index f84ed7e7d..ce3d596a2 100644
--- a/unity/Assets/Tests/EditMode/StartScreenTests.cs
+++ b/unity/Assets/Tests/EditMode/StartScreenTests.cs
@@ -210,6 +210,36 @@ public class StartScreenTests
return store;
}
+ // #2707 item 3: the start-up notes (here an unreadable autosave) stay in the toast when the recording fails to play,
+ // the failure line sits under them, and pressing the button again takes only that line away.
+ [Test]
+ public void ARecordingFailureIsAddedToTheStartNotesAndGoesWithTheNextPress()
+ {
+ var dir = Path.Combine(Path.GetTempPath(), "statecraft-start-" + Guid.NewGuid().ToString("N"));
+ temp.Add(dir);
+ Directory.CreateDirectory(dir);
+ File.WriteAllText(Path.Combine(dir, SaveStore.AutosaveName), "not a save");
+ var store = new SaveStore(dir);
+ using var ui = new RenderedUi();
+ var notes = new List<string>();
+ var bridge = new SimBridge(GameStart.Begin(C, store, () => 4UL, notes, Text, out var resumed), Text);
+ using var toast = new ToastPresenter(ui.Root, bridge, Text);
+ toast.Show(notes); // as GameRoot, once the screens are ready
+ Assert.IsNotEmpty(notes);
+ var label = ui.Q<Label>("toast");
+ var start = label.text;
+ StringAssert.StartsWith("Your saved game could not be loaded", start);
+ var fails = true;
+ using var recording = new DeclarationRecording(ui.Root, Text, toast.RecordingFailed,
+ (url, done) => { if (fails) done(null, "no network"); return new NoAnswer(); }, retry: toast.RecordingRetried);
+ LogAssert.Expect(LogType.Warning, new System.Text.RegularExpressions.Regex("^RECORDING failed"));
+ ui.Press("start-listen");
+ Assert.AreEqual(start + "\n" + Text["start.recording_failed"], label.text, "the notes stay, the failure is added");
+ fails = false;
+ ui.Press("start-listen"); // the retry
+ Assert.AreEqual(start, label.text, "the failure line goes with the retry; the notes stay");
+ }
+
/// <summary>Ben-Gurion's recording (docs/declaration-recording.md) plays only from its own button: never when the screen
/// opens, never on Continue or New Game; the screen closing stops it.</summary>
[Test]
@@ -918,7 +948,7 @@ public class StartScreenTests
var bridge = new SimBridge(GameStart.Begin(C, store, () => 4UL, new List<string>(), text, out var resumed), text);
var toast = new ToastPresenter(root, bridge, text);
var newGame = new NewGamePresenter(root, bridge, store, toast, text, () => 5UL);
- var recording = new DeclarationRecording(root, text, toast.Show, (url, done) => new NoAnswer()); // as GameRoot
+ var recording = new DeclarationRecording(root, text, toast.RecordingFailed, (url, done) => new NoAnswer(), retry: toast.RecordingRetried); // as GameRoot
var start = new StartScreenPresenter(root, newGame, resumed, null, recording, text);
var at = hebrew ? "Hebrew 390x844" : "English 390x844";
Application.logMessageReceived += Capture;