lichess-org / flutter-chessground

Chessboard package for flutter
https://pub.dev/packages/chessground
GNU General Public License v3.0
44 stars 27 forks source link

fix: flip dragFeedbackOffset.y when piece is flipped #50

Closed tom-anders closed 2 weeks ago

tom-anders commented 1 month ago

Noticed this while building the "over the board" screen for lichess mobile v2. When pieces are flipped, the person dragging them will probably look at the app in such a way that the piece is not flipped from their POV. This means with the previous behavior, the drag feedback offset would be shifted into the wrong vertical direction.

tom-anders commented 1 month ago

Before:

before.webm

After:

after.webm

tom-anders commented 3 weeks ago

Related change, so I added it to this PR as well, as it will cause conflicts otherwise: Added possibility to flip all pieces (not just opponent pieces). This is also needed for the over the board implementation. Moved the variable from ChessboardState to ChessboardSettings as that felt like the more appropiate place to me (as it's a visual setting, not really about state):

tom-anders commented 2 weeks ago

I have one API change suggestion, cf comment.

I also think this deserves testing. Right now we don't test the upside down behavior, but with the new logic all the cases should be tested.

Piece widget should always return a Transform.rotate I think and we'd check the angle in tests to verify behavior.

Unfortunately, Transform.rotate does not actually store the angle, but a matrix internally.

I went with checking the upsideDown property of all pieces widgets, let me know if you think this is sufficient