From 58323a58d4ee0f33e83cbd197af84a32c9c999d4 Mon Sep 17 00:00:00 2001 From: tannerkrewson Date: Sat, 23 Jan 2021 11:00:09 -0600 Subject: [PATCH] seperate player and host in connectToGame --- components/in-game/GameFrame.tsx | 60 ++++------------------- config/games/_protobowl.ts | 2 +- config/games/_setwithfriends.ts | 2 +- config/games/_template.ts | 82 +++++++++++++++++++++----------- config/games/alenros.ts | 2 +- config/games/codenames.ts | 2 +- config/games/cosel.ts | 2 +- config/games/drawphone.ts | 8 ++-- config/games/fishbowl.ts | 4 +- config/games/justone.ts | 4 +- config/games/longwave.ts | 2 +- config/games/netgamesio.ts | 2 +- config/games/qwiqwit.ts | 8 ++-- config/games/snakeout.ts | 8 ++-- config/games/spyfall.ts | 2 +- server/rocketcrab.ts | 12 ++--- test/server/rocketcrab.test.ts | 13 ++--- types/types.ts | 14 ++++-- utils/useConnectedGame.ts | 42 ++++++++++++++++ 19 files changed, 152 insertions(+), 119 deletions(-) create mode 100644 utils/useConnectedGame.ts diff --git a/components/in-game/GameFrame.tsx b/components/in-game/GameFrame.tsx index 694399c..cd4e5b1 100644 --- a/components/in-game/GameFrame.tsx +++ b/components/in-game/GameFrame.tsx @@ -1,6 +1,7 @@ import { GameStatus } from "../../types/enums"; import { Loading } from "@geist-ui/react"; import { ClientGame, GameState, Player } from "../../types/types"; +import { useConnectedGame } from "../../utils/useConnectedGame"; const GameFrame = ({ gameState, @@ -9,54 +10,18 @@ const GameFrame = ({ thisPlayer, frameRefreshCount, }: GameFrameProps): JSX.Element => { - const { - status, - joinGameURL: { - playerURL, - hostURL, - customQueryParams, - afterQueryParams, - }, - } = gameState; + const { status, connectedGame } = gameState; - const { renameParams } = thisGame; - const { name, isHost } = thisPlayer; + const { isHost } = thisPlayer; - const paramKeys = { - rocketcrab: "rocketcrab", - name: "name", - ishost: "ishost", - ...renameParams, - }; - - const defaultParams = { - rocketcrab: "true", - name, - ishost: isHost.toString(), - }; - - const params = { - ...Object.keys(paramKeys).reduce( - (acc, name) => ({ - ...acc, - [paramKeys[name]]: defaultParams[name], - }), - {} - ), - ...customQueryParams, - }; - - const appendToUrl = - "?" + new URLSearchParams(params).toString() + (afterQueryParams ?? ""); + const gameUrl = useConnectedGame(connectedGame, thisGame, thisPlayer); const showLoading = status === GameStatus.loading; const showError = status === GameStatus.error; const showWaitingForHost = !isHost && status === GameStatus.waitingforhost; - const showGameFrame = !isHost && status === GameStatus.inprogress; - const showHostGameFrame = - isHost && - (status === GameStatus.inprogress || - status === GameStatus.waitingforhost); + const showGameFrame = + (isHost && status === GameStatus.waitingforhost) || + status === GameStatus.inprogress; return ( <> @@ -123,16 +88,9 @@ const GameFrame = ({ {showGameFrame && ( - )} - {showHostGameFrame && ( - )}