|
@@ -9,7 +9,7 @@ import {
|
|
|
getInfoFromLocalStorage,
|
|
|
} from "./localStorageMethods";
|
|
|
|
|
|
-const [ hooks, createAction ] = createStore({
|
|
|
+const [ hooks, set, get ] = createStore({
|
|
|
gameId: null,
|
|
|
playerName: null,
|
|
|
lastRound: {
|
|
@@ -43,15 +43,15 @@ export const {
|
|
|
usePanoStartPov,
|
|
|
} = hooks;
|
|
|
|
|
|
-const setPlayerName = createAction(([set], playerName) => set({ playerName }));
|
|
|
+const setPlayerName = playerName => set({ playerName });
|
|
|
|
|
|
-const goToLobby = createAction(([set], gameId) => set({
|
|
|
+const goToLobby = gameId => set({
|
|
|
gameId,
|
|
|
playerId: null,
|
|
|
gameState: PRE_ROUND,
|
|
|
-}));
|
|
|
+});
|
|
|
|
|
|
-const updateCurrentRound = createAction(async ([set, get]) => {
|
|
|
+const updateCurrentRound = async () => {
|
|
|
const { currentRound, coord, timer } = await getCurrentRound(
|
|
|
get.gameId(),
|
|
|
get.playerId()
|
|
@@ -63,18 +63,18 @@ const updateCurrentRound = createAction(async ([set, get]) => {
|
|
|
panoStartPov: { heading: 0, pitch: 0 },
|
|
|
roundSeconds: timer,
|
|
|
});
|
|
|
-});
|
|
|
+};
|
|
|
|
|
|
-const joinGameAction = createAction(async ([set, get]) => {
|
|
|
+const joinGameAction = async () => {
|
|
|
const gameId = get.gameId();
|
|
|
const name = get.playerName();
|
|
|
const { playerId } = await joinGame(gameId, name);
|
|
|
set({ playerId });
|
|
|
await updateCurrentRound();
|
|
|
saveGameInfoToLocalStorage(gameId, name, playerId);
|
|
|
-});
|
|
|
+};
|
|
|
|
|
|
-const rejoinGame = createAction(async ([set, get]) => {
|
|
|
+const rejoinGame = async () => {
|
|
|
const { gameId, playerName, playerId, timer, position, pov } = getInfoFromLocalStorage();
|
|
|
set({ gameId, playerName, playerId });
|
|
|
await updateCurrentRound();
|
|
@@ -84,11 +84,11 @@ const rejoinGame = createAction(async ([set, get]) => {
|
|
|
panoStartPov: pov ?? get.panoStartPov(),
|
|
|
gameState: IN_ROUND,
|
|
|
});
|
|
|
-});
|
|
|
+};
|
|
|
|
|
|
-const startRound = createAction(([set]) => set({ gameState: IN_ROUND }));
|
|
|
+const startRound = () => set({ gameState: IN_ROUND });
|
|
|
|
|
|
-const submitGuess = createAction(async ([set, get], selectedPoint) => {
|
|
|
+const submitGuess = async selectedPoint => {
|
|
|
clearRoundInfoFromLocalStorage();
|
|
|
const gameId = get.gameId();
|
|
|
const playerId = get.playerId();
|
|
@@ -114,9 +114,9 @@ const submitGuess = createAction(async ([set, get], selectedPoint) => {
|
|
|
gameState: POST_ROUND,
|
|
|
});
|
|
|
await updateCurrentRound();
|
|
|
-});
|
|
|
+};
|
|
|
|
|
|
-const goToSummary = createAction(([set], gameId, clearSavedGame = true) => {
|
|
|
+const goToSummary = (gameId, clearSavedGame = true) => {
|
|
|
if (gameId) {
|
|
|
set({ gameId });
|
|
|
}
|
|
@@ -125,13 +125,13 @@ const goToSummary = createAction(([set], gameId, clearSavedGame = true) => {
|
|
|
clearRoundInfoFromLocalStorage();
|
|
|
clearGameInfoFromLocalStorage();
|
|
|
}
|
|
|
-});
|
|
|
+};
|
|
|
|
|
|
-const updateRoundSeconds = createAction(([set, get], update) => {
|
|
|
+const updateRoundSeconds = update => {
|
|
|
const roundSeconds = update(get.roundSeconds());
|
|
|
set({ roundSeconds });
|
|
|
saveTimerToLocalStorage(roundSeconds);
|
|
|
-});
|
|
|
+};
|
|
|
|
|
|
export const dispatch = {
|
|
|
setPlayerName,
|