/** * `SaveManager` — wraps the engine's `ISaveData` for localStorage * persistence and exposes a small UI surface (save index, autosave, * transcript decompression). * * Public interface: {@link SaveManager} class. * * Bounded context: `@sharpee/platform-browser` host. The host registers * `ISaveRestoreHooks` with the engine; on save the engine produces a * complete `ISaveData` and the platform wraps it in a * {@link BrowserSaveEnvelope}; on restore the platform unwraps the * envelope and returns the engine save back to the engine, which * applies it via `WorldModel.loadJSON`. * * History: v3.0.0-delta of this manager implemented its own * locations + traits serializer that silently dropped score, * capabilities, world state values, relationships, and ID counters. * v4.0.0 (this version) routes through the engine's save/restore * service and is therefore feature-complete by construction. The save * format bumped from `'3.0.0-delta'` → envelope `'4.0.0'`; old slots * are rejected. */ import type { ISaveData } from '@sharpee/core'; import type { WorldModel } from '@sharpee/world-model'; import type { BrowserSaveEnvelope, SaveContext, SaveSlotMeta } from '../types'; export interface SaveManagerConfig { /** Storage key prefix (e.g., "dungeo-") */ storagePrefix: string; /** WorldModel reference — used only for UI helpers (current location). */ world: WorldModel; /** Callback when state changes (for UI updates) */ onStateChange?: () => void; } export declare class SaveManager { private storagePrefix; private indexKey; private savePrefix; private world; private onStateChange?; constructor(config: SaveManagerConfig); /** * Walk localStorage for entries under this manager's `savePrefix` and * delete any whose envelope is not the current `ENVELOPE_VERSION`. * Prunes corresponding index entries. * * Treats malformed payloads (not lz-string compressed, not JSON, no * `envelopeVersion`) as obsolete and deletes them — better than * leaving unreadable bytes consuming quota. * * Idempotent: a second call after a clean-up is a no-op (every * remaining entry will pass the version check). */ private cleanupObsoleteSaves; /** Get list of all saved games from index. */ getSaveIndex(): SaveSlotMeta[]; /** Update save index with new/updated slot. */ updateSaveIndex(meta: SaveSlotMeta): void; /** Get current player's containing-room name, or 'Unknown'. */ getCurrentLocation(): string; /** Generate a suggested save name based on current state. */ generateSaveName(turnCount: number): string; /** Sanitize a user-provided save name for use as a storage key. */ sanitizeSaveName(name: string): string; /** * Wrap an engine save in an envelope and persist it to localStorage. * * @param slotName - already-sanitized slot key. * @param engineSave - the canonical save produced by the engine * (`ISaveData`). Carries the full world state via * `engineState.worldSnapshot`. * @param context - browser-only context for UI display: turn count * for the slot meta, score for the envelope, transcript HTML to * restore the visible scrollback. */ performSave(slotName: string, engineSave: ISaveData, context: SaveContext, _silent?: boolean): { success: boolean; error?: string; }; /** * Persist an autosave to the dedicated autosave slot. Same envelope * shape as {@link performSave}; only the slot key differs. */ performAutoSave(engineSave: ISaveData, context: SaveContext): void; /** * Load and decompress an envelope from localStorage. Returns `null` * for unknown slots, malformed payloads, or wrong-version envelopes. * v3.0.0-delta saves are not migrated — they were known-broken. */ loadEnvelope(slotName: string): BrowserSaveEnvelope | null; /** Convenience: load the autosave envelope. */ loadAutosaveEnvelope(): BrowserSaveEnvelope | null; /** Decompress transcript HTML from an envelope. */ decompressTranscript(compressedHtml: string): string; /** * Sync localStorage saves to world `sharedData` so stdlib actions * know saves exist (used by the `restoring` action's listing). */ syncSavesToWorld(): void; /** Clear the autosave slot (used on restart). */ clearAutosave(): void; /** * Return the most recent save (by timestamp), or `null` if none. Used * by the startup dialog to offer a "continue last game" affordance. */ checkForSavedGame(): SaveSlotMeta | null; /** Return user-visible saves (everything but the autosave slot). */ getUserSaves(): SaveSlotMeta[]; } //# sourceMappingURL=SaveManager.d.ts.map