// Web stand-in for the desktop iopman.js (IOP Manager sessions). The packs of the opened game folder // are registered as sessions, so every tool that works with "a pack open in IOP Manager" (UI image // sets: Load, texture source "packs next to …") works with the game folder. The web IOP Manager // (PLAN phase 8b) will add its own packs here too. // Session ids are numbers, like the desktop's: the renderer does Number(select.value). const registry = new Map(); // id -> { id, name, file, pack, key, game } const idOfFile = new Map(); // lower file path -> id (stable while the page is open) let nextId = 1; /** Replace the game folder's packs: [{ name, file, pack, key }] (key = detected profile or null). */ export function setGamePacks(list) { for (const [id, s] of [...registry]) if (s.game) registry.delete(id); for (const p of list) { const k = p.file.toLowerCase(); if (!idOfFile.has(k)) idOfFile.set(k, nextId++); const id = idOfFile.get(k); registry.set(id, { id, game: true, ...p }); } } /** Same shape as the desktop: { id, name, file, encrypted, detected, profileId }. */ export function sessions() { return [...registry.values()].map((s) => ({ id: s.id, name: s.name, file: s.file, encrypted: !!s.encrypted, detected: !!s.key, profileId: s.key ? s.key.id : null, entries: s.pack.liveEntries().length, })); } /** { pack, password (type 0 of the detected key), file } of a session. */ export function handle(id) { const s = registry.get(Number(id)); if (!s) throw new Error("That pack is not open any more. Open the game folder again."); return { pack: s.pack, password: s.key ? s.key.passwords[0] : null, file: s.file }; } export async function addData() { throw new Error("Saving into packs is not available yet."); } export const replaceData = addData; export default { sessions, handle, addData, replaceData, setGamePacks };