Squashed commit of the following:

commit dfc79cf287823383a25a650d5788ee5250b1c316
Author: GuillaumeSD <47183782+GuillaumeSD@users.noreply.github.com>
Date:   Sun May 11 01:32:35 2025 +0200

    fix : style

commit bccfa5a3358302c2f037cc2dcfbd0a1df5e2974e
Author: GuillaumeSD <47183782+GuillaumeSD@users.noreply.github.com>
Date:   Sun May 11 01:01:12 2025 +0200

    feat : players clocks v1

commit 5f65009f200686433904710d5f9ceb1ba166fa9d
Author: GuillaumeSD <47183782+GuillaumeSD@users.noreply.github.com>
Date:   Sat May 10 21:58:02 2025 +0200

    fix : merge issues

commit f93dc6104e2d3fbb60088f578c2d1f13bf6519e9
Merge: a9f3728 fea1f3f
Author: GuillaumeSD <47183782+GuillaumeSD@users.noreply.github.com>
Date:   Sat May 10 21:53:11 2025 +0200

    Merge branch 'main' into feat/add-players-clocks

commit a9f372808ef403dfb823c4cf93c837412cc55c53
Author: GuillaumeSD <gsd.lfny@gmail.com>
Date:   Mon Jan 6 23:10:28 2025 +0100

    fix : rename

commit aedf9c252023bebe4da4327b7526371fa75b7b3e
Author: GuillaumeSD <gsd.lfny@gmail.com>
Date:   Sun Jan 5 17:30:27 2025 +0100

    feat : add players clocks
This commit is contained in:
GuillaumeSD
2025-05-11 01:33:10 +02:00
parent fea1f3fe47
commit 74a2adbb7d
17 changed files with 169 additions and 57 deletions

View File

@@ -28,7 +28,7 @@ export default function BoardContainer() {
return Math.min(width, height - 150);
}
return Math.min(width - 700, height * 0.95);
return Math.min(width - 700, height * 0.92);
}, [screenSize]);
return (

View File

@@ -42,9 +42,20 @@ export const useCurrentPosition = (engineName?: EngineName) => {
if (gameEval) {
const evalIndex = boardHistory.length;
position.eval = gameEval.positions[evalIndex];
position.eval = {
...gameEval.positions[evalIndex],
lines: gameEval.positions[evalIndex].lines.slice(0, multiPv),
};
position.lastEval =
evalIndex > 0 ? gameEval.positions[evalIndex - 1] : undefined;
evalIndex > 0
? {
...gameEval.positions[evalIndex - 1],
lines: gameEval.positions[evalIndex - 1].lines.slice(
0,
multiPv
),
}
: undefined;
}
}
@@ -70,11 +81,12 @@ export const useCurrentPosition = (engineName?: EngineName) => {
(savedEval.lines?.length ?? 0) >= multiPv &&
(savedEval.lines[0].depth ?? 0) >= depth
) {
setPartialEval?.({
const positionEval: PositionEval = {
...savedEval,
lines: savedEval.lines.slice(0, multiPv),
});
return savedEval;
};
setPartialEval?.(positionEval);
return positionEval;
}
const rawPositionEval = await engine.evaluatePositionWithUpdate({

View File

@@ -12,7 +12,10 @@ export default function Opening() {
}
if (!lastMove) return null;
const opening = position?.eval?.opening || lastOpening;
const opening =
position?.eval?.opening && !position?.eval?.opening.includes("Unknown")
? position.eval.opening
: lastOpening;
if (opening && opening !== lastOpening) {
setLastOpening(opening);
}

View File

@@ -12,13 +12,12 @@ import { useGameDatabase } from "@/hooks/useGameDatabase";
import { useAtomValue, useSetAtom } from "jotai";
import { Chess } from "chess.js";
import { useRouter } from "next/router";
import { getStartingFen } from "@/lib/chess";
export default function LoadGame() {
const router = useRouter();
const game = useAtomValue(gameAtom);
const { setPgn: setGamePgn } = useChessActions(gameAtom);
const { reset: resetBoard } = useChessActions(boardAtom);
const { resetToStartingPosition: resetBoard } = useChessActions(boardAtom);
const { gameFromUrl } = useGameDatabase();
const setEval = useSetAtom(gameEvalAtom);
const setBoardOrientation = useSetAtom(boardOrientationAtom);
@@ -26,7 +25,7 @@ export default function LoadGame() {
const resetAndSetGamePgn = useCallback(
(pgn: string) => {
resetBoard({ fen: getStartingFen({ pgn }) });
resetBoard(pgn);
setEval(undefined);
setGamePgn(pgn);
},

View File

@@ -8,11 +8,10 @@ import NextMoveButton from "./nextMoveButton";
import GoToLastPositionButton from "./goToLastPositionButton";
import SaveButton from "./saveButton";
import { useEffect } from "react";
import { getStartingFen } from "@/lib/chess";
export default function PanelToolBar() {
const board = useAtomValue(boardAtom);
const { reset: resetBoard, undoMove: undoBoardMove } =
const { resetToStartingPosition: resetBoard, undoMove: undoBoardMove } =
useChessActions(boardAtom);
const boardHistory = board.history();
@@ -24,7 +23,7 @@ export default function PanelToolBar() {
if (e.key === "ArrowLeft") {
undoBoardMove();
} else if (e.key === "ArrowDown") {
resetBoard({ fen: getStartingFen({ game: board }) });
resetBoard();
}
};
@@ -42,7 +41,7 @@ export default function PanelToolBar() {
<Tooltip title="Reset board">
<Grid>
<IconButton
onClick={() => resetBoard({ fen: getStartingFen({ game: board }) })}
onClick={() => resetBoard()}
disabled={boardHistory.length === 0}
sx={{ paddingX: 1.2, paddingY: 0.5 }}
>

View File

@@ -22,12 +22,16 @@ export default function NextMoveButton() {
const nextMoveIndex = boardHistory.length;
const nextMove = game.history({ verbose: true })[nextMoveIndex];
const comment = game
.getComments()
.find((c) => c.fen === nextMove.after)?.comment;
if (nextMove) {
makeBoardMove({
from: nextMove.from,
to: nextMove.to,
promotion: nextMove.promotion,
comment,
});
}
}, [isButtonEnabled, boardHistory, game, makeBoardMove]);