import { useState, useEffect, useRef } from "react"; import { TheAbstractionEngine, Game } from "../engine"; export interface GameCanvasProps { width: number; height: number; } export const GameCanvas = ({ width, height }: GameCanvasProps) => { const canvasRef = useRef(null); const [_game, setGame] = useState(); useEffect(() => { if (canvasRef.current) { const canvas = canvasRef.current; const ctx = canvas.getContext("2d"); if (ctx) { const game = new Game(); const theAbstractionEngine = new TheAbstractionEngine(game, ctx); theAbstractionEngine.init().then(() => { theAbstractionEngine.play(); setGame(theAbstractionEngine); }); return () => theAbstractionEngine.stop(); } } }, [canvasRef]); return (
); };