|
@@ -8,6 +8,7 @@ export const [
|
|
|
usePlayerName,
|
|
|
useLastRound,
|
|
|
useGameJoined,
|
|
|
+ usePlayerId,
|
|
|
useGameState,
|
|
|
},
|
|
|
dispatch,
|
|
@@ -24,6 +25,7 @@ export const [
|
|
|
totalScore: -1,
|
|
|
},
|
|
|
gameJoined: false,
|
|
|
+ playerId: null,
|
|
|
gameState: PRE_GAME,
|
|
|
}, {
|
|
|
setPlayerName: ([set], playerName) => set({ playerName }),
|
|
@@ -31,25 +33,24 @@ export const [
|
|
|
createGame: async ([set, get], timer) => {
|
|
|
const gameId = await createGame(timer);
|
|
|
const name = get.playerName();
|
|
|
- await joinGame(gameId, name);
|
|
|
- set({ gameId, gameJoined: true, gameState: PRE_ROUND });
|
|
|
+ const { playerId } = await joinGame(gameId, name);
|
|
|
+ set({ gameId, gameJoined: true, playerId, gameState: PRE_ROUND });
|
|
|
},
|
|
|
joinGame: async ([set, get]) => {
|
|
|
const gameId = get.gameId();
|
|
|
const name = get.playerName();
|
|
|
- await joinGame(gameId, name);
|
|
|
- set({ gameJoined: true });
|
|
|
+ const { playerId } = await joinGame(gameId, name);
|
|
|
+ set({ gameJoined: true, playerId });
|
|
|
},
|
|
|
startRound: ([set]) => set({ gameState: IN_ROUND }),
|
|
|
submitGuess: async ([set, get], selectedPoint, roundNum, targetPoint) => {
|
|
|
- const gameId = get.gameId();
|
|
|
- const name = get.playerName();
|
|
|
const { score, totalScore } = await sendGuess(
|
|
|
- gameId,
|
|
|
- name,
|
|
|
+ get.gameId(),
|
|
|
+ get.playerId(),
|
|
|
roundNum,
|
|
|
selectedPoint || { timeout: true }
|
|
|
);
|
|
|
+ console.log(score + " " + totalScore);
|
|
|
set({
|
|
|
lastRound: {
|
|
|
roundNum,
|
|
@@ -66,6 +67,7 @@ export const [
|
|
|
}),
|
|
|
resetGame: ([set]) => set({
|
|
|
gameJoined: false,
|
|
|
+ playerId: null,
|
|
|
gameState: PRE_GAME,
|
|
|
}),
|
|
|
});
|