feat : set depth & multipv

This commit is contained in:
GuillaumeSD
2024-02-24 01:20:39 +01:00
parent 89ca7d8f13
commit 6156e4a228
13 changed files with 318 additions and 142 deletions

View File

@@ -0,0 +1,55 @@
import { Grid } from "@mui/material";
import LoadGameButton from "../../loadGame/loadGameButton";
import { useCallback, useEffect } from "react";
import { useChessActions } from "@/hooks/useChess";
import {
boardAtom,
boardOrientationAtom,
gameAtom,
gameEvalAtom,
} from "../states";
import { useGameDatabase } from "@/hooks/useGameDatabase";
import { useAtomValue, useSetAtom } from "jotai";
import { Chess } from "chess.js";
export default function LoadGame() {
const game = useAtomValue(gameAtom);
const gameActions = useChessActions(gameAtom);
const boardActions = useChessActions(boardAtom);
const { gameFromUrl } = useGameDatabase();
const setEval = useSetAtom(gameEvalAtom);
const setBoardOrientation = useSetAtom(boardOrientationAtom);
const resetAndSetGamePgn = useCallback(
(pgn: string) => {
boardActions.reset();
setEval(undefined);
setBoardOrientation(true);
gameActions.setPgn(pgn);
},
[boardActions, gameActions, setEval, setBoardOrientation]
);
useEffect(() => {
const loadGame = async () => {
if (!gameFromUrl) return;
const gamefromDbChess = new Chess();
gamefromDbChess.loadPgn(gameFromUrl.pgn);
if (game.history().join() === gamefromDbChess.history().join()) return;
resetAndSetGamePgn(gameFromUrl.pgn);
setEval(gameFromUrl.eval);
};
loadGame();
}, [gameFromUrl, game, resetAndSetGamePgn, setEval]);
if (gameFromUrl) return null;
return (
<Grid item container xs={12} justifyContent="center" alignItems="center">
<LoadGameButton setGame={(game) => resetAndSetGamePgn(game.pgn())} />
</Grid>
);
}