From e6e29440563e33bb67e0ad51f9fb6c5c2c3fe809 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Thu, 7 Mar 2024 20:45:47 -0700 Subject: level one (applications prototype finished!) --- src/components/GameCanvas.tsx | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'src/components/GameCanvas.tsx') diff --git a/src/components/GameCanvas.tsx b/src/components/GameCanvas.tsx index 09351e3..b6c585d 100644 --- a/src/components/GameCanvas.tsx +++ b/src/components/GameCanvas.tsx @@ -1,6 +1,7 @@ import { useState, useEffect, useRef } from "react"; import { TheAbstractionEngine, Game } from "../engine"; import { Miscellaneous } from "../engine/config"; +import { Title } from "./Title"; export interface GameCanvasProps { width: number; @@ -10,6 +11,8 @@ export interface GameCanvasProps { export const GameCanvas = ({ width, height }: GameCanvasProps) => { const canvasRef = useRef(null); const [game, setGame] = useState(); + const [ready, setReady] = useState(false); + const [loading, setLoading] = useState(true); useEffect(() => { if (canvasRef.current && !game) { @@ -21,25 +24,35 @@ export const GameCanvas = ({ width, height }: GameCanvasProps) => { theAbstractionEngine.init().then(() => { theAbstractionEngine.play(); - setGame(theAbstractionEngine); - canvas.focus(); + + setGame(theAbstractionEngine); + setLoading(false); }); return () => theAbstractionEngine.stop(); } } - }, [canvasRef]); + }, [canvasRef, ready]); + + if (ready) { + return ( +
+ + {loading && Loading...} +
+ ); + } return (
- + </div> ); }; -- cgit v1.2.3-70-g09d2