commit 8460d2a386a5b579355357281224e28dbf7a6f94
parent 2b1b68247750ac863c92c555c40509441115addc
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Thu, 15 Jun 2023 11:42:26 -0700
cleanup
Diffstat:
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/pkg/web/handlers/chess.go b/pkg/web/handlers/chess.go
@@ -872,14 +872,13 @@ func renderShowVisiblePieceInPosition(styles *StylesBuilder, animationIdx *int,
styles.Appendf(`#%s { animation: %s %dms forwards; }`, id, animationName, 400)
}
- for sq := range visiblePieces {
- sqID := piecesCache[sq]
- sqStr := strings.TrimPrefix(sqID, "piece_")
- s2 := parseSq(sqStr)
- pc1 := piecesCache1[s2]
- p := squareMap[sq]
- animate(pc1, sq, sqID, p)
- piecesCache1[s2] = sq
+ for newSq := range visiblePieces {
+ sqID := piecesCache[newSq] // Get ID of piece on square newSq
+ visiblePieceIDSqStr := parseSq(strings.TrimPrefix(sqID, "piece_")) // Get original board square
+ currentSq := piecesCache1[visiblePieceIDSqStr] // Get current square location of the piece
+ piece := squareMap[newSq] // Get the piece currently on the new square according to game data
+ animate(currentSq, newSq, sqID, piece) // Move piece from current square to the new square where we want it to be
+ piecesCache1[visiblePieceIDSqStr] = newSq // Update cache of location of the piece
}
}