diff options
author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-03-07 20:45:47 -0700 |
---|---|---|
committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-03-07 20:45:47 -0700 |
commit | e6e29440563e33bb67e0ad51f9fb6c5c2c3fe809 (patch) | |
tree | 5deaee322ff1a039dc44a3cb52ecc48a671fda2a /src/components | |
parent | 823620b2a6ebb7ece619991e47a37ad46542b69f (diff) | |
download | the-abstraction-engine-e6e29440563e33bb67e0ad51f9fb6c5c2c3fe809.tar.gz the-abstraction-engine-e6e29440563e33bb67e0ad51f9fb6c5c2c3fe809.zip |
level one (applications prototype finished!)
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/GameCanvas.tsx | 33 | ||||
-rw-r--r-- | src/components/Title.tsx | 17 |
2 files changed, 40 insertions, 10 deletions
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<HTMLCanvasElement>(null); const [game, setGame] = useState<TheAbstractionEngine>(); + 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 ( + <div className="centered-game"> + <canvas + id={Miscellaneous.CANVAS_ID} + tabIndex={1} + ref={canvasRef} + width={loading ? 50 : width} + height={loading ? 50 : height} + ></canvas> + {loading && <span className="loading">Loading...</span>} + </div> + ); + } return ( <div className="centered-game"> - <canvas - id={Miscellaneous.CANVAS_ID} - tabIndex={1} - ref={canvasRef} - width={width} - height={height} - ></canvas> + <Title setReady={setReady} /> </div> ); }; diff --git a/src/components/Title.tsx b/src/components/Title.tsx new file mode 100644 index 0000000..99c7584 --- /dev/null +++ b/src/components/Title.tsx @@ -0,0 +1,17 @@ +export interface TitleProps { + setReady: (ready: boolean) => void; +} + +export const Title = ({ setReady }: TitleProps) => { + return ( + <div style={{ textAlign: "center" }}> + <h1>the abstraction engine</h1> + <p>a game based on the lambda calculus</p> + + <br /> + <hr /> + <br /> + <button onClick={() => setReady(true)}>ready</button> + </div> + ); +}; |