dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 17064984aaa7570fbeff6a4b1208beefd65cab0f
parent 115dd4ef532047dfddd382187d080e2979339cd8
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sat, 17 Jun 2023 11:27:02 -0700

kinda working

Diffstat:
Mpkg/web/handlers/chess.go | 30+++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/pkg/web/handlers/chess.go b/pkg/web/handlers/chess.go @@ -678,19 +678,13 @@ Loop: checkIDStr = interceptors.BlackKingID } - // Calc visible pieces - visiblePieces := hashset.New[chess.Square]() - for sq := range squareMap { - visiblePieces.Set(sq) - } - var styles StylesBuilder renderAdvantages(&styles, pos) renderHideAllPieces(&styles, piecesCache, piecesCache1, squareMap) renderChecks(&styles, checkIDStr) renderLastMove(&styles, *lastMove) renderBestMove(&styles, bestMove, isFlipped) - renderShowVisiblePieceInPosition(&styles, &animationIdx, visiblePieces, squareMap, piecesCache, piecesCache1, isFlipped) + renderShowVisiblePieceInPosition(&styles, &animationIdx, squareMap, piecesCache, piecesCache1, isFlipped) send(styles.Build()) c.Response().Flush() @@ -766,23 +760,29 @@ Loop: return nil } -func renderShowVisiblePieceInPosition(styles *StylesBuilder, animationIdx *int, visiblePieces *hashset.HashSet[chess.Square], +func renderShowVisiblePieceInPosition(styles *StylesBuilder, animationIdx *int, squareMap map[chess.Square]chess.Piece, piecesCache map[chess.Square]string, piecesCache1 map[string]chess.Square, isFlipped bool) { - for _, newSq := range visiblePieces.ToArray() { + oldSqs := hashset.New[chess.Square]() + for newSq := range squareMap { sqID := piecesCache[newSq] // Get ID of piece on square newSq currentSq := piecesCache1[sqID] // Get current square location of the piece - piece := squareMap[newSq] // Get the piece currently on the new square according to game data - bStyle := fmt.Sprintf("#%s { display: block !important; ", sqID) - if currentSq == newSq { - x, y := squareCoord(newSq, isFlipped) - bStyle += fmt.Sprintf("left: calc(%d*12.5%%); top: calc(%d*12.5%%); ", x, y) + if currentSq != newSq { + oldSqs.Set(currentSq) } + } + + for newSq, piece := range squareMap { + sqID := piecesCache[newSq] // Get ID of piece on square newSq + currentSq := piecesCache1[sqID] // Get current square location of the piece + bStyle := fmt.Sprintf("#%s { display: block !important; ", sqID) + x, y := squareCoord(newSq, isFlipped) + bStyle += fmt.Sprintf("left: calc(%d*12.5%%); top: calc(%d*12.5%%); animation: none; ", x, y) if strings.HasSuffix(sqID, "2") || strings.HasSuffix(sqID, "7") { bStyle += "background-image: url(/public/img/chess/" + piece.Color().String() + strings.ToUpper(piece.Type().String()) + ".png) !important; " } bStyle += "}\n" styles.Append(bStyle) - if currentSq != newSq { + if currentSq != newSq && !oldSqs.Contains(newSq) { animate(currentSq, newSq, sqID, isFlipped, animationIdx, styles) // Move piece from current square to the new square where we want it to be } piecesCache1[sqID] = newSq // Update cache of location of the piece