lichess-org / chessground

Mobile/Web chess UI for lichess.org
https://lichess.org
GNU General Public License v3.0
1.04k stars 261 forks source link

Crazyhouse drops by click-click #292

Open VVestin opened 10 months ago

VVestin commented 10 months ago

fixes lichess-org/lila#12866 This change is dependant on this follow-up PR on lila that adds a CSS class for the selected piece within the pocket: https://github.com/lichess-org/lila/pull/14052

This change makes it so that when you click an external piece and try to drag it onto the board and drop it (such as in the crazyhouse variant), you have the option to click and select (previously only drag and drop was possible).

I implemented this by making the dragNewPiece function in drag.ts also select the new piece. Then if the drag ends on the same element where it started, we count that as a click and select that piece. When the user clicks an empty space on the board, we drop the selected piece onto that square.

I also added a board to demo.html that allows you to drop pieces on it.

I also made it respect state.selectable.enabled and state.draggable.enabled for external pieces the same as pieces on the board because previously dragging was the only way to drop pieces in crazyhouse. With this change, we should respect the user's preferences for whether they allow dragging, clicking, or both.