Ver Fonte

Renaming a few more things for clarity

Kirk Trombley há 5 anos atrás
pai
commit
3e8956cd5e

+ 5 - 6
client/src/components/Game.jsx

@@ -8,7 +8,7 @@ import {
   ERROR,
 } from "../domain/GameState";
 import PreGame from "./screens/PreGame";
-import PreRound from "./screens/PreRound";
+import Lobby from "./screens/Lobby";
 import GamePanel from "./screens/GamePanel";
 import RoundSummary from "./screens/RoundSummary";
 import PlayerScores from "./screens/PlayerScores";
@@ -16,7 +16,7 @@ import { useGameState, dispatch } from "../domain/gameStore";
 
 const componentMap = {
   [PRE_GAME]: PreGame,
-  [PRE_ROUND]: PreRound,
+  [PRE_ROUND]: Lobby,
   [IN_ROUND]: GamePanel,
   [POST_ROUND]: RoundSummary,
   [POST_GAME]: PlayerScores,
@@ -24,8 +24,8 @@ const componentMap = {
 }
 
 const paramRouter = {
-  join: dispatch.startGame,
-  summary: dispatch.endGame,
+  join: dispatch.goToLobby,
+  summary: dispatch.goToSummary,
 }
 
 const Game = () => {
@@ -37,8 +37,7 @@ const Game = () => {
     if (route) {
       url.searchParams.delete(param);
       window.history.replaceState({}, document.title, url.href);
-      dispatch.setGameId(value);
-      route();
+      route(value);
       break;
     }
   }

+ 1 - 1
client/src/components/screens/GamePanel/GamePanel.jsx

@@ -35,7 +35,7 @@ const GamePanelContainer = () => {
   const [finished, roundInfo] = useRoundInfo();
 
   if (finished) {
-    dispatch.endGame();
+    dispatch.goToSummary();
     return <Loading/>
   }
 

+ 2 - 2
client/src/components/screens/PreRound/PreRound.jsx → client/src/components/screens/Lobby/Lobby.jsx

@@ -103,7 +103,7 @@ const JoinForm = () => {
   );
 }
 
-const PreRound = ({ onStart }) => {
+const Lobby = ({ onStart }) => {
   const joined = useGameJoined();
 
   return (
@@ -120,4 +120,4 @@ const PreRound = ({ onStart }) => {
   )
 };
 
-export default PreRound;
+export default Lobby;

+ 0 - 0
client/src/components/screens/PreRound/LobbyPlayerList.jsx → client/src/components/screens/Lobby/LobbyPlayerList.jsx


+ 1 - 0
client/src/components/screens/Lobby/index.js

@@ -0,0 +1 @@
+export { default } from './Lobby';

+ 1 - 1
client/src/components/screens/PreGame/PreGame.jsx

@@ -41,7 +41,7 @@ export default () => {
 
   const onCreateGame = async () => {
     setLoading(true);
-    await dispatch.createGameAndStart(timer);
+    await dispatch.createGame(timer);
   };
   const cannotCreateGame = !playerName || playerName.length === 0;
 

+ 0 - 1
client/src/components/screens/PreRound/index.js

@@ -1 +0,0 @@
-export { default } from './PreRound';

+ 16 - 8
client/src/domain/gameStore.js

@@ -30,13 +30,12 @@ export const [
   gameJoined: false,
   gameState: PRE_GAME,
 }, {
-  setGameId: ([set], gameId) => set({ gameId }),
   setPlayerName: ([set], playerName) => set({ playerName }),
-  resetGame: ([set]) => set({ gameJoined: false, gameState: PRE_GAME }),
-  startGame: ([set]) => set({ gameState: PRE_ROUND }),
-  startRound: ([set]) => set({ gameState: IN_ROUND }),
-  endGame: ([set]) => set({ gameState: POST_GAME }),
-  createGameAndStart: async ([set, get], timer) => {
+  goToLobby: ([set, get], gameId) => set({
+    gameId: gameId || get.gameId(),
+    gameState: PRE_ROUND,
+  }),
+  createGame: async ([set, get], timer) => {
     const name = get.playerName();
     const gameId = await createGame(name, timer);
     set({ gameId, gameJoined: true, gameState: PRE_ROUND });
@@ -47,6 +46,7 @@ export const [
     await joinGame(gameId, name);
     set({ gameJoined: true });
   },
+  startRound: ([set]) => set({ gameState: IN_ROUND }),
   submitGuess: async ([set, get], selectedPoint) => {
     const gameId = get.gameId();
     const name = get.playerName();
@@ -54,7 +54,7 @@ export const [
     const { score, totalScore } = await sendGuess(
       gameId,
       name,
-      currentRound, 
+      currentRound,
       selectedPoint || { timeout: true }
     );
     set({
@@ -67,5 +67,13 @@ export const [
       },
       gameState: POST_ROUND,
     });
-  }
+  },
+  goToSummary: ([set, get], gameId) => set({
+    gameId: gameId || get.gameId(),
+    gameState: POST_GAME,
+  }),
+  resetGame: ([set]) => set({
+    gameJoined: false,
+    gameState: PRE_GAME,
+  }),
 });