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:
parent
02e7fd4b7e
commit
8a1e205cf0
6 changed files with 132 additions and 38 deletions
|
|
@ -155,17 +155,37 @@ public static class RunSave
|
|||
}
|
||||
|
||||
// Removes every run record (SavedGame, SavedZone, OrbitData, BodyData, ProvenanceLedger) in one Commit.
|
||||
public static void Clear(CultCache cache)
|
||||
public static void Clear(CultCache cache) => Remove(cache, Records(cache));
|
||||
|
||||
// A new run replaces the saved one only once it has started: start runs with the saved run still in the store.
|
||||
// When it returns a value, the saved run's records go. When it returns null or throws, the records it wrote go and
|
||||
// the saved run stays as it was.
|
||||
public static T Replace<T>(CultCache cache, Func<T> start) where T : class
|
||||
{
|
||||
var run = cache.AllStoredDocuments
|
||||
var saved = Records(cache);
|
||||
T started = null;
|
||||
try
|
||||
{
|
||||
started = start();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Remove(cache, started != null ? saved : Records(cache).Except(saved).ToArray());
|
||||
}
|
||||
return started;
|
||||
}
|
||||
|
||||
private static CultRecordKey[] Records(CultCache cache) =>
|
||||
cache.AllStoredDocuments
|
||||
.Where(stored => IsRunRecord(stored.Descriptor.DocumentType))
|
||||
.Select(stored => stored.Key)
|
||||
.ToArray();
|
||||
|
||||
private static void Remove(CultCache cache, CultRecordKey[] records) =>
|
||||
cache.Commit(batch =>
|
||||
{
|
||||
foreach (var key in run) batch.Remove(key);
|
||||
foreach (var key in records) batch.Remove(key);
|
||||
});
|
||||
}
|
||||
|
||||
public static bool IsRunRecord(Type documentType) =>
|
||||
AetheriaStores.RunTypes.Any(home => home.IsAssignableFrom(documentType));
|
||||
|
|
|
|||
Loading…
Reference in a new issue