Closed jimmyyzr closed 3 years ago
This is a timing / callback bug. You will need to set the board position after the user selects their promotion piece. For a moment in time, the chess.js game state will not match the state on the chessboard.js board.
Sorry I am a little confused. Could you elaborate a little bit? What do you mean by "set the board position"? I think game.move
has to happen in onDrag
Could you please send a response at your convenience?
The order of operations should look like this:
onDrop
event from Chessboard)game.move()
)For a moment in time before the user selects a piece from the pawn promotion interface, the board will show a pawn on the 8th rank.
Thanks for your response! I understand the process you described, but I think the current problem is that onDrop
wouldn't wait for the user to make the choice (since my promotion window is asynchronous), and onSnapEnd
will be called immediately without knowinig the user's decision.
I have a popup window to let the user choose a promotion, however, the rest of the code in
onDrag
wouldn't wait until the click happen, andonSnapEnd
is triggered right after, when the move has not be set up, which causes bad behavior. Below is part of my code inonDrag
:Any suggestion on how should I fix this?I think I need to stop the
onDrag
function when the user hasn't choose the promotion.