Skip to content

EngineStore Composite

Most games want one corpus instance shared across snapshots, bindings, and prefs:

import { engine_store } from "@f0rbit/forge/storage";
const store = engine_store({ backend: "file", dir: "./saves" });
// ^ EngineStore = {
// snapshots: Store<Snapshot>;
// bindings: Store<Bindings>;
// prefs: Store<Prefs>;
// corpus(): Corpus;
// }
await store.snapshots.save("auto", taken.value);
await store.bindings.save("default", input.bindings());
await store.prefs.save("user", { debug_enabled: true, time_scale: 1, autosave: false });
Sub-storeTypeDefault schema
snapshotsStore<Snapshot>snapshot_schema
bindingsStore<Bindings>bindings_schema (validates trigger union, axis union, deadzone)
prefsStore<Prefs>prefs_schema (debug_enabled, time_scale, autosave)

Pass into boot() so palette save / load commands work:

const r = await boot({
mount: "#root",
engine_store: store,
// ...
});
engine_store(); // mem backend, prefix "forge"
engine_store({ backend: "mem" }); // explicit
engine_store({ backend: "file", dir: "./saves", id_prefix: "mygame" });