commit 6e63419f661d3e271397a09ab69a0e5d3cc68595
parent dcc0620c0abd50b97bf748c805840fc75ddab530
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Sun, 11 Jun 2023 18:35:49 -0700
cleanup
Diffstat:
1 file changed, 12 insertions(+), 19 deletions(-)
diff --git a/pkg/web/handlers/interceptors/chess.go b/pkg/web/handlers/interceptors/chess.go
@@ -110,6 +110,16 @@ const (
LastMoveColor = "rgba(0, 255, 0, 0.2)"
)
+func getID(row, col int, isFlipped bool) int {
+ var id int
+ if isFlipped {
+ id = row*8 + (7 - col)
+ } else {
+ id = (7-row)*8 + col
+ }
+ return id
+}
+
func (g *ChessGame) renderBoardHTML1(position *chess.Position, isFlipped bool, imgB64 string, spectator bool) string {
moves := g.Game.Moves()
var last *chess.Move
@@ -118,15 +128,6 @@ func (g *ChessGame) renderBoardHTML1(position *chess.Position, isFlipped bool, i
}
boardMap := position.Board().SquareMap()
- getID := func(row, col int) int {
- var id int
- if isFlipped {
- id = row*8 + (7 - col)
- } else {
- id = (7-row)*8 + col
- }
- return id
- }
pieceInCheck := func(p chess.Piece) bool {
return last != nil && p.Color() == g.Game.Position().Turn() && p.Type() == chess.King && last.HasTag(chess.Check)
}
@@ -206,7 +207,7 @@ input[type=checkbox]:checked + label {
}
fns := template.FuncMap{
- "GetID": getID,
+ "GetID": func(row, col int) int { return getID(row, col, isFlipped) },
"IsLastMove": sqIsLastMove,
"PieceInCheck": pieceInCheck,
"GetPieceFileName": getPieceFileName,
@@ -345,15 +346,7 @@ input[type=checkbox]:checked + label {
}
fns := template.FuncMap{
- "GetID": func(row, col int) int {
- var id int
- if isBlack {
- id = row*8 + (7 - col)
- } else {
- id = (7-row)*8 + col
- }
- return id
- },
+ "GetID": func(row, col int) int { return getID(row, col, isBlack) },
}
var buf bytes.Buffer