Skip to content

Commit

Permalink
Works now
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherJMiller committed Jul 15, 2023
1 parent fc746e2 commit 99fab03
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
3 changes: 1 addition & 2 deletions Justfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

install-global-deps:
cargo install wasm-bindgen-cli@0.2.87
cargo install wasm-bindgen-cli

serve: build-client
yarn workspace web dev
Expand All @@ -23,4 +23,3 @@ client-wasm-bindgen: build-wasm

build-wasm:
cargo build -p game --lib --profile wasm-release --target wasm32-unknown-unknown

16 changes: 12 additions & 4 deletions web/src/Game.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
import { useEffect, useState } from "react";
import { Button } from "./components/Button";

const Game = () => {
const [gameLoaded, setGameLoaded] = useState(false);
const [loading, setLoading] = useState(false);
const [startGame, setStartGame] = useState(false);

useEffect(() => {
const run = async () => {
console.log("Loading bevy");
setLoading(true);
const { main } = await import("./game");
setGameLoaded(true);
setLoading(false);
main();
};

if (!gameLoaded && !loading) {
if (startGame) {
run();
}
}, [gameLoaded]);
}, [startGame]);

const joinForm = !startGame ? (
<div className="flex flex-col gap-3">
<Button disabled={false} text="Join Server" onClick={() => setStartGame(true)} />
</div>
) : null;

const statusText = loading ? <h1 className="text-4xl text-center my-4">Loading Game...</h1> : null;

return (
<>
{joinForm}
{statusText}
<canvas className="bevy-instance__canvas" id="bevy" onContextMenu={(e) => e.preventDefault()}></canvas>
</>
Expand Down
12 changes: 12 additions & 0 deletions web/src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

interface ButtonProps {
text: string;
disabled: boolean;
onClick: () => void;
}

export const Button = ({ text, disabled, onClick }: ButtonProps) => {
return (
<div className={`${disabled ? "italic" : "hover:cursor-pointer hover:bg-teal-600 active:bg-teal-800"} bg-teal-500 rounded-md text-center px-3 p-2`} onClick={() => !disabled ? onClick() : null}>{text}</div>
)
};

0 comments on commit 99fab03

Please sign in to comment.