feat: navigation can cycle through board

This commit is contained in:
latenitecoding 2024-03-02 18:08:48 -06:00 committed by Christoph Lindstädt
parent edf436f198
commit d15b71985e

View file

@ -65,17 +65,22 @@ export const displayMoveInHistory = (
if (typeof variantMoves[moveIndex + offset] !== 'undefined') { if (typeof variantMoves[moveIndex + offset] !== 'undefined') {
moveToDisplay = variantMoves[moveIndex + offset]; moveToDisplay = variantMoves[moveIndex + offset];
} }
if (typeof moveToDisplay === 'undefined') {
moveToDisplay = moves[variant.parentMoveIndex + offset];
}
} else { } else {
if (typeof moves[moveIndex + offset] !== 'undefined') { if (typeof moves[moveIndex + offset] !== 'undefined') {
moveToDisplay = moves[moveIndex + offset]; moveToDisplay = moves[moveIndex + offset];
} }
} }
} else if (offset < 0) {
moveToDisplay = draft.study.moves[draft.study.moves.length - 1];
} else if (offset > 0) {
moveToDisplay = draft.study.moves[0];
}
if (!moveToDisplay) { if (moveToDisplay) {
console.log(`No move to display found`);
return draft;
}
const chess = new Chess(moveToDisplay.after); const chess = new Chess(moveToDisplay.after);
chessView.set({ chessView.set({
@ -92,6 +97,26 @@ export const displayMoveInHistory = (
draft.currentMove = moveToDisplay; draft.currentMove = moveToDisplay;
setChessLogic(chess); setChessLogic(chess);
} else if (offset !== 0){
const chess = draft.study.root.fen ? new Chess(draft.study.root.fen) : new Chess();
chessView.set({
fen: chess.fen(),
check: chess.isCheck(),
movable: {
free: false,
color: toColor(chess),
dests: toDests(chess),
},
turnColor: toColor(chess),
});
draft.currentMove = null;
setChessLogic(chess);
} else {
console.log(`No move to display found`);
return draft;
} }
return draft; return draft;