feat: teach Chessboard to support DropMoves#84
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds support for DropMoves to the Chessboard widget, enabling pieces to be dragged from outside the board (e.g., from a piece pocket in Crazyhouse) and dropped onto board squares. The implementation broadens the type system from NormalMove to the more general Move type to accommodate both regular moves and drop moves.
Changes:
- Expanded type signatures from
NormalMovetoMovethroughout the codebase to support both normal moves and drop moves - Added
enableDropMovessetting toChessboardSettingsto enable/disable the feature - Implemented drag target overlays for all board squares when drop moves are enabled
- Added validation for back-rank pawn drops and empty square requirements
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/src/models.dart | Updated onMove callback and Premovable type definitions to accept Move instead of NormalMove |
| lib/src/board_settings.dart | Added enableDropMoves boolean setting with default value of false |
| lib/src/widgets/board.dart | Added 64 DragTarget widgets for drop move acceptance, updated _lastDrop type, and added pattern matching for NormalMove checks |
| lib/src/widgets/animation.dart | Updated preparePieceAnimations to handle both NormalMove and DropMove in the lastDrop parameter |
| test/widgets/board_test.dart | Added tests for drop moves and drop premoves, updated test app to support Move type, added unsafe type cast for premove promotion |
| example/lib/main.dart | Added Crazyhouse demonstration with drag-and-drop piece pockets, duplicated ChessboardSettings creation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -56,7 +56,7 @@ class GameData { | |||
| /// Callback called after a move has been made. | |||
| /// | |||
| /// If the move has been made with drag and drop, `isDrop` will be true. | |||
There was a problem hiding this comment.
The documentation comment states "If the move has been made with drag and drop, isDrop will be true." However, this is now ambiguous. The isDrop parameter could mean either:
- A drag-and-drop interaction (vs tap-to-select)
- A DropMove (vs NormalMove)
Consider updating the documentation to clarify this distinction, especially since the code at line 420 in board.dart sets isDrop: true specifically for DropMoves (pieces dragged from outside the board), not for all drag-and-drop moves.
| /// If the move has been made with drag and drop, `isDrop` will be true. | |
| /// The optional [isDrop] flag is `true` when the move is a drop move, | |
| /// i.e. a piece is placed onto the board from outside (as opposed to a | |
| /// normal move of a piece already on the board). It does not indicate | |
| /// whether the user interaction was performed via drag-and-drop or | |
| /// tap-to-select. |
There was a problem hiding this comment.
@veloce I also thought about this, do we want to rename to viaDragAndDrop maybe?
There was a problem hiding this comment.
I think this is not even used by the app... But we should leave it in case other folks use it. In any case it is BC so major version.
There was a problem hiding this comment.
IIRC I added that because the old app was using this metadata to send to server (don't remember why).
f914d7d to
e049c09
Compare
dropmoves.webm