/** * The key-value store a save is written to. * * Kept behind an interface so the save logic itself has no engine dependency * and can be tested headlessly. `CocosStorage` is the real implementation; * `MemoryStorage` is the one tests use. */ export interface IStorage { getItem(key: string): string | null; setItem(key: string, value: string): void; removeItem(key: string): void; } /** An in-process store. Used by tests, and as a fallback when storage is unavailable. */ export class MemoryStorage implements IStorage { private readonly _data = new Map(); getItem(key: string): string | null { const value = this._data.get(key); return value === undefined ? null : value; } setItem(key: string, value: string): void { this._data.set(key, value); } removeItem(key: string): void { this._data.delete(key); } /** Test helper: everything currently stored. */ get entries(): ReadonlyMap { return this._data; } }