commit 86e4a1f17bbab1ebe31401766e02ad7a54e5bad1
parent 5a7a9d3fd858c7c12af0b86c51b98ffed55c26d4
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Fri, 16 Jun 2023 23:24:38 -0700
simplify code
Diffstat:
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/pkg/web/handlers/chess.go b/pkg/web/handlers/chess.go
@@ -4,6 +4,7 @@ import (
"bytes"
"dkforest/pkg/config"
"dkforest/pkg/database"
+ "dkforest/pkg/hashset"
"dkforest/pkg/pubsub"
"dkforest/pkg/utils"
"dkforest/pkg/web/handlers/interceptors"
@@ -678,9 +679,9 @@ Loop:
}
// Calc visible pieces
- visiblePieces := make(map[chess.Square]struct{})
+ visiblePieces := hashset.New[chess.Square]()
for sq := range squareMap {
- visiblePieces[sq] = struct{}{}
+ visiblePieces.Set(sq)
}
var styles StylesBuilder
@@ -765,9 +766,9 @@ Loop:
return nil
}
-func renderShowVisiblePieceInPosition(styles *StylesBuilder, animationIdx *int, visiblePieces map[chess.Square]struct{},
+func renderShowVisiblePieceInPosition(styles *StylesBuilder, animationIdx *int, visiblePieces hashset.HashSet[chess.Square],
squareMap map[chess.Square]chess.Piece, piecesCache map[chess.Square]string, piecesCache1 map[string]chess.Square, isFlipped bool) {
- for newSq := range visiblePieces {
+ for _, newSq := range visiblePieces.ToArray() {
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