/** * Heavy-asset loading progress — mirrors the original's heavy-load tracking * (models + texture layers + sticker atlas gate the entrance). Components * report completion via mark(); the overlay reads progress/ready. */ const REQUIRED = [ "model:hello.gltf", "model:cursor.glb", "stickers", "img:about", ] as const; const done = new Set(); const listeners = new Set<() => void>(); let notifyQueued = false; function notify() { if (notifyQueued) return; notifyQueued = true; queueMicrotask(() => { notifyQueued = false; listeners.forEach((l) => l()); }); } function computeSnapshot() { const marked = REQUIRED.filter((k) => done.has(k)).length; return { progress: Math.round((marked / REQUIRED.length) * 100), ready: marked === REQUIRED.length, }; } let currentSnapshot = computeSnapshot(); export const loadingBus = { mark(key: string) { if (!done.has(key)) { done.add(key); currentSnapshot = computeSnapshot(); notify(); } }, /** Safety valve: complete everything (a stalled asset must not soft-lock). */ forceReady() { let changed = false; for (const k of REQUIRED) { if (!done.has(k)) { done.add(k); changed = true; } } if (changed) { currentSnapshot = computeSnapshot(); notify(); } }, getSnapshot() { return currentSnapshot; }, subscribe(listener: () => void) { listeners.add(listener); return () => { listeners.delete(listener); }; }, };