A new run replaces the saved run only once it has staged; a failed start says why and leaves the saved run

Launch cleared the run store before generating, and a generation or staging failure only reached the log: the
Generating Galaxy dialog stayed up, StartGame threw, and the saved run was already gone.

RunSave.Replace runs a start with the saved run still stored: when it returns a staged run the saved run's records go,
and when it returns null or throws, only the records it wrote (the arena's orbits and bodies) go. StartGame's
new-run branch is StartScenario, chosen by PendingScenario rather than by the absence of a SavedGame; it mints into an
empty ledger, and a failed start clears CurrentGalaxy (so quitting saves nothing) and refuses on the main menu with
every failure. Launch no longer clears; a galaxy that throws is refused on the title menu. The menu offers Continue
whenever no run is live, which replaces MainMenu.InGame (cut, with its prefab value and scene override), so a
failed start can resume the saved run in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-03 22:03:50 +02:00
commit 8a1e205cf0
6 changed files with 132 additions and 38 deletions

View file

@ -126,6 +126,56 @@ public sealed class RunSaveTests : IDisposable
Assert.Equal(before, new[] { Catalog, Player }.Select(Hash).ToArray());
}
// A new run's start writes its arena's orbits and bodies while the saved run is still stored. A start that fails,
// by returning nothing or by throwing, takes away only what it wrote; one that starts takes away the saved run.
[Fact]
public void ANewRunReplacesTheSavedRunOnlyOnceItHasStarted()
{
using (var cache = Open())
RunSave.Commit(cache, Game(cache), Zones(3, StageZoneContents(cache), 0), new ProvenanceLedger());
string[] saved;
using (var cache = Open())
saved = RunKeys(cache);
Assert.Equal(8, saved.Length);
using (var cache = Open())
Assert.Null(RunSave.Replace<ZonePack>(cache, () =>
{
StageZoneContents(cache);
return null;
}));
using (var cache = Open())
{
Assert.Equal(saved, RunKeys(cache));
Assert.NotNull(cache.GetGlobal<SavedGame>());
}
using (var cache = Open())
Assert.Throws<InvalidOperationException>(() => RunSave.Replace<ZonePack>(cache, () =>
{
StageZoneContents(cache);
throw new InvalidOperationException("the arena would not generate");
}));
using (var cache = Open())
Assert.Equal(saved, RunKeys(cache));
ZonePack started;
using (var cache = Open())
started = RunSave.Replace(cache, () => StageZoneContents(cache));
using (var cache = Open())
{
Assert.Null(cache.GetGlobal<SavedGame>());
Assert.Equal(started.Orbits.Select(orbit => orbit.Key.Value).Concat(started.Planets.Select(body => body.Key.Value))
.OrderBy(key => key, StringComparer.Ordinal), RunKeys(cache));
}
}
private static string[] RunKeys(CultCache cache) => cache.AllStoredDocuments
.Where(stored => RunSave.IsRunRecord(stored.Descriptor.DocumentType))
.Select(stored => stored.Key.Value)
.OrderBy(key => key, StringComparer.Ordinal)
.ToArray();
// Lot 1 sits on the root ship's hull; lot 3 (Produced from facility 4, input 5) sits in a docked child's
// docking-bay contents; lots 2 and 6 are minted but referenced by nothing packed. Only the reachable closure
// {1, 3, 4, 5} survives into the written copy; the live ledger keeps every lot.