dkforest

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

commit 56d8f51ab5849bc02aabc1898ba90ab5ddf53bcc
parent c1eeca3a287d4e0da52df64a76b97bbf0317330d
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sun, 11 Jun 2023 17:57:26 -0700

cleanup

Diffstat:
Mpkg/web/handlers/interceptors/chess.go | 80+++++++++++++++++++++++++++++++------------------------------------------------
1 file changed, 31 insertions(+), 49 deletions(-)

diff --git a/pkg/web/handlers/interceptors/chess.go b/pkg/web/handlers/interceptors/chess.go @@ -157,62 +157,44 @@ input[type=checkbox]:checked + label { border: 3px solid red; } </style>` - out += `<table class="newBoard">` - for i := 0; i < 64; i++ { - id := i - mm := 0 - switch i % 8 { - case 0: - mm = -7 - case 1: - mm = -5 - case 2: - mm = -3 - case 3: - mm = -1 - case 4: - mm = 1 - case 5: - mm = 3 - case 6: - mm = 5 - case 7: - mm = 7 - } - if !isFlipped { - id = (63 - i) + mm + + getID := func(row, col int) int { + var id int + if isFlipped { + id = row*8 + (7 - col) } else { - id = i - mm - } - sq := chess.Square(id) - idStr := strconv.Itoa(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) - lastMoveColor := utils.Ternary(isLastMove, LastMoveColor, "transparent") - checkColor := utils.Ternary(inCheck, CheckColor, "transparent") - x := i % 8 - y := i / 8 - - if i%8 == 0 { - if i != 0 { - out += "</tr>" - } - out += "<tr>" + id = (7-row)*8 + col } - out += fmt.Sprintf(`<td class="square square_%s" style="background-color: %s;">`, idStr, lastMoveColor) - if p != chess.NoPiece { - out += fmt.Sprintf(`<div id="%s" class="img" style=" + return id + } + + out += `<table class="newBoard">` + for row := 0; row < 8; row++ { + out += "<tr>" + for col := 0; col < 8; col++ { + id := getID(row, col) + 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) + lastMoveColor := utils.Ternary(isLastMove, LastMoveColor, "transparent") + checkColor := utils.Ternary(inCheck, CheckColor, "transparent") + + out += fmt.Sprintf(`<td class="square square_%d" style="background-color: %s;">`, id, lastMoveColor) + if p != chess.NoPiece { + out += fmt.Sprintf(`<div id="%s" class="img" style=" left: calc(%d*12.5%%); top: calc(%d*12.5%%); background-image: url(/public/img/chess/%s.png); background-color: %s;"></div>`, - pidStr, x, y, fname, checkColor) + pidStr, col, row, fname, checkColor) + } + out += "</td>" } - out += "</td>" + out += "</tr>" } - out += "</tr></table>" + out += "</table>" return out }