import Slider from "@/components/slider"; import { Color, EngineName } from "@/types/enums"; import { MenuItem, Select, Button, Dialog, DialogTitle, DialogContent, FormControl, InputLabel, OutlinedInput, DialogActions, Typography, Grid2 as Grid, FormGroup, FormControlLabel, Switch, } from "@mui/material"; import { useAtomLocalStorage } from "@/hooks/useAtomLocalStorage"; import { useAtom, useSetAtom } from "jotai"; import { engineEloAtom, playerColorAtom, isGameInProgressAtom, gameAtom, enginePlayNameAtom, } from "../states"; import { useChessActions } from "@/hooks/useChessActions"; import { playGameStartSound } from "@/lib/sounds"; import { logAnalyticsEvent } from "@/lib/firebase"; import { useEffect } from "react"; import { isEngineSupported } from "@/lib/engine/shared"; import { Stockfish16_1 } from "@/lib/engine/stockfish16_1"; import { engineLabel } from "@/sections/engineSettings/engineSettingsDialog"; interface Props { open: boolean; onClose: () => void; } export default function GameSettingsDialog({ open, onClose }: Props) { const [engineElo, setEngineElo] = useAtomLocalStorage( "engine-elo", engineEloAtom ); const [engineName, setEngineName] = useAtomLocalStorage( "engine-play-name", enginePlayNameAtom ); const [playerColor, setPlayerColor] = useAtom(playerColorAtom); const setIsGameInProgress = useSetAtom(isGameInProgressAtom); const { reset: resetGame } = useChessActions(gameAtom); const handleGameStart = () => { onClose(); resetGame({ whiteName: playerColor === Color.White ? "You" : engineLabel[engineName].small, blackName: playerColor === Color.Black ? "You" : engineLabel[engineName].small, }); playGameStartSound(); setIsGameInProgress(true); logAnalyticsEvent("play_game", { engine: engineName, engineElo, playerColor, }); }; useEffect(() => { if (!isEngineSupported(engineName)) { if (Stockfish16_1.isSupported()) { setEngineName(EngineName.Stockfish16_1Lite); } else { setEngineName(EngineName.Stockfish11); } } }, [setEngineName, engineName]); return ( Set game parameters Stockfish 17 Lite is the default engine if your device support its requirements. It offers the best balance between speed and strength. Stockfish 17 is the strongest engine available, note that it requires a one time download of 75MB. Bot's engine { setPlayerColor( e.target.checked ? Color.White : Color.Black ); }} /> } label={ playerColor === Color.White ? "You play as White" : "You play as Black" } /> ); }