feat(web): implement game lifecycle management for SPA navigation

Add stop_game and restart_game FFI functions to properly pause/resume the game loop during page transitions, preventing resource leaks and audio issues when navigating between pages
This commit is contained in:
2025-12-29 02:06:15 -06:00
parent 791a0e48e3
commit 5e86bbb040
7 changed files with 148 additions and 26 deletions
+8
View File
@@ -1,6 +1,14 @@
import type { OnPageTransitionStartAsync } from "vike/types";
import { getPacmanWindow } from "@/lib/pacman";
export const onPageTransitionStart: OnPageTransitionStartAsync = async () => {
console.log("Page transition start");
document.querySelector("body")?.classList.add("page-is-transitioning");
// Stop the game loop when navigating away from the game page
const win = getPacmanWindow();
if (win.Module?._stop_game) {
console.log("Stopping game loop for page transition");
win.Module._stop_game();
}
};