import ms from "pretty-ms";
import { useCallback, useState } from "react";
import { createGame } from "../../../domain/apiMethods";
import {
COUNTRY_RACE,
DISTANCE,
HARD,
FROZEN,
NORMAL,
RACE,
RANDOM_STREET_VIEW,
TIME_BANK,
URBAN,
NIGHTMARE,
RAMP,
RAMP_HARD,
} from "../../../domain/constants";
import useCountryLookup from "../../../hooks/useCountryLookup";
import Loading from "../Loading";
import { CountryDropdown, Dropdown, DropdownGroup, Item } from "./Dropdown";
import ErrorModal from "./ErrorModal";
import styles from "./GameCreationForm.module.css";
const DEFAULTS = {
timer: 300,
rounds: 5,
countryLock: null,
generationMethod: RANDOM_STREET_VIEW,
gameMode: NORMAL,
clockMode: NORMAL,
scoreMethod: DISTANCE,
roundPointCap: null,
};
const PRESETS = {
URBAN_AMERICA: {
...DEFAULTS,
generationMethod: URBAN,
countryLock: "us",
},
URBAN_GLOBAL: {
...DEFAULTS,
generationMethod: URBAN,
},
FAST_FROZEN: {
...DEFAULTS,
timer: 30,
rounds: 3,
generationMethod: RANDOM_STREET_VIEW,
gameMode: FROZEN,
},
COUNTRY_RACE: {
...DEFAULTS,
scoreMethod: COUNTRY_RACE,
},
FROZEN_COUNTRY_RACE: {
...DEFAULTS,
timer: 30,
gameMode: FROZEN,
scoreMethod: COUNTRY_RACE,
},
BOOTLEG_GG_DUEL: {
...DEFAULTS,
clockMode: RACE,
scoreMethod: RAMP,
},
};
export const LastSettingsButton = ({ onClick }) => (
{
if (key === "Enter") {
onClick();
}
}}
title="Reuse Previous Game Settings"
>
♻️
);
const GameCreationForm = ({ afterCreate, lastSettings = null }) => {
const [loading, setLoading] = useState(false);
const [creationError, setCreationError] = useState(false);
const [timer, setTimer] = useState(DEFAULTS.timer);
const [rounds, setRounds] = useState(DEFAULTS.rounds);
const [countryLock, setCountryLock] = useState(DEFAULTS.countryLock);
const [generationMethod, setGenMethod] = useState(DEFAULTS.generationMethod);
const [gameMode, setGameMode] = useState(DEFAULTS.gameMode);
const [clockMode, setClockMode] = useState(DEFAULTS.clockMode);
const [scoreMethod, setScoreMethod] = useState(DEFAULTS.scoreMethod);
const [roundPointCap, setRoundPointCap] = useState(DEFAULTS.roundPointCap);
const countryLookup = useCountryLookup(generationMethod);
const [presetOpen, setPresetOpen] = useState(false);
const setPreset = useCallback(
({
timer: newTimer,
rounds: newRounds,
countryLock: newCountryLock,
generationMethod: newGenMethod,
gameMode: newGameMode,
clockMode: newClockMode,
scoreMethod: newScoreMethod,
roundPointCap: newRoundPointCap,
}) => {
setTimer(newTimer);
setRounds(newRounds);
setCountryLock(newCountryLock);
setGenMethod(newGenMethod);
setGameMode(newGameMode);
setClockMode(newClockMode);
setScoreMethod(newScoreMethod);
setRoundPointCap(newRoundPointCap);
},
[]
);
if (loading || countryLookup === null) {
return ;
}
const onCreateGame = async () => {
setLoading(true);
let gameId;
try {
gameId = await createGame(
timer,
rounds,
countryLock,
generationMethod,
gameMode,
clockMode,
scoreMethod,
roundPointCap
);
} catch (e) {
setCreationError(true);
setLoading(false);
return;
}
if (afterCreate) {
afterCreate(gameId);
}
};
return (
setCreationError(false)}
/>
setPresetOpen(o => !o)}
onSelect={v => {
setPresetOpen(false);
setPreset(v);
}}
open={presetOpen}
>
-
Default
-
Urban America
-
Urban Global
-
Fast Frozen
-
Country Race
-
Frozen Country Race
-
Legally Distinct from Geoguessr Duels
{lastSettings && (
setPreset(lastSettings)} />
)}
New Game
-
30 Seconds
-
2 Minutes
-
5 Minutes
-
1 Hour
- 1 Round
- 3 Rounds
- 5 Rounds
- 10 Rounds
-
Random Street View
-
Urban Centers
-
Normal
-
Frozen
-
Standard
-
Time Bank
-
Duel
-
Distance
-
Ramping
-
Country Race
-
Hard Mode
-
Ramping Hard Mode
-
Nightmare Mode
-
No Limit
-
10k Total Points per Round
-
20k Total Points per Round
);
};
export default GameCreationForm;