|
@@ -50,33 +50,36 @@ export const [
|
|
|
playerId: null,
|
|
|
gameState: PRE_ROUND,
|
|
|
}),
|
|
|
- joinGame: async ([set, get]) => {
|
|
|
- const gameId = get.gameId();
|
|
|
- const name = get.playerName();
|
|
|
- const { playerId } = await joinGame(gameId, name);
|
|
|
- // TODO pull this chunk out
|
|
|
- const { currentRound, coord, timer } = await getCurrentRound(gameId, playerId);
|
|
|
+ updateCurrentRound: async ([set, get]) => {
|
|
|
+ const { currentRound, coord, timer } = await getCurrentRound(
|
|
|
+ get.gameId(),
|
|
|
+ get.playerId()
|
|
|
+ );
|
|
|
set({
|
|
|
- playerId,
|
|
|
currentRound,
|
|
|
targetPoint: coord,
|
|
|
panoStartPosition: coord,
|
|
|
panoStartPov: { heading: 0, pitch: 0 },
|
|
|
roundSeconds: timer,
|
|
|
});
|
|
|
+ },
|
|
|
+ joinGame: async ([set, get]) => {
|
|
|
+ const gameId = get.gameId();
|
|
|
+ const name = get.playerName();
|
|
|
+ const { playerId } = await joinGame(gameId, name);
|
|
|
+ set({ playerId });
|
|
|
+ await dispatch.updateCurrentRound();
|
|
|
saveGameInfoToLocalStorage(gameId, name, playerId);
|
|
|
},
|
|
|
- rejoinGame: async ([set]) => {
|
|
|
+ rejoinGame: async ([set, get]) => {
|
|
|
const { gameId, playerName, playerId } = getGameInfoFromLocalStorage();
|
|
|
set({ gameId, playerName, playerId });
|
|
|
- const { currentRound, coord, timer } = await getCurrentRound(gameId, playerId);
|
|
|
- const { savedPosition, savedPov, savedTimer } = getRoundInfoFromLocalStorage();
|
|
|
+ await dispatch.updateCurrentRound();
|
|
|
+ const { timer, position, pov } = getRoundInfoFromLocalStorage();
|
|
|
set({
|
|
|
- currentRound,
|
|
|
- targetPoint: coord,
|
|
|
- roundSeconds: savedTimer ?? timer,
|
|
|
- panoStartPosition: savedPosition ?? coord,
|
|
|
- panoStartPov: savedPov ?? { heading: 0, pitch: 0 },
|
|
|
+ roundSeconds: timer ?? get.roundSeconds(),
|
|
|
+ panoStartPosition: position ?? get.panoStartPosition(),
|
|
|
+ panoStartPov: pov ?? get.panoStartPov(),
|
|
|
gameState: IN_ROUND,
|
|
|
});
|
|
|
},
|
|
@@ -102,14 +105,7 @@ export const [
|
|
|
},
|
|
|
gameState: POST_ROUND,
|
|
|
});
|
|
|
- const { currentRound, coord, timer } = await getCurrentRound(gameId, playerId);
|
|
|
- set({
|
|
|
- currentRound,
|
|
|
- targetPoint: coord,
|
|
|
- panoStartPosition: coord,
|
|
|
- panoStartPov: { heading: 0, pitch: 0 },
|
|
|
- roundSeconds: timer,
|
|
|
- });
|
|
|
+ await dispatch.updateCurrentRound();
|
|
|
},
|
|
|
goToSummary: ([set], gameId, clearSavedGame = true) => {
|
|
|
if (gameId) {
|