diff --git a/DOSBOX_DOOM.ZIP b/DOSBOX_DOOM.ZIP new file mode 100644 index 0000000..be6e0fa Binary files /dev/null and b/DOSBOX_DOOM.ZIP differ diff --git a/frontend/src/pages/Play.svelte b/frontend/src/pages/Play.svelte index 346245a..67a0b6b 100644 --- a/frontend/src/pages/Play.svelte +++ b/frontend/src/pages/Play.svelte @@ -25,7 +25,7 @@ } async function startEmulator() { - if (!dosContainer || !game?.ready || running || started) return; + if (started || !game?.ready || !dosContainer) return; started = true; booting = true; @@ -35,7 +35,7 @@ link.href = "https://v8.js-dos.com/latest/js-dos.css"; document.head.appendChild(link); - // Load js-dos script from CDN if not already loaded + // Load js-dos script from CDN if (!window.Dos) { try { await new Promise((resolve, reject) => { @@ -55,19 +55,16 @@ // Start the DOS emulator try { const url = bundleUrl(game); - if (!url || !window.Dos) { - throw new Error("Failed to resolve game bundle"); - } + if (!url || !window.Dos) throw new Error("Failed to resolve game bundle"); dosCI = await window.Dos(dosContainer, { url }); running = true; } catch (e) { - error = "Failed to start emulator: " + e.message; + error = e.message; } booting = false; } function stopEmulator() { - // Kill the emulator process if (dosCI) { try { dosCI.exit(); } catch (_) {} dosCI = null; @@ -76,21 +73,19 @@ dosContainer.innerHTML = ""; } running = false; - // Navigate back to game detail push(`/game/${game.id}`); } - // Load game data on mount $effect(() => { load(); }); - // Auto-start emulator once game data and DOM are ready + // Auto-start when both game data and the container exist $effect(() => { if (game?.ready && dosContainer && !started) { startEmulator(); } }); - // Cleanup on unmount (navigating away, browser back, etc.) + // Cleanup emulator on component unmount (browser back, nav away) $effect(() => { return () => { if (dosCI) { @@ -100,82 +95,64 @@ if (dosContainer) { dosContainer.innerHTML = ""; } - running = false; }; }); -{#if loading} -
Starting emulator...
-💾 Game saves are stored automatically in your browser
-This game is not ready yet.
- {/if} -💾 Game saves are stored automatically in your browser
-