From 552902b803c7c1ae6098129cefb014ddb4dd0979 Mon Sep 17 00:00:00 2001 From: pb-coding <71174645+pb-coding@users.noreply.github.com> Date: Mon, 25 Sep 2023 15:53:03 +0200 Subject: [PATCH] adds endgame --- src/App.tsx | 14 +++++--------- src/components/Footer.tsx | 23 +++++++++++------------ src/components/GameCanvas.tsx | 25 ++++++++++++------------- src/components/Indicators.tsx | 9 +++++++++ src/components/SessionManager.tsx | 7 +++++++ src/types/gameTypes.ts | 1 + 6 files changed, 45 insertions(+), 34 deletions(-) create mode 100644 src/components/Indicators.tsx diff --git a/src/App.tsx b/src/App.tsx index 144661d..4a5475b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -22,7 +22,7 @@ export default function App() { setMessageDisplay(message); setTimeout(() => { setMessageDisplay(""); - }, 800); + }, 3000); } useEffect(() => { @@ -39,12 +39,7 @@ export default function App() { } function onMessageEvent(message: string) { - if ( - message.includes(" won ") || - message.includes(" equally ") || - message.includes(" doubled ") - ) - setTempMessage(message); + setTempMessage(message); // setMessageEvents((previous) => [...previous, message]); } @@ -73,6 +68,7 @@ export default function App() {
{!gameData && ( - {session !== "" && ( + {gameData && session !== "" && (
- {playerData.map((player) => ( + {gameData.players.map((player) => (
{player?.name} {player.socketId == socket.id && "👤"}{" "} {player.playersTurn && } + {isEndOfGame && player.place == 1 && "🏆"}

diff --git a/src/components/GameCanvas.tsx b/src/components/GameCanvas.tsx index c165951..74b2086 100644 --- a/src/components/GameCanvas.tsx +++ b/src/components/GameCanvas.tsx @@ -1,7 +1,7 @@ import { FC } from "react"; import { Object3D, Mesh } from "three"; 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 { Game } from "../types/gameTypes"; @@ -14,6 +14,8 @@ type GameCanvasProps = { const GameCanvas: FC = ({ gameData }) => { const tableModel = useGLTF("/models/table.glb"); const heightProportion = 1.4; + const aspectRatio = + window.innerWidth / (window.innerHeight / heightProportion); if (!gameData) return null; @@ -24,17 +26,15 @@ const GameCanvas: FC = ({ gameData }) => { height: window.innerHeight / heightProportion, }} > - - new Vector3(0, 20, 0)} - /> + = ({ gameData }) => { /> -
diff --git a/src/components/Indicators.tsx b/src/components/Indicators.tsx new file mode 100644 index 0000000..d3177ca --- /dev/null +++ b/src/components/Indicators.tsx @@ -0,0 +1,9 @@ +import { FC } from "react"; + +export const ConnectedIndicator: FC = () => ( + +); + +export const DisconnectedIndicator: FC = () => ( + +); diff --git a/src/components/SessionManager.tsx b/src/components/SessionManager.tsx index 245271d..83ed160 100644 --- a/src/components/SessionManager.tsx +++ b/src/components/SessionManager.tsx @@ -1,9 +1,11 @@ import { Dispatch, FC, SetStateAction, useState } from "react"; import { socket } from "../socket"; +import { ConnectedIndicator, DisconnectedIndicator } from "./Indicators"; import Button from "../global/Button"; type SessionManagerProps = { + isConnected: boolean; clientsInRoom: number; setClientsInRoom: Dispatch>; session: string; @@ -12,6 +14,7 @@ type SessionManagerProps = { }; export const SessionManager: FC = ({ + isConnected, clientsInRoom, setClientsInRoom, session, @@ -89,6 +92,10 @@ export const SessionManager: FC = ({ Leave Session )} +
+ Game Server: + {isConnected ? : } +
diff --git a/src/types/gameTypes.ts b/src/types/gameTypes.ts index 1ced9bf..8336f2c 100644 --- a/src/types/gameTypes.ts +++ b/src/types/gameTypes.ts @@ -12,6 +12,7 @@ export type Player = { roundPoints: number; totalPoints: number; closedRound: boolean; + place: number; }; export type PlayerWithVisualCards = {