/** * Save/Restore Service — manages game state persistence and undo. * * Public interface: {@link SaveRestoreService} class — `createSaveData`, * `loadSaveData`, plus undo helpers (`createUndoSnapshot`, `undo`, * `canUndo`, `getUndoLevels`, `clearUndoSnapshots`). * * Bounded context: `@sharpee/engine` runtime. Every Sharpee host (CLI, * platform-browser, multi-user sandbox) routes saves through this * service. * * Save format v2.0.0 (one-shot cutover from v1.0.0; v1 saves rejected): * - `IEngineState.worldSnapshot` carries the verbatim * `WorldModel.toJSON()` output, gzipped, then base64-encoded for * JSON-safety. Hydration: base64-decode → gunzip → `world.loadJSON()`. * - This replaces v1's partial `spatialIndex` serializer, which * captured only entity traits + room contents and silently dropped * the ScoreLedger, capabilities, world state values, relationships, * ID counters, and sub-container containment. */ import { WorldModel } from '@sharpee/world-model'; import { ISaveData, ISerializedTurn, ISemanticEventSource } from '@sharpee/core'; import { PluginRegistry } from '@sharpee/plugins'; import { TurnResult, GameContext } from './types'; import { Story } from './story'; /** * Interface for accessing engine state needed for save/restore */ export interface ISaveRestoreStateProvider { getWorld(): WorldModel; getContext(): GameContext; getStory(): Story | undefined; getEventSource(): ISemanticEventSource; getPluginRegistry(): PluginRegistry; getParser(): unknown | undefined; } /** * Configuration for the undo system */ export interface UndoConfig { maxSnapshots: number; } /** * Service for managing save/restore and undo functionality */ export declare class SaveRestoreService { private undoSnapshots; private undoSnapshotTurns; private maxUndoSnapshots; constructor(config?: UndoConfig); /** * Create an undo snapshot of the current world state */ createUndoSnapshot(world: WorldModel, currentTurn: number): void; /** * Undo to previous turn * @returns The turn number restored to, or null if nothing to undo */ undo(world: WorldModel): { turn: number; } | null; /** * Check if undo is available */ canUndo(): boolean; /** * Get number of undo levels available */ getUndoLevels(): number; /** * Clear all undo snapshots (e.g., after restore) */ clearUndoSnapshots(): void; /** * Create save data from current engine state */ createSaveData(provider: ISaveRestoreStateProvider): ISaveData; /** * Load save data into engine state * @returns New event source with restored events */ loadSaveData(saveData: ISaveData, provider: ISaveRestoreStateProvider): { eventSource: ISemanticEventSource; currentTurn: number; }; /** * Serialize event source */ private serializeEventSource; /** * Serialize event data, handling functions and special types */ private serializeEventData; /** * Deserialize event source */ private deserializeEventSource; /** * Deserialize event data, handling function markers */ private deserializeEventData; /** * Serialize turn history */ private serializeTurnHistory; /** * Deserialize turn history */ deserializeTurnHistory(turns: ISerializedTurn[], eventSource: ISemanticEventSource): TurnResult[]; /** * Serialize parser state */ private serializeParserState; } /** * Create a save/restore service instance */ export declare function createSaveRestoreService(config?: UndoConfig): SaveRestoreService; //# sourceMappingURL=save-restore-service.d.ts.map