Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 2x 2x 2x 2x 2x 2x 2x 73x 73x 1x 1x 1x 1x 1x 1x 1x 73x 73x 1x 1x 1x 1x 1x 73x 73x 73x 73x 73x 73x 72x 72x | import { game } from './gstate.js';
// storage.js -- Virtual filesystem backed by localStorage.
//
// Each VFS file is stored as a separate localStorage key with a 'vfs:' prefix.
// Example: localStorage['vfs:/home/rodney/notes'] = 'Remember to buy scrolls'
const VFS_PREFIX = 'vfs:';
// Safe localStorage access -- returns null when unavailable (e.g. Node.js tests).
export function setStorageForTesting(mock) { if (game) game.mockStorage = mock; }
function storage() {
if (game?.mockStorage) return game.mockStorage;
try {
if (typeof localStorage === 'undefined') return null;
return localStorage;
} catch (e) { return null; }
}
export function vfsReadFile(path) {
const s = storage();
if (!s) return null;
try {
const v = s.getItem(VFS_PREFIX + path);
return v !== null ? v : null;
} catch (e) { return null; }
}
export function vfsWriteFile(path, content) {
const s = storage();
if (!s) return false;
try { s.setItem(VFS_PREFIX + path, content); return true; }
catch (e) { return false; }
}
export function vfsDeleteFile(path) {
const s = storage();
if (!s) return false;
try {
if (s.getItem(VFS_PREFIX + path) === null) return false;
s.removeItem(VFS_PREFIX + path);
return true;
} catch (e) { return false; }
}
export function vfsListFiles(prefix) {
const s = storage();
if (!s) return [];
try {
const result = [];
for (let i = 0; i < s.length; i++) {
const key = s.key(i);
if (!key || !key.startsWith(VFS_PREFIX)) continue;
const path = key.slice(VFS_PREFIX.length);
if (!prefix || path.startsWith(prefix)) result.push(path);
}
return result;
} catch (e) { return []; }
}
export function init_storage_globals() {
if (game) game.mockStorage = null;
}
|