|
@@ -1,9 +1,17 @@
|
|
import { useCallback, useState } from "react";
|
|
import { useCallback, useState } from "react";
|
|
-import { dispatch } from "../../../../domain/gameStore";
|
|
|
|
|
|
+import {
|
|
|
|
+ dispatch,
|
|
|
|
+ useCurrentRound,
|
|
|
|
+ useTargetPoint,
|
|
|
|
+} from "../../../../domain/gameStore";
|
|
import ClickMarkerMap from "./ClickMarkerMap";
|
|
import ClickMarkerMap from "./ClickMarkerMap";
|
|
import styles from "./GuessPane.module.css";
|
|
import styles from "./GuessPane.module.css";
|
|
import RoundTimer from "./RoundTimer";
|
|
import RoundTimer from "./RoundTimer";
|
|
|
|
+import GunGame from "./GunGame";
|
|
import { useMapResizeKeybindings } from "./hooks";
|
|
import { useMapResizeKeybindings } from "./hooks";
|
|
|
|
+import { useGameConfig } from "../../../../hooks/useGameInfo";
|
|
|
|
+import { GUN_GAME } from "../../../../domain/constants";
|
|
|
|
+import { checkScore } from "../../../../domain/apiMethods";
|
|
|
|
|
|
const mapSizeOpts = {
|
|
const mapSizeOpts = {
|
|
small: styles["pane--small"],
|
|
small: styles["pane--small"],
|
|
@@ -18,11 +26,30 @@ const GuessPane = () => {
|
|
const [selectedPoint, setSelectedPoint] = useState(null);
|
|
const [selectedPoint, setSelectedPoint] = useState(null);
|
|
const [submitted, setSubmitted] = useState(false);
|
|
const [submitted, setSubmitted] = useState(false);
|
|
const [mapSize, setMapSize] = useState("small");
|
|
const [mapSize, setMapSize] = useState("small");
|
|
|
|
+ const [potentialScore, setPotentialScore] = useState(null);
|
|
|
|
+ const [gunGameBlock, setGunGameBlock] = useState(false);
|
|
|
|
+ const unblock = useCallback(() => setGunGameBlock(false), []);
|
|
const toggleBig = useCallback(() => setMapSize(toggleMapSize("big")), []);
|
|
const toggleBig = useCallback(() => setMapSize(toggleMapSize("big")), []);
|
|
const toggleMed = useCallback(() => setMapSize(toggleMapSize("medium")), []);
|
|
const toggleMed = useCallback(() => setMapSize(toggleMapSize("medium")), []);
|
|
useMapResizeKeybindings(toggleBig);
|
|
useMapResizeKeybindings(toggleBig);
|
|
|
|
+ const { gameMode, scoreMethod } = useGameConfig();
|
|
|
|
+ const targetPoint = useTargetPoint();
|
|
|
|
+ const roundNum = useCurrentRound();
|
|
|
|
|
|
const handleSubmitGuess = async () => {
|
|
const handleSubmitGuess = async () => {
|
|
|
|
+ if (gameMode === GUN_GAME) {
|
|
|
|
+ const { score } = await checkScore(
|
|
|
|
+ selectedPoint,
|
|
|
|
+ targetPoint,
|
|
|
|
+ scoreMethod,
|
|
|
|
+ roundNum
|
|
|
|
+ );
|
|
|
|
+ if (score < 4000) {
|
|
|
|
+ setPotentialScore(score);
|
|
|
|
+ setGunGameBlock(true);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
setSubmitted(true);
|
|
setSubmitted(true);
|
|
if (!submitted) {
|
|
if (!submitted) {
|
|
await dispatch.submitGuess(selectedPoint);
|
|
await dispatch.submitGuess(selectedPoint);
|
|
@@ -30,44 +57,49 @@ const GuessPane = () => {
|
|
};
|
|
};
|
|
|
|
|
|
return (
|
|
return (
|
|
- <div className={`${styles.pane} ${mapSizeOpts[mapSize]}`}>
|
|
|
|
- <button
|
|
|
|
- type="button"
|
|
|
|
- className={styles.submit}
|
|
|
|
- onClick={handleSubmitGuess}
|
|
|
|
- disabled={submitted || selectedPoint === null}
|
|
|
|
- >
|
|
|
|
- Submit Guess
|
|
|
|
- </button>
|
|
|
|
- <ClickMarkerMap onMarkerMoved={setSelectedPoint} />
|
|
|
|
- <RoundTimer onTimeout={handleSubmitGuess} />
|
|
|
|
- <div
|
|
|
|
- className={styles.resize}
|
|
|
|
- onClick={toggleBig}
|
|
|
|
- role="button"
|
|
|
|
- tabIndex="0"
|
|
|
|
- onKeyDown={({ key }) => {
|
|
|
|
- if (key === "Enter") {
|
|
|
|
- toggleBig();
|
|
|
|
- }
|
|
|
|
- }}
|
|
|
|
- >
|
|
|
|
- {mapSize === "small" ? "↗️" : "↙️"}
|
|
|
|
- </div>
|
|
|
|
- <div
|
|
|
|
- className={`${styles.resize} ${styles["resize--medium"]}`}
|
|
|
|
- onClick={toggleMed}
|
|
|
|
- role="button"
|
|
|
|
- tabIndex="0"
|
|
|
|
- onKeyDown={({ key }) => {
|
|
|
|
- if (key === "Enter") {
|
|
|
|
- toggleMed();
|
|
|
|
- }
|
|
|
|
- }}
|
|
|
|
- >
|
|
|
|
- {mapSize === "small" ? "➡️" : "⬅️"}
|
|
|
|
|
|
+ <>
|
|
|
|
+ {gunGameBlock && gameMode === GUN_GAME && (
|
|
|
|
+ <GunGame points={potentialScore} onFinish={unblock} />
|
|
|
|
+ )}
|
|
|
|
+ <div className={`${styles.pane} ${mapSizeOpts[mapSize]}`}>
|
|
|
|
+ <button
|
|
|
|
+ type="button"
|
|
|
|
+ className={styles.submit}
|
|
|
|
+ onClick={handleSubmitGuess}
|
|
|
|
+ disabled={submitted || selectedPoint === null}
|
|
|
|
+ >
|
|
|
|
+ Submit Guess
|
|
|
|
+ </button>
|
|
|
|
+ <ClickMarkerMap onMarkerMoved={setSelectedPoint} />
|
|
|
|
+ <RoundTimer onTimeout={handleSubmitGuess} />
|
|
|
|
+ <div
|
|
|
|
+ className={styles.resize}
|
|
|
|
+ onClick={toggleBig}
|
|
|
|
+ role="button"
|
|
|
|
+ tabIndex="0"
|
|
|
|
+ onKeyDown={({ key }) => {
|
|
|
|
+ if (key === "Enter") {
|
|
|
|
+ toggleBig();
|
|
|
|
+ }
|
|
|
|
+ }}
|
|
|
|
+ >
|
|
|
|
+ {mapSize === "small" ? "↗️" : "↙️"}
|
|
|
|
+ </div>
|
|
|
|
+ <div
|
|
|
|
+ className={`${styles.resize} ${styles["resize--medium"]}`}
|
|
|
|
+ onClick={toggleMed}
|
|
|
|
+ role="button"
|
|
|
|
+ tabIndex="0"
|
|
|
|
+ onKeyDown={({ key }) => {
|
|
|
|
+ if (key === "Enter") {
|
|
|
|
+ toggleMed();
|
|
|
|
+ }
|
|
|
|
+ }}
|
|
|
|
+ >
|
|
|
|
+ {mapSize === "small" ? "➡️" : "⬅️"}
|
|
|
|
+ </div>
|
|
</div>
|
|
</div>
|
|
- </div>
|
|
|
|
|
|
+ </>
|
|
);
|
|
);
|
|
};
|
|
};
|
|
|
|
|