commit 66c22b0c95023e50c457afc13b2585e688af2931
parent a2543d249fde60517246e51ca1c80073b8f74aba
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Sun, 11 Jun 2023 16:22:58 -0700
cleanup
Diffstat:
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -5254,16 +5254,16 @@ Loop:
// Render last move
send(`<style>.square { background-color: transparent !important; }</style>`)
- send(fmt.Sprintf(`<style>.square_%d, .square_%d { background-color: rgba(0, 255, 0, 0.2) !important; }</style>`, int(payload.Move.S1()), int(payload.Move.S2())))
+ send(fmt.Sprintf(`<style>.square_%d, .square_%d { background-color: `+interceptors.LastMoveColor+` !important; }</style>`, int(payload.Move.S1()), int(payload.Move.S2())))
// Reset kings background to transparent
send(`<style>#` + whiteKingID + ` { background-color: transparent !important; }</style>`)
send(`<style>#` + blackKingID + ` { background-color: transparent !important; }</style>`)
// Render "checks" red background
if payload.CheckW {
- send(`<style>#` + whiteKingID + ` { background-color: rgba(255, 0, 0, 0.4) !important; }</style>`)
+ send(`<style>#` + whiteKingID + ` { background-color: ` + interceptors.CheckColor + ` !important; }</style>`)
} else if payload.CheckB {
- send(`<style>#` + blackKingID + ` { background-color: rgba(255, 0, 0, 0.4) !important; }</style>`)
+ send(`<style>#` + blackKingID + ` { background-color: ` + interceptors.CheckColor + ` !important; }</style>`)
}
c.Response().Flush()
diff --git a/pkg/web/handlers/interceptors/chess.go b/pkg/web/handlers/interceptors/chess.go
@@ -105,6 +105,9 @@ var ChessInstance *Chess
const (
sqSize = 45
boardSize = 8 * sqSize
+
+ CheckColor = "rgba(255, 0, 0, 0.4)"
+ LastMoveColor = "rgba(0, 255, 0, 0.2)"
)
func (g *ChessGame) renderBoardHTML1(position *chess.Position, isFlipped bool, imgB64 string, spectator bool) string {
@@ -195,7 +198,7 @@ input[type=checkbox]:checked + label {
idStr := strconv.Itoa(id)
out += `<td class="square square_` + idStr + `"`
if last != nil && (last.S1() == sq || last.S2() == sq) {
- out += ` style="background-color: rgba(0, 255, 0, 0.2);"`
+ out += ` style="background-color: ` + LastMoveColor + `;"`
}
out += ">"
sqPiece := boardMap[sq]
@@ -206,7 +209,7 @@ input[type=checkbox]:checked + label {
pidStr := g.PiecesCache[sq]
out += `<div id="` + pidStr + `" class="img" style="left: calc(` + strconv.Itoa(x) + `*12.5%); top: calc(` + strconv.Itoa(y) + `*12.5%); background-image: url(/public/img/chess/` + p.Color().String() + pieceTypeMap[p.Type()] + `.png);`
if last != nil && p.Color() == g.Game.Position().Turn() && p.Type() == chess.King && last.HasTag(chess.Check) {
- out += ` background-color: rgba(255, 0, 0, 0.4);`
+ out += ` background-color: ` + CheckColor + `;`
}
out += `"></div>`
}