Comments (21)
And yes, this is not related to custom pieces. Same behavior with default ones
from react-chessboard.
Do you get the same issues here: https://react-chessboard.vercel.app/?path=/story/example-chessboard--play-vs-computer
If not, then can you please copy the board setup from here and use it and see if the issue remains, we need to work out at what point it stops working
from react-chessboard.
Are you able to check on any other devices?
from react-chessboard.
I think it has something to do with this (position: "fixed")
from react-chessboard.
Hi! Is this issue also appears with default pieces? Can you provide code example of your <Chessboard/>
component with the props you use?
from react-chessboard.
const ModalVisual = ({ onHide }: { onHide: () => void }) => {
const [game, setGame] = useState(new Chess());
const [moveFrom, setMoveFrom] = useState<Square>();
const [moveTo, setMoveTo] = useState<Square | null>(null);
const [optionSquares, setOptionSquares] = useState<CustomSquareStyles>({});
const [isCheck, setCheck] = useState(false);
const [isCheckmate, setCheckmate] = useState(false);
const [statusMessage, setStatusMessage] = useState<StatusMessage>(undefined);
const whoseMove = game.turn();
const gameName = useModalStore((state) => state.gameName);
const reward = useModalStore((state) => state.reward);
const setModalGiveUpVisible = useModalStore(
(state) => state.setModalGiveUpVisible
);
const makeAMove = (move: ShortMove) => {
const gameCopy = { ...game };
gameCopy.move(move);
setGame(gameCopy);
};
const customPieces = useMemo(() => {
const pieceComponents: CustomPieces = {};
pieces.map((piece) => {
pieceComponents[piece] = () => (
<div
style={{
width: 67.5,
height: 67.5,
backgroundImage: `url(${BASE_PATH_IMG}/${piece}.svg)`,
backgroundSize: "100%",
}}
/>
);
return null;
});
return pieceComponents;
}, []);
const getMoveOptions = (square: Square) => {
const moves = game.moves({
square,
verbose: true,
});
if (moves.length === 0) {
setOptionSquares({});
return false;
}
const newSquares: CustomSquareStyles = {};
moves.map((move) => {
newSquares[move.to] = {
background:
game.get(move.to) &&
game.get(move.to)?.color !== game.get(square)?.color
? "rgba(237, 65, 89, 0.40)"
: "rgba(0, 205, 164, 0.40)",
boxShadow:
game.get(move.to) &&
game.get(move.to)?.color !== game.get(square)?.color
? "inset 0 0 0 4px #ed4159"
: "",
borderTopLeftRadius: move.to === "a8" ? "24px" : "",
borderBottomLeftRadius: move.to === "a1" ? "24px" : "",
borderTopRightRadius: move.to === "h8" ? "24px" : "",
borderBottomRightRadius: move.to === "h1" ? "24px" : "",
};
return move;
});
newSquares[square] = {
background: "#00cda4",
borderTopLeftRadius: square === "a8" ? "24px" : "",
borderBottomLeftRadius: square === "a1" ? "24px" : "",
borderTopRightRadius: square === "h8" ? "24px" : "",
borderBottomRightRadius: square === "h1" ? "24px" : "",
};
setOptionSquares(newSquares);
return true;
};
const onMouseOverSquare = (square: Square) => {
// from square
if (!moveFrom) {
const hasMoveOptions = getMoveOptions(square);
if (hasMoveOptions) setMoveFrom(square);
return;
}
// to square
if (!moveTo) {
// check if valid move before showing dialog
const moves = game.moves({
square: moveFrom,
verbose: true,
});
const foundMove = moves.find(
(m) => m.from === moveFrom && m.to === square
);
// not a valid move
if (!foundMove) {
// check if clicked on new piece
const hasMoveOptions = getMoveOptions(square);
// if new piece, setMoveFrom, otherwise clear moveFrom
setMoveFrom(hasMoveOptions ? square : undefined);
return;
}
// valid move
setMoveTo(square);
setMoveFrom(undefined);
setMoveTo(null);
setOptionSquares({});
return;
}
};
const onDrop = (sourceSquare: Square, targetSquare: Square) => {
const move = makeAMove({
from: sourceSquare,
to: targetSquare,
promotion: "q",
});
if (move === null) return false;
return true;
};
useEffect(() => {
if (game.in_check()) {
setCheck(true);
setStatusMessage("Check");
}
if (game.in_checkmate()) {
setCheckmate(true);
setStatusMessage("Checkmate, you lose");
}
if (whoseMove === "b") {
setStatusMessage("Opponent's turn");
}
if (game.in_check() && whoseMove === "b") {
setStatusMessage("Check");
}
}, [game, whoseMove]);
return (
<>
<div className={classes.background} />
<IconButton
className={classes.back}
icon="arrow-left"
onClick={() => setModalGiveUpVisible(true)}
color="red"
/>
<div className={classes.content}>
<div className={classes.content__inner}>
<div className={classes.game}>
<div
className={clsx(
classes.game__badge,
(isCheck || isCheckmate) &&
classes.game__badge_checkOrCheckmate,
whoseMove === "b" && classes.game__badge_opponentsTurn
)}
>
{(isCheck || isCheckmate || whoseMove === "b") && statusMessage}
</div>
<div className={classes["modal__game-board"]}>
<Chessboard
position={game.fen()}
boardWidth={540}
showBoardNotation={false}
promotionToSquare={moveTo}
customPieces={customPieces}
customBoardStyle={BOARD_STYLE}
customDropSquareStyle={DROP_SQUARE_STYLE}
customDarkSquareStyle={DARK_SQUARE_STYLE}
customLightSquareStyle={LIGHT_SQUARE_STYLE}
customSquareStyles={{ ...optionSquares }}
onPieceDrop={onDrop}
onMouseOverSquare={onMouseOverSquare}
/>
</div>
</div>
<VersusBox
title={gameName}
reward={reward}
// isYouWin={isYouWin}
// isYouLose={isYouLose}
icon={icon}
onHide={onHide}
/>
</div>
</div>
</>
);
};
from react-chessboard.
@Clariity Hello! Yes, I'm having the same problem with blinking (if that's what we're talking about) in the mode "PlayerVsComputer"
from react-chessboard.
And the funny thing is that only in this mode there is such a blinking, in other modes there is no Sorry for misleading you, itβs the same in other modes
from react-chessboard.
So using the same build, you experience blinking, and I do not, so this implies there must be something else affecting this, perhaps your device or browser or operating system?
For reference I am on Windows 10 on a desktop PC in Chrome Version 116.0.5845.188 (Official Build) (64-bit)
I also do not see the issue on my Android phone on a Chrome browser, nor on a Macbook Pro using a trackpad in Chrome
Does this occur for you on any other devices?
from react-chessboard.
Well, I use too Windows 10, but in Chrome version 117.0.5938.89 (lastest, updated now)
But actually I'm more worried about the bug with dragging a figure and its teleportation (first comment in this issue)
from react-chessboard.
I checked blinking in 3 browsers (Chrome, Mozilla and Edge) and this problem is present in all of them. Strange thing...
from react-chessboard.
2023-09-20.16-50-43.mp4
from react-chessboard.
But actually I'm more worried about the bug with dragging a figure and its teleportation (first comment in this issue)
Are you able to replicate this on the react-chessboard storybook website? I have not been able to replicate it at all
from react-chessboard.
I will try to do this
from react-chessboard.
Are you able to check on any other devices?
In my iPhone 6S working correctly
from react-chessboard.
Could it be your mouse input device on the device where the bug is happening?
from react-chessboard.
To be honest I doubt this is the problem
from react-chessboard.
I noticed some differences in the drawing of the chessboard between you and me. On the left is what the storybook shows, on the right is what it draws for me, there are differences in nesting and quite possibly this is where the problem lies
from react-chessboard.
I'm missing a perspective div and I don't know why this is?
from react-chessboard.
that will be because a new version has recently been released, shouldn't have any effect
from react-chessboard.
@Clariity @Manukyanq Good morning! How are you doing?
A new day gave me new ideas that helped me solve this puzzle with dragging a figure. I revised the layout of this modal window and moved some styles to a lower level, which led to the correct operation of the chessboard. I am very glad and grateful to you for your help. Sometimes you need to talk to someone in order for some idea to come to fruition. Thanks again and sorry if I took up your time
from react-chessboard.
Related Issues (20)
- Is it possible to disable field labels? HOT 2
- Animation looks weird when position and boardOrientation are changed at the same time HOT 6
- Animation goes wrong way when board is flipped HOT 2
- How can I make one black pawn a star, another black pawn, for example, an ice cream, replace not all pawns at once, but only one ? HOT 1
- areArrowsAllowed={false} doesn't work HOT 3
- onPromotionCheck for squareClick HOT 4
- Animation skips after failed drag move HOT 1
- How i can add pieces from outside the board ? HOT 3
- Feature Request: Add Circle Annotations to Squares HOT 3
- Positioning issue if FEN string changes completely HOT 7
- Premove back to existing premove square causes piece to disappear HOT 5
- Board resets to previous state despite value of `position` HOT 8
- Got error when run in dev environment HOT 2
- showPromotionDialog prop not working as expected HOT 1
- Issue with isDraggablePiece update HOT 2
- Feature Request: Exposing the `Square` and `PieceSymbol` in the `onSquareClick()` and `onPieceClick()` handlers HOT 7
- No moves are available with custom positions HOT 2
- Show Dead Pieces HOT 2
- pieces dont snap back into place in touch screen HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-chessboard.