dkforest

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

commit 62d62c5b16b35ca7ad00743733f1f3fc3f2d285c
parent 56d8f51ab5849bc02aabc1898ba90ab5ddf53bcc
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sun, 11 Jun 2023 18:03:12 -0700

cleanup

Diffstat:
Mpkg/web/handlers/interceptors/chess.go | 17+++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/pkg/web/handlers/interceptors/chess.go b/pkg/web/handlers/interceptors/chess.go @@ -167,6 +167,15 @@ input[type=checkbox]:checked + label { } 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) + } + sqIsLastMove := func(sq chess.Square) bool { + return last != nil && (last.S1() == sq || last.S2() == sq) + } + getPieceFileName := func(p chess.Piece) string { + return p.Color().String() + pieceTypeMap[p.Type()] + } out += `<table class="newBoard">` for row := 0; row < 8; row++ { @@ -176,9 +185,9 @@ input[type=checkbox]:checked + label { sq := chess.Square(id) p := boardMap[sq] pidStr := g.PiecesCache[sq] - isLastMove := last != nil && (last.S1() == sq || last.S2() == sq) - fname := p.Color().String() + pieceTypeMap[p.Type()] - inCheck := last != nil && p.Color() == g.Game.Position().Turn() && p.Type() == chess.King && last.HasTag(chess.Check) + isLastMove := sqIsLastMove(sq) + fName := getPieceFileName(p) + inCheck := pieceInCheck(p) lastMoveColor := utils.Ternary(isLastMove, LastMoveColor, "transparent") checkColor := utils.Ternary(inCheck, CheckColor, "transparent") @@ -188,7 +197,7 @@ input[type=checkbox]:checked + label { left: calc(%d*12.5%%); top: calc(%d*12.5%%); background-image: url(/public/img/chess/%s.png); background-color: %s;"></div>`, - pidStr, col, row, fname, checkColor) + pidStr, col, row, fName, checkColor) } out += "</td>" }