feat : add click on engine lines
This commit is contained in:
@@ -67,7 +67,7 @@ export const useChessActions = (chessAtom: PrimitiveAtom<Chess>) => {
|
||||
[copyGame, setGame]
|
||||
);
|
||||
|
||||
const makeMove = useCallback(
|
||||
const playMove = useCallback(
|
||||
(params: {
|
||||
from: string;
|
||||
to: string;
|
||||
@@ -92,6 +92,18 @@ export const useChessActions = (chessAtom: PrimitiveAtom<Chess>) => {
|
||||
[copyGame, setGame]
|
||||
);
|
||||
|
||||
const addMoves = useCallback(
|
||||
(moves: string[]) => {
|
||||
const newGame = copyGame();
|
||||
|
||||
for (const move of moves) {
|
||||
newGame.move(move);
|
||||
}
|
||||
setGame(newGame);
|
||||
},
|
||||
[copyGame, setGame]
|
||||
);
|
||||
|
||||
const undoMove = useCallback(() => {
|
||||
const newGame = copyGame();
|
||||
const move = newGame.undo();
|
||||
@@ -127,9 +139,10 @@ export const useChessActions = (chessAtom: PrimitiveAtom<Chess>) => {
|
||||
return {
|
||||
setPgn,
|
||||
reset,
|
||||
makeMove,
|
||||
playMove,
|
||||
undoMove,
|
||||
goToMove,
|
||||
resetToStartingPosition,
|
||||
addMoves,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user