Files
Pac-Man/web/pages/+onPageTransitionStart.ts
Xevion 5e86bbb040 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
2025-12-29 02:06:15 -06:00

15 lines
529 B
TypeScript

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();
}
};