Squashed commit of the following:

commit 933ba823d5f991b9ab1f66bd94262c181e9d0267
Author: GuillaumeSD <gsd.lfny@gmail.com>
Date:   Mon Apr 21 20:13:37 2025 +0200

    fix : new chessjs version

commit b9376bcbc718f6eaa9a0fd9caada6b957f73b85a
Author: GuillaumeSD <gsd.lfny@gmail.com>
Date:   Mon Apr 21 19:34:12 2025 +0200

    chore : chessjs bump version
This commit is contained in:
GuillaumeSD
2025-04-21 20:14:13 +02:00
parent 06b447dbed
commit 47e52988f3
8 changed files with 32 additions and 21 deletions

View File

@@ -12,6 +12,7 @@ export interface resetGameParams {
fen?: string;
whiteName?: string;
blackName?: string;
noHeaders?: boolean;
}
export const useChessActions = (chessAtom: PrimitiveAtom<Chess>) => {
@@ -29,7 +30,7 @@ export const useChessActions = (chessAtom: PrimitiveAtom<Chess>) => {
const reset = useCallback(
(params?: resetGameParams) => {
const newGame = new Chess(params?.fen);
setGameHeaders(newGame, params);
if (!params?.noHeaders) setGameHeaders(newGame, params);
setGame(newGame);
},
[setGame]
@@ -40,7 +41,10 @@ export const useChessActions = (chessAtom: PrimitiveAtom<Chess>) => {
if (game.history().length === 0) {
const pgnSplitted = game.pgn().split("]");
if (pgnSplitted.at(-1)?.includes("1-0")) {
if (
pgnSplitted.at(-1)?.includes("1-0") ||
pgnSplitted.at(-1) === "\n *"
) {
newGame.loadPgn(pgnSplitted.slice(0, -1).join("]") + "]");
return newGame;
}