Capture presets through their own cache; keep the catalog read-only
Opening the process cache's catalog writable in the editor was the wrong cut. It made catalog read-only only by convention, so a stray catalog write in play succeeded and a later flush could land play-mutated instances in Aetheria.cc. - The process cache opens the catalog read-only in every build again, so the missing-global check runs for it as it did beforedb83cd29. The writable empty-seed exemption fromab4ced0fstays for AetherDb and fixtures. - Loadouts.Commit(catalogPath, loadout, replace) is the only preset writer. It opens its own short-lived cache over the catalog, writable, commits the one preset conditionally on its key and disposes it. No other cache or instance is touched. The running game sees the preset only after the catalog reloads. CultLib at a0813c6 allows this: a read-only single-file store takes no lock and holds no handle, and the writer's commit takes the exclusive sidecar <path>.lock and replaces the file atomically. - Capture refuses, writing nothing, when Aetheria.cc is missing (it never creates the catalog), when a preset of that name exists under another key (CultCache does not reject duplicate names on write), or when the key holds a preset and replace is not given. - The console refuses a command with any character outside letters, digits, spaces and hyphens instead of stripping it, so "Mk.II" can no longer become "MkII". capturepreset refuses a second argument other than replace, so an unquoted capturepreset My Ship refuses instead of saving "My". - The capture log line says the session sees the preset after a reload, and that a Studio session opened earlier overwrites captured presets on save. - Tests: capture while the process cache holds the catalog read-only leaves it unchanged; a missing catalog refuses and creates nothing; a same name under a Studio-minted key refuses, with or without replace; a game-shaped read-only open missing a global throws. The existing preset tests now commit through the catalog path. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
11902b23cf
commit
d503f076e1
5 changed files with 121 additions and 38 deletions
|
|
@ -42,6 +42,8 @@ public class ActionGameManager : MonoBehaviour
|
|||
|
||||
private static CultCache _cultCache;
|
||||
|
||||
private static string CatalogPath => Path.Combine(GameDataDirectory.FullName, "Aetheria.cc");
|
||||
|
||||
public static CultCache CultCache
|
||||
{
|
||||
get
|
||||
|
|
@ -50,12 +52,11 @@ public class ActionGameManager : MonoBehaviour
|
|||
|
||||
// All three stores attach once and stay attached until the process exits. The run lifecycle is record-level
|
||||
// inside this cache; reopening would replace the catalog instances the galaxy and live entities hold.
|
||||
// The editor opens the catalog writable so the capturepreset console command can author presets in play.
|
||||
// The catalog is read-only in every build; capturepreset writes through its own cache (Loadouts.Commit).
|
||||
_cultCache = AetheriaStores.Open(
|
||||
Path.Combine(GameDataDirectory.FullName, "Aetheria.cc"),
|
||||
CatalogPath,
|
||||
runPath: Path.Combine(GameDataDirectory.FullName, "run.cc"),
|
||||
playerPath: Path.Combine(GameDataDirectory.FullName, "player.cc"),
|
||||
catalogWritable: Application.isEditor);
|
||||
playerPath: Path.Combine(GameDataDirectory.FullName, "player.cc"));
|
||||
|
||||
return _cultCache;
|
||||
}
|
||||
|
|
@ -546,18 +547,27 @@ public class ActionGameManager : MonoBehaviour
|
|||
//Temporary, or not
|
||||
ConsoleController.AddCommand("tow", _ => TowShip());
|
||||
|
||||
// Editor only: capturepreset "<name>" [replace] writes the piloted ship as a catalog preset.
|
||||
// Editor only: capturepreset "<name>" [replace] writes the piloted ship as a catalog preset. A multi-word name must
|
||||
// be quoted; any other second argument than replace is refused rather than dropped.
|
||||
if (Application.isEditor)
|
||||
ConsoleController.AddCommand("capturepreset", args =>
|
||||
{
|
||||
var console = ConsoleController.Instance;
|
||||
var name = args.Length > 0 ? args[0] : "";
|
||||
if (string.IsNullOrWhiteSpace(name)) { console.AppendLogLine("usage: capturepreset \"<name>\" [replace]"); return; }
|
||||
var replace = args.Length == 2 && args[1] == "replace";
|
||||
if (string.IsNullOrWhiteSpace(name) || args.Length > 2 || args.Length == 2 && !replace)
|
||||
{
|
||||
console.AppendLogLine("usage: capturepreset \"<name>\" [replace] (quote a name with spaces)");
|
||||
return;
|
||||
}
|
||||
if (!(_currentEntity is Ship ship)) { console.AppendLogLine("capturepreset: pilot a ship first"); return; }
|
||||
try
|
||||
{
|
||||
var written = Loadouts.Commit(CultCache, Loadouts.Capture(ItemManager, ship, name), args.Length > 1 && args[1] == "replace");
|
||||
console.AppendLogLine(written ? $"Preset '{name}' written to the catalog" : $"Preset '{name}' changed on disk since load; nothing written");
|
||||
var written = Loadouts.Commit(CatalogPath, Loadouts.Capture(ItemManager, ship, name), replace);
|
||||
console.AppendLogLine(written
|
||||
? $"Preset '{name}' written to {CatalogPath}. This session sees it after the catalog reloads (next launch). " +
|
||||
"Reopen CultCache Studio before saving there: a Studio session opened earlier overwrites captured presets."
|
||||
: $"Preset '{name}' changed on disk since load; nothing written");
|
||||
}
|
||||
catch (InvalidOperationException e)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue