Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skipping of move animation #22

Open
Mercutio1243 opened this issue Jan 30, 2024 · 4 comments
Open

Skipping of move animation #22

Mercutio1243 opened this issue Jan 30, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@Mercutio1243
Copy link

Hi Alex,

I am experiencing a display issue with the squares chessboard when programmatically making a move. I use the makeMove command on the corresponding bishop instance and update the SquaresState. Sometimes, the move animation is skipped. As you can see in the video, this seems to be randomly on specific moves, however it then repeats when I use the undo command and repeat the specific move:

WhatsApp.Video.2024-01-30.at.10.49.02_62514847.mp4

Here, it is for instance the knight move to B6, where the animation is simply skipped. I have increased the animation duration to make it more visible. As there is no difference between how I execute the different moves, I am a bit confused why this is happening sometimes.

Do you have any idea what could be the reason here? Have you faced something similar in the past?

Thanks in advance for any advise!

@Mercutio1243 Mercutio1243 changed the title Skipping in move animation Skipping of move animation Jan 30, 2024
@alexobviously alexobviously added the bug Something isn't working label Jan 31, 2024
@alexobviously alexobviously self-assigned this Jan 31, 2024
@alexobviously
Copy link
Owner

Yeah I have definitely seen this before and I did once have a quick look but didn't find anything. I'm up to have another look though. If you have any more ideas about the cause then definitely let me know.

@alexobviously
Copy link
Owner

By the way, I have been skim reading all the other stuff you and others have come up with in discussions, I've just been really busy with work and haven't quite had the time to get to it properly yet. It is much appreciated though and if you hit something that is really really blocking you, definitely ping me as much as you want and I'll reprioritise.

@Mercutio1243
Copy link
Author

Mercutio1243 commented Feb 1, 2024

Thanks Alex, much appreciated, and do not worry, I was able to figure out most on my own. Apart from this topic here, I do not have any open issues or questions.

I left some code for arrows in the discussions, this is more for you to consider, whether you want to include some functionality like this directly in the package. I am sure, you would want to rewrite the code a bit though ;)

@Mercutio1243
Copy link
Author

Mercutio1243 commented Feb 1, 2024

Looking into the issue, I hope I can at least give a first indication, why the skipping is happening: In my case, the issue seems to be with the variable animate in board_pieces.dart.

In board_pieces.dart, there is a if-clause to check, whether the element should be animated at that moment. During piece movement, it is called repeatedly:

if (widget.state.lastTo == id && widget.state.lastFrom != Squares.hand && symbol.isNotEmpty && widget.animatePieces && animate)

In cases, when the animation is skipped, the check always evaluates to false, because animate is always false.

implementing Next Board Move: e5
widget.state.lastTo == id: false, widget.state.lastFrom != Squares.hand: true, symbol.isNotEmpty: true, widget.animatePieces: true, animate: false
[repeating]
widget.state.lastTo == id: false, widget.state.lastFrom != Squares.hand: true, symbol.isNotEmpty: true, widget.animatePieces: true, animate: false
widget.state.lastTo == id: true, widget.state.lastFrom != Squares.hand: true, symbol.isNotEmpty: true, widget.animatePieces: true, animate: false
widget.state.lastTo == id: false, widget.state.lastFrom != Squares.hand: true, symbol.isNotEmpty: true, widget.animatePieces: true, animate: false
[repeating]
widget.state.lastTo == id: false, widget.state.lastFrom != Squares.hand: true, symbol.isNotEmpty: true, widget.animatePieces: true, animate: false

However, when there is no skipping observable, the animate variable is true, which allows for the entire clause to evaluate to true once:

implementNextBoardMove: Qh5
widget.state.lastTo == id: false, widget.state.lastFrom != Squares.hand: true, symbol.isNotEmpty: false, widget.animatePieces: true, animate: true
[repeating]
widget.state.lastTo == id: true, widget.state.lastFrom != Squares.hand: true, symbol.isNotEmpty: true, widget.animatePieces: true, animate: true
-----> Entire clause evaluates to true and move animation inside if-clause is returned
widget.state.lastTo == id: false, widget.state.lastFrom != Squares.hand: true, symbol.isNotEmpty: false, widget.animatePieces: true, animate: true
[repeating with different constellations, but never all true]
widget.state.lastTo == id: false, widget.state.lastFrom != Squares.hand: true, symbol.isNotEmpty: true, widget.animatePieces: true, animate: true
[repeating with different constellations, but never all true]

The animate variable is determined as follows:

  bool animate = true;

  @override
  void didUpdateWidget(covariant BoardPieces oldWidget) {
    // This prevents the animation from repeating in cases where it shouldn't,
    // e.g. if the board is rotated. It would also be possible to do this with
    // collection's ListEquality or something but this seems efficient.
    animate = oldWidget.state.board.join() != widget.state.board.join() && !afterDrag;
    afterDrag = false;
    super.didUpdateWidget(oldWidget);
  }

When you comment out the animate = oldWidget[...] line, there is no skipping of the animation (but the animation is also generated in cases when the user moves a piece by hand, which is not supposed to be happening).

I do not fully understand mechanic of the animate variable, but maybe this helps already. In my case from fen starting position, the skipping occurs realiably when moving pawns 2 steps forwards. Also, when queen moves sideways, but not if queen moves diagonally. In the same position it is replicable, but I cannot see a clear pattern that explains it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants