|
@@ -1,6 +1,6 @@
|
|
|
import { PRE_GAME, PRE_ROUND, IN_ROUND, POST_ROUND, POST_GAME } from "./GameState";
|
|
|
import { createStore } from "../store";
|
|
|
-import { createGame, joinGame } from "./GGSHService";
|
|
|
+import { createGame, joinGame, sendGuess, getCurrentRound } from "./GGSHService";
|
|
|
|
|
|
export const [
|
|
|
{
|
|
@@ -14,7 +14,19 @@ export const [
|
|
|
] = createStore({
|
|
|
gameId: null,
|
|
|
playerName: null,
|
|
|
- lastRound: null,
|
|
|
+ lastRound: {
|
|
|
+ roundNum: -1,
|
|
|
+ selectedPoint: {
|
|
|
+ lat: 0,
|
|
|
+ lng: 0,
|
|
|
+ },
|
|
|
+ targetPoint: {
|
|
|
+ lat: 0,
|
|
|
+ lng: 0,
|
|
|
+ },
|
|
|
+ score: -1,
|
|
|
+ totalScore: -1,
|
|
|
+ },
|
|
|
gameJoined: false,
|
|
|
gameState: PRE_GAME,
|
|
|
}, {
|
|
@@ -25,7 +37,6 @@ export const [
|
|
|
resetGame: ([set]) => set({ gameJoined: false, gameState: PRE_GAME }),
|
|
|
startGame: ([set]) => set({ gameState: PRE_ROUND }),
|
|
|
startRound: ([set]) => set({ gameState: IN_ROUND }),
|
|
|
- endRound: ([set], lastRound) => set({ lastRound, gameState: POST_ROUND }),
|
|
|
endGame: ([set]) => set({ gameState: POST_GAME }),
|
|
|
createGameAndStart: async ([set, get], timer) => {
|
|
|
const name = get.playerName();
|
|
@@ -38,4 +49,25 @@ export const [
|
|
|
await joinGame(gameId, name);
|
|
|
set({ gameJoined: true });
|
|
|
},
|
|
|
+ submitGuess: async ([set, get], selectedPoint) => {
|
|
|
+ const gameId = get.gameId();
|
|
|
+ const name = get.playerName();
|
|
|
+ const { currentRound, coord } = await getCurrentRound(gameId, name);
|
|
|
+ const { score, totalScore } = await sendGuess(
|
|
|
+ gameId,
|
|
|
+ name,
|
|
|
+ currentRound,
|
|
|
+ selectedPoint || { timeout: true }
|
|
|
+ );
|
|
|
+ set({
|
|
|
+ lastRound: {
|
|
|
+ roundNum: currentRound,
|
|
|
+ selectedPoint,
|
|
|
+ targetPoint: coord,
|
|
|
+ score,
|
|
|
+ totalScore,
|
|
|
+ },
|
|
|
+ gameState: POST_ROUND,
|
|
|
+ });
|
|
|
+ }
|
|
|
});
|