adds endgame
This commit is contained in:
parent
ff4bab18f1
commit
552902b803
6 changed files with 45 additions and 34 deletions
14
src/App.tsx
14
src/App.tsx
|
|
@ -22,7 +22,7 @@ export default function App() {
|
||||||
setMessageDisplay(message);
|
setMessageDisplay(message);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setMessageDisplay("");
|
setMessageDisplay("");
|
||||||
}, 800);
|
}, 3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -39,12 +39,7 @@ export default function App() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function onMessageEvent(message: string) {
|
function onMessageEvent(message: string) {
|
||||||
if (
|
setTempMessage(message);
|
||||||
message.includes(" won ") ||
|
|
||||||
message.includes(" equally ") ||
|
|
||||||
message.includes(" doubled ")
|
|
||||||
)
|
|
||||||
setTempMessage(message);
|
|
||||||
// setMessageEvents((previous) => [...previous, message]);
|
// setMessageEvents((previous) => [...previous, message]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,6 +68,7 @@ export default function App() {
|
||||||
<div className="bg-gray-900 w-screen h-screen">
|
<div className="bg-gray-900 w-screen h-screen">
|
||||||
{!gameData && (
|
{!gameData && (
|
||||||
<SessionManager
|
<SessionManager
|
||||||
|
isConnected={isConnected}
|
||||||
clientsInRoom={clientsInRoom}
|
clientsInRoom={clientsInRoom}
|
||||||
setClientsInRoom={setClientsInRoom}
|
setClientsInRoom={setClientsInRoom}
|
||||||
session={session}
|
session={session}
|
||||||
|
|
@ -82,12 +78,12 @@ export default function App() {
|
||||||
)}
|
)}
|
||||||
<GameCanvas session={session} gameData={gameData} />
|
<GameCanvas session={session} gameData={gameData} />
|
||||||
<MessageDisplay message={messageDispaly} />
|
<MessageDisplay message={messageDispaly} />
|
||||||
{session !== "" && (
|
{gameData && session !== "" && (
|
||||||
<Footer
|
<Footer
|
||||||
isConnected={isConnected}
|
isConnected={isConnected}
|
||||||
session={session}
|
session={session}
|
||||||
clientsInRoom={clientsInRoom}
|
clientsInRoom={clientsInRoom}
|
||||||
playerData={gameData?.players ?? []}
|
gameData={gameData}
|
||||||
showNextGameButton={showNextGameButton}
|
showNextGameButton={showNextGameButton}
|
||||||
setClientsInRoom={setClientsInRoom}
|
setClientsInRoom={setClientsInRoom}
|
||||||
setSession={setSession}
|
setSession={setSession}
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,14 @@ import { socket } from "../socket";
|
||||||
|
|
||||||
import Text from "../global/Text";
|
import Text from "../global/Text";
|
||||||
import Button from "../global/Button";
|
import Button from "../global/Button";
|
||||||
import { Player } from "../types/gameTypes";
|
import { Game } from "../types/gameTypes";
|
||||||
|
import { ConnectedIndicator, DisconnectedIndicator } from "./Indicators";
|
||||||
|
|
||||||
type Footer = {
|
type Footer = {
|
||||||
isConnected: boolean;
|
isConnected: boolean;
|
||||||
session: string;
|
session: string;
|
||||||
clientsInRoom: number;
|
clientsInRoom: number;
|
||||||
playerData: Player[];
|
gameData: Game;
|
||||||
showNextGameButton: boolean;
|
showNextGameButton: boolean;
|
||||||
setClientsInRoom: Dispatch<SetStateAction<number>>;
|
setClientsInRoom: Dispatch<SetStateAction<number>>;
|
||||||
setSession: Dispatch<SetStateAction<string>>;
|
setSession: Dispatch<SetStateAction<string>>;
|
||||||
|
|
@ -20,7 +21,7 @@ type Footer = {
|
||||||
export const Footer: FC<Footer> = ({
|
export const Footer: FC<Footer> = ({
|
||||||
isConnected,
|
isConnected,
|
||||||
session,
|
session,
|
||||||
playerData,
|
gameData,
|
||||||
showNextGameButton,
|
showNextGameButton,
|
||||||
setClientsInRoom,
|
setClientsInRoom,
|
||||||
setSession,
|
setSession,
|
||||||
|
|
@ -35,13 +36,7 @@ export const Footer: FC<Footer> = ({
|
||||||
setSession("");
|
setSession("");
|
||||||
}
|
}
|
||||||
|
|
||||||
const ConnectedIndicator: FC = () => (
|
const isEndOfGame = gameData.phase === "game ended";
|
||||||
<span className="ml-2 flex w-2.5 h-2.5 bg-green-500 rounded-full"></span>
|
|
||||||
);
|
|
||||||
|
|
||||||
const DisconnectedIndicator: FC = () => (
|
|
||||||
<span className="ml-2 flex w-2 h-2 bg-red-500 rounded-full"></span>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|
@ -56,18 +51,22 @@ export const Footer: FC<Footer> = ({
|
||||||
{isConnected ? <ConnectedIndicator /> : <DisconnectedIndicator />}
|
{isConnected ? <ConnectedIndicator /> : <DisconnectedIndicator />}
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-between items-center">
|
<div className="flex justify-between items-center">
|
||||||
{showNextGameButton && <Button onClick={nextGame}>Next Game</Button>}
|
{!isEndOfGame && showNextGameButton && (
|
||||||
|
<Button onClick={nextGame}>Next Game</Button>
|
||||||
|
)}
|
||||||
|
{isEndOfGame && <p className="mr-4">Game is over</p>}
|
||||||
<Button variant="secondary" onClick={() => leaveSession(session)}>
|
<Button variant="secondary" onClick={() => leaveSession(session)}>
|
||||||
Leave
|
Leave
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{playerData.map((player) => (
|
{gameData.players.map((player) => (
|
||||||
<div className="mb-3 pt-2 mt-2 border-t border-gray-600">
|
<div className="mb-3 pt-2 mt-2 border-t border-gray-600">
|
||||||
<div className="flex justify-between items-center">
|
<div className="flex justify-between items-center">
|
||||||
<Text>
|
<Text>
|
||||||
{player?.name} {player.socketId == socket.id && "👤"}{" "}
|
{player?.name} {player.socketId == socket.id && "👤"}{" "}
|
||||||
{player.playersTurn && <span className="text-green-500">⏩</span>}
|
{player.playersTurn && <span className="text-green-500">⏩</span>}
|
||||||
|
{isEndOfGame && player.place == 1 && "🏆"}
|
||||||
</Text>
|
</Text>
|
||||||
<p></p>
|
<p></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { FC } from "react";
|
import { FC } from "react";
|
||||||
import { Object3D, Mesh } from "three";
|
import { Object3D, Mesh } from "three";
|
||||||
import { Canvas } from "@react-three/fiber";
|
import { Canvas } from "@react-three/fiber";
|
||||||
import { OrbitControls, useGLTF, PerspectiveCamera } from "@react-three/drei";
|
import { useGLTF } from "@react-three/drei";
|
||||||
|
|
||||||
import PlayArea from "../components/PlayArea";
|
import PlayArea from "../components/PlayArea";
|
||||||
import { Game } from "../types/gameTypes";
|
import { Game } from "../types/gameTypes";
|
||||||
|
|
@ -14,6 +14,8 @@ type GameCanvasProps = {
|
||||||
const GameCanvas: FC<GameCanvasProps> = ({ gameData }) => {
|
const GameCanvas: FC<GameCanvasProps> = ({ gameData }) => {
|
||||||
const tableModel = useGLTF("/models/table.glb");
|
const tableModel = useGLTF("/models/table.glb");
|
||||||
const heightProportion = 1.4;
|
const heightProportion = 1.4;
|
||||||
|
const aspectRatio =
|
||||||
|
window.innerWidth / (window.innerHeight / heightProportion);
|
||||||
|
|
||||||
if (!gameData) return null;
|
if (!gameData) return null;
|
||||||
|
|
||||||
|
|
@ -24,17 +26,15 @@ const GameCanvas: FC<GameCanvasProps> = ({ gameData }) => {
|
||||||
height: window.innerHeight / heightProportion,
|
height: window.innerHeight / heightProportion,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Canvas>
|
<Canvas
|
||||||
<PerspectiveCamera
|
camera={{
|
||||||
makeDefault
|
position: [0, 43, 10],
|
||||||
manual
|
fov: 75,
|
||||||
fov={75}
|
near: 0.1,
|
||||||
aspect={window.innerWidth / (window.innerHeight / heightProportion)}
|
far: 1000,
|
||||||
near={0.1}
|
aspect: aspectRatio,
|
||||||
far={1000}
|
}}
|
||||||
position={[0, 43, 10]}
|
>
|
||||||
// lookAt={() => new Vector3(0, 20, 0)}
|
|
||||||
/>
|
|
||||||
<ambientLight color={0xa3a3a3} intensity={0.1} />
|
<ambientLight color={0xa3a3a3} intensity={0.1} />
|
||||||
<directionalLight
|
<directionalLight
|
||||||
color={0xffffff}
|
color={0xffffff}
|
||||||
|
|
@ -59,7 +59,6 @@ const GameCanvas: FC<GameCanvasProps> = ({ gameData }) => {
|
||||||
/>
|
/>
|
||||||
<gridHelper args={[100, 100]} />
|
<gridHelper args={[100, 100]} />
|
||||||
<axesHelper args={[5]} />
|
<axesHelper args={[5]} />
|
||||||
<OrbitControls />
|
|
||||||
<PlayArea gameData={gameData} />
|
<PlayArea gameData={gameData} />
|
||||||
</Canvas>
|
</Canvas>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
9
src/components/Indicators.tsx
Normal file
9
src/components/Indicators.tsx
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
import { FC } from "react";
|
||||||
|
|
||||||
|
export const ConnectedIndicator: FC = () => (
|
||||||
|
<span className="ml-2 flex w-2.5 h-2.5 bg-green-500 rounded-full"></span>
|
||||||
|
);
|
||||||
|
|
||||||
|
export const DisconnectedIndicator: FC = () => (
|
||||||
|
<span className="ml-2 flex w-2 h-2 bg-red-500 rounded-full"></span>
|
||||||
|
);
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
import { Dispatch, FC, SetStateAction, useState } from "react";
|
import { Dispatch, FC, SetStateAction, useState } from "react";
|
||||||
import { socket } from "../socket";
|
import { socket } from "../socket";
|
||||||
|
|
||||||
|
import { ConnectedIndicator, DisconnectedIndicator } from "./Indicators";
|
||||||
import Button from "../global/Button";
|
import Button from "../global/Button";
|
||||||
|
|
||||||
type SessionManagerProps = {
|
type SessionManagerProps = {
|
||||||
|
isConnected: boolean;
|
||||||
clientsInRoom: number;
|
clientsInRoom: number;
|
||||||
setClientsInRoom: Dispatch<SetStateAction<number>>;
|
setClientsInRoom: Dispatch<SetStateAction<number>>;
|
||||||
session: string;
|
session: string;
|
||||||
|
|
@ -12,6 +14,7 @@ type SessionManagerProps = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SessionManager: FC<SessionManagerProps> = ({
|
export const SessionManager: FC<SessionManagerProps> = ({
|
||||||
|
isConnected,
|
||||||
clientsInRoom,
|
clientsInRoom,
|
||||||
setClientsInRoom,
|
setClientsInRoom,
|
||||||
session,
|
session,
|
||||||
|
|
@ -89,6 +92,10 @@ export const SessionManager: FC<SessionManagerProps> = ({
|
||||||
Leave Session
|
Leave Session
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
<div className="mt-8 flex justify-center items-center">
|
||||||
|
<span className="text-gray-200">Game Server: </span>
|
||||||
|
{isConnected ? <ConnectedIndicator /> : <DisconnectedIndicator />}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ export type Player = {
|
||||||
roundPoints: number;
|
roundPoints: number;
|
||||||
totalPoints: number;
|
totalPoints: number;
|
||||||
closedRound: boolean;
|
closedRound: boolean;
|
||||||
|
place: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PlayerWithVisualCards = {
|
export type PlayerWithVisualCards = {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue