dkforest

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

commit 3c4495c0508af9f35c8e8dc9e084318989f10332
parent dbfda74d4d7e61d2972b4c27c5356482f4dfcbc4
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Thu, 15 Jun 2023 19:24:20 -0700

reduce bandwidth and css animations

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

diff --git a/pkg/web/handlers/chess.go b/pkg/web/handlers/chess.go @@ -764,7 +764,7 @@ Loop: var styles StylesBuilder renderAdvantages(&styles, pos) - renderHideAllPieces(&styles) + renderHideAllPieces(&styles, piecesCache, piecesCache1, squareMap) renderChecks(&styles, checkIDStr) renderLastMove(&styles, *lastMove) renderBestMove(&styles, bestMove, isFlipped) @@ -888,12 +888,20 @@ func renderAdvantages(styles *StylesBuilder, pos *chess.Position) { styles.Appendf(`#black-advantage .score:after { content: "%s" !important; }`, blackScore) } -func renderHideAllPieces(styles *StylesBuilder) { - ids := make([]string, 64) - for i := 0; i < 64; i++ { - ids[i] = "#piece_" + chess.Square(i).String() +func renderHideAllPieces(styles *StylesBuilder, piecesCache map[chess.Square]string, piecesCache1 map[string]chess.Square, squareMap map[chess.Square]chess.Piece) { + toHideMap := make(map[string]struct{}) + for id, _ := range piecesCache1 { + toHideMap[id] = struct{}{} + } + for sq := range squareMap { + idOnSq, _ := piecesCache[sq] + delete(toHideMap, idOnSq) + } + toHide := make([]string, 0) + for id := range toHideMap { + toHide = append(toHide, "#"+id) } - styles.Appendf(`%s { display: none !important; }`, strings.Join(ids, ", ")) + styles.Appendf(`%s { display: none !important; }`, strings.Join(toHide, ", ")) } func calcDisc(x1, y1, x2, y2 int) (d int, isDiag, isLine bool) {