Overview
Sugarbox is a single engine class, SugarboxEngine, created with the async init() method.
init() is async because it can load previously stored achievements and settings, and it can also load the most recent save on startup (when enabled in config).
Creating an engine
Section titled “Creating an engine”import { SugarboxEngine } from "sugarbox";
export const engine = await SugarboxEngine.init({ name: "Dave's Adventure",
startPassage: { name: "Start", data: "This is the starting passage", tags: ["prologue"], },
// Note: the current API uses `vars` (not `variables`) vars: { player: { gold: 500, level: 1, }, },
// Optional passages that should be available immediately otherPassages: [ { name: "Next", data: "You step forward.", }, ],
// Settings and achievements are stored separately from save slots achievements: { unlocked: { pirateCove: false, hiddenSchool: false, }, completedGame: false, },
settings: { volume: 35, theme: "dark", },
// Class constructors to support serialization and deserialization classes: [],
// All config fields are optional; these are the defaults config: { autoSave: false, compress: true, emitMode: "acc", loadOnStart: true, maxStates: 100, regenSeed: "passage", saveCompat: "strict", saveSlots: 20, saveVersion: "0.0.1", stateMergeCount: 1, // You can also provide `initialSeed` if you want deterministic runs // initialSeed: 12345, },
// Migrations to move old save data forward as your schema changes migrations: [],});