dkforest

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

commit 90c38ee312bfdfa79ed1fb89f49ef06b4c2071a9
parent 12c21b9a954d88b67216eb3ef4c1c3902f5e59a0
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Thu, 15 Jun 2023 20:35:46 -0700

reduce animations

Diffstat:
Mpkg/web/handlers/chess.go | 24+++++++++++++++---------
Mpkg/web/handlers/interceptors/chess.go | 1-
2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/pkg/web/handlers/chess.go b/pkg/web/handlers/chess.go @@ -857,30 +857,36 @@ Loop: } func renderShowVisiblePieceInPosition(styles *StylesBuilder, animationIdx *int, visiblePieces map[chess.Square]struct{}, squareMap map[chess.Square]chess.Piece, piecesCache map[chess.Square]string, piecesCache1 map[string]chess.Square, isFlipped bool) { - animate := func(s1, s2 chess.Square, id string, p chess.Piece) { + animate := func(s1, s2 chess.Square, id string) { x1, y1 := squareCoord(s1, isFlipped) x2, y2 := squareCoord(s2, isFlipped) *animationIdx++ animationName := fmt.Sprintf("move_anim_%d", *animationIdx) keyframes := "@keyframes %s {" + "from { left: calc(%d*12.5%%); top: calc(%d*12.5%%); }" + - " to { left: calc(%d*12.5%%); top: calc(%d*12.5%%); } }" + " to { left: calc(%d*12.5%%); top: calc(%d*12.5%%); } }\n" styles.Appendf(keyframes, animationName, x1, y1, x2, y2) - styles.Appendf(`#%s { animation: %s %dms forwards; }`, id, animationName, 400) + styles.Appendf("#%s { animation: %s %dms forwards; }\n", id, animationName, 400) } for newSq := range visiblePieces { 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 - styles.Appendf("#%s { display: block !important; "+ - "background-image: url(/public/img/chess/"+piece.Color().String()+strings.ToUpper(piece.Type().String())+".png) !important; }", sqID) + 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 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 { - animate(currentSq, newSq, sqID, piece) // Move piece from current square to the new square where we want it to be - } else { - x, y := squareCoord(currentSq, isFlipped) - styles.Appendf("#%s { left: calc(%d*12.5%%) !important; top: calc(%d*12.5%%) !important; }", sqID, x, y) + animate(currentSq, newSq, sqID) // Move piece from current square to the new square where we want it to be } + //animate(currentSq, newSq, sqID) piecesCache1[sqID] = newSq // Update cache of location of the piece } } diff --git a/pkg/web/handlers/interceptors/chess.go b/pkg/web/handlers/interceptors/chess.go @@ -238,7 +238,6 @@ func (g *ChessGame) renderBoardHTML1(moveIdx int, position *chess.Position, isFl {{ range $.Dead }} {{ $p1 := DeadPieceFromSq . }} <div id="piece_{{ . }}" class="img" style=" - left: calc(0*12.5%); top: calc(0*12.5%); background-image: url(/public/img/chess/{{ GetPieceFileName $p1 }}.png); background-color: transparent; display: none;"></div> {{ end }}