dkforest

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

commit 7540b41528ce994d14f004c44678cecc59854853
parent ff4b18b51a0b32f56dee5e096a800a86988ef3e0
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Thu, 15 Jun 2023 10:57:44 -0700

fix arrow for flipped board

Diffstat:
Mpkg/web/handlers/chess.go | 12++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/pkg/web/handlers/chess.go b/pkg/web/handlers/chess.go @@ -752,7 +752,7 @@ Loop: renderHideAllPieces(&styles) renderChecks(&styles, checkIDStr) renderLastMove(&styles, *lastMove) - renderBestMove(&styles, bestMove) + renderBestMove(&styles, bestMove, isFlipped) renderShowVisiblePieceInPosition(&styles, visiblePieces, squareMap, piecesCache, isFlipped) send(styles.Build()) @@ -889,9 +889,9 @@ func calcDisc(x1, y1, x2, y2 int) (d int, isDiag, isLine bool) { return } -func arrow(s1, s2 chess.Square) (out string) { - cx1, cy1 := squareCoord(s1, false) - cx2, cy2 := squareCoord(s2, false) +func arrow(s1, s2 chess.Square, isFlipped bool) (out string) { + cx1, cy1 := squareCoord(s1, isFlipped) + cx2, cy2 := squareCoord(s2, isFlipped) dist, isDiag, isLine := calcDisc(cx1, cy1, cx2, cy2) a := math.Atan2(float64(cy1-cy2), float64(cx1-cx2)) + math.Pi/2 + math.Pi out += fmt.Sprintf("#arrow { "+ @@ -913,11 +913,11 @@ func arrow(s1, s2 chess.Square) (out string) { return } -func renderBestMove(styles *StylesBuilder, bestMove *chess.Move) { +func renderBestMove(styles *StylesBuilder, bestMove *chess.Move, isFlipped bool) { if bestMove != nil { s1 := bestMove.S1() s2 := bestMove.S2() - arrowStyle := arrow(s1, s2) + arrowStyle := arrow(s1, s2, isFlipped) styles.Append(arrowStyle) } }