Skip to content

Save & Load

Doodle Engine supports saving and loading the complete game state.

interface SaveData {
version: string; // Save format version
timestamp: string; // ISO 8601 timestamp
state: GameState; // Complete game state
}

The SaveData contains the entire GameState, including current location, time, flags, variables, inventory, quest progress, dialogue state, and more.

const saveData = engine.saveGame();
// saveData is a plain object, ready to serialize
const snapshot = engine.loadGame(saveData);
// Restores state and returns a fresh snapshot

The GameRenderer includes a SaveLoadPanel component that saves to localStorage:

import { GameProvider, GameRenderer } from '@doodle-engine/react';
<GameProvider engine={engine} initialSnapshot={snapshot}>
<GameRenderer />
</GameProvider>;

The panel provides Save and Load buttons with feedback messages. The Load button is disabled when no save exists.

import { SaveLoadPanel } from '@doodle-engine/react';
<SaveLoadPanel
onSave={() => engine.saveGame()}
onLoad={(saveData) => {
const snapshot = engine.loadGame(saveData);
// update your state with the new snapshot
}}
storageKey="my-game-save"
/>;
PropTypeDefaultDescription
onSave() => SaveDatarequiredCalled when the player clicks Save
onLoad(saveData: SaveData) => voidrequiredCalled when the player clicks Load
storageKeystring'doodle-engine-save'localStorage key
classNamestring''CSS class

For custom storage (server-side, IndexedDB, etc.), use the engine API directly:

// Save to server
const saveData = engine.saveGame();
await fetch('/api/save', {
method: 'POST',
body: JSON.stringify(saveData),
});
// Load from server
const response = await fetch('/api/save');
const saveData = await response.json();
const snapshot = engine.loadGame(saveData);

The complete GameState is saved, including:

  • Current location and time
  • All flags and variables
  • Inventory
  • Quest progress
  • Unlocked journal entries
  • Player notes
  • Current dialogue state
  • Character locations, party membership, relationships, stats
  • Item locations
  • Map enabled/disabled state
  • Current locale