joeldick / chess_puzzles2

0 stars 0 forks source link

Allow click moves #11

Open joeldick opened 4 months ago

joeldick commented 4 months ago

Now, only drag and drop works. Allow the user to click on a piece and click on the square they want it to go.

joeldick commented 4 months ago

This turns out to be much harder than I expected.

Handling promotions is a bitch, because on the second click (move to square), you have to detect if it's a pawn and last rank, and manually pull up the promotion dialog by setting the showPromotionDialog property of the chessboard to true. There's a few extra states to keep track of.

On its own, it's doable with a bit of work, but it's especially hard to get it to work IN ADDITION to drag and drop.

Also, I tried having both the onDrop and the onClick functions call a third function that actually makes the move, but the asynchronous nature of the function calls causes the drag-on-drop to behave with a strange delay (causing the piece to move twice). You can test this easily by simply making a call like this: onDrop(to, from, piece) { onDrop2(to, from, piece); } and you'll see the delay in action.