LINE1 10 20 30 40 50 60 70 801// Save slots kept in localStorage. Each slot holds one JSON document: a small2// label for the slot list, and the session state needed to resume play.34exportconst SAVE_SLOTS = 3;5exportconst SAVE_VERSION = 1;67const KEY_PREFIX = 'torment.save.';89functionstorage() {10try {11return window.localStorage;12 } catch {13returnnull;14 }15}1617/** The stored record for a slot, or null when it is empty or unreadable. */18exportfunctionreadSlot(slot) {19const store = storage();20if (!store) returnnull;21let raw = null;22try {23 raw = store.getItem(KEY_PREFIX + slot);24 } catch {25returnnull;26 }27if (!raw) returnnull;28try {29const record = JSON.parse(raw);30if (record?.version !== SAVE_VERSION || !record.state || !record.label) returnnull;31return record;32 } catch {33returnnull;34 }35}3637exportfunctionwriteSlot(slot, state, label) {38const store = storage();39if (!store) thrownewError('Saving needs browser storage, which is turned off.');40const record = {41 version: SAVE_VERSION,42 savedAt: newDate().toISOString(),43 label,44 state,45 };46try {47 store.setItem(KEY_PREFIX + slot, JSON.stringify(record));48 } catch {49thrownewError('The game could not write the save. Browser storage may be full.');50 }51return record;52}