-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(web): use routing to start games
- Loading branch information
1 parent
429e3ec
commit 3535c51
Showing
14 changed files
with
196 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
import { FC } from "react"; | ||
import { Routes as NativeRoutes, Route } from "react-router"; | ||
import { FC, Fragment } from "react"; | ||
import { Routes, Route } from "react-router"; | ||
|
||
import { MainMenuComponent } from "./shared/components"; | ||
import { MainLayout } from "./shared/layouts"; | ||
import { HomeRoute } from "./routes/home.route"; | ||
import { PlayRoute } from "./routes/play.route"; | ||
|
||
export const App: FC = () => ( | ||
<> | ||
<NativeRoutes> | ||
<Route index element={<HomeRoute />} /> | ||
</NativeRoutes> | ||
|
||
<MainMenuComponent /> | ||
</> | ||
<Fragment> | ||
<Routes> | ||
<Route path="/" element={<MainLayout />}> | ||
<Route index element={<HomeRoute />} /> | ||
<Route path="/play" element={<PlayRoute />} /> | ||
</Route> | ||
</Routes> | ||
</Fragment> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,32 @@ | ||
import { useMainMenuStore } from "../shared/stores"; | ||
|
||
export const HomeRoute = () => { | ||
const { openMenu } = useMainMenuStore(); | ||
const { openMenu, openNewGameSection } = useMainMenuStore(); | ||
|
||
return ( | ||
<main className="flex flex-col justify-center items-center h-screen gap-8"> | ||
<div className="flex flex-col justify-center items-center"> | ||
<h1 className="text-4xl"> Chess Dimension </h1> | ||
<p className="text-2xl">Basic 3D chess game built with Three.js </p> | ||
<p className="text-2xl"> | ||
3D chess game built with{" "} | ||
<code className="font-semibold">Three.js</code> | ||
</p> | ||
</div> | ||
|
||
<button | ||
className="transition-colors bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" | ||
onClick={() => openMenu()} | ||
onClick={() => { | ||
openMenu(); | ||
setTimeout(openNewGameSection, 0); | ||
}} | ||
> | ||
Start a new game | ||
</button> | ||
|
||
<small> | ||
Or open the main menu with{" "} | ||
<code className="border rounded p-[1px]">Esc</code> | ||
</small> | ||
</main> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { FC, useCallback, useEffect, useMemo } from "react"; | ||
|
||
import { useGame } from "../shared/hooks"; | ||
import { getGameModeFromUrl } from "../shared/utils"; | ||
import { useLocation } from "react-router"; | ||
|
||
export const PlayRoute: FC = () => { | ||
const location = useLocation(); | ||
|
||
const { state: gameState, init: initGame, dispose: disposeGame } = useGame(); | ||
|
||
useEffect(() => { | ||
if (!gameState.app && !gameState.isPending && !gameState.isReady) { | ||
getGameModeFromUrl(); | ||
initGame(); | ||
} | ||
|
||
return () => { | ||
if (gameState.app && !gameState.isPending && gameState.isReady) | ||
disposeGame(); | ||
}; | ||
}, [disposeGame, gameState, initGame, location]); | ||
|
||
return null; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export enum GameMode { | ||
ai = "AI_MODE", | ||
HUMAN = "HUMAN_MODE", | ||
FREE = "FREE_MODE", | ||
SIMULATION = "SIMULATION_MODE" | ||
human = "HUMAN_MODE", | ||
free = "FREE_MODE", | ||
simulation = "SIMULATION_MODE" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./game.enum"; |
Oops, something went wrong.