fix : move click

This commit is contained in:
GuillaumeSD
2024-03-26 03:56:32 +01:00
parent cd514d90cf
commit 410a794308

View File

@@ -60,7 +60,7 @@ export default function Board({
setClickedSquares([]); setClickedSquares([]);
}, [gameFen, setClickedSquares]); }, [gameFen, setClickedSquares]);
const isPieceDraggable = useCallback( const isPiecePlayable = useCallback(
({ piece }: { piece: string }): boolean => { ({ piece }: { piece: string }): boolean => {
if (game.isGameOver() || !canPlay) return false; if (game.isGameOver() || !canPlay) return false;
if (canPlay === true || canPlay === piece[0]) return true; if (canPlay === true || canPlay === piece[0]) return true;
@@ -74,7 +74,7 @@ export default function Board({
target: Square, target: Square,
piece: string piece: string
): boolean => { ): boolean => {
if (!isPieceDraggable({ piece })) return false; if (!isPiecePlayable({ piece })) return false;
const result = makeGameMove({ const result = makeGameMove({
from: source, from: source,
@@ -97,10 +97,11 @@ export default function Board({
} }
}; };
const handleSquareLeftClick = (square: Square) => { const handleSquareLeftClick = (square: Square, piece?: string) => {
setClickedSquares([]); setClickedSquares([]);
if (!moveClickFrom) { if (!moveClickFrom) {
if (piece && !isPiecePlayable({ piece })) return;
resetMoveClick(square); resetMoveClick(square);
return; return;
} }
@@ -255,7 +256,7 @@ export default function Board({
boxShadow: "0 2px 10px rgba(0, 0, 0, 0.5)", boxShadow: "0 2px 10px rgba(0, 0, 0, 0.5)",
}} }}
customArrows={customArrows} customArrows={customArrows}
isDraggablePiece={isPieceDraggable} isDraggablePiece={isPiecePlayable}
customSquare={SquareRenderer} customSquare={SquareRenderer}
onSquareClick={handleSquareLeftClick} onSquareClick={handleSquareLeftClick}
onSquareRightClick={handleSquareRightClick} onSquareRightClick={handleSquareRightClick}
@@ -264,6 +265,7 @@ export default function Board({
onPromotionPieceSelect={onPromotionPieceSelect} onPromotionPieceSelect={onPromotionPieceSelect}
showPromotionDialog={showPromotionDialog} showPromotionDialog={showPromotionDialog}
promotionToSquare={moveClickTo} promotionToSquare={moveClickTo}
animationDuration={200}
/> />
</Grid> </Grid>