commit 90bd3f95453c08b90fdcf4e2c173d984fc500755
parent 345a2d3063f902663225cacc5c70dfba7df15da6
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Fri, 8 Nov 2024 13:28:51 -0800
cleanup
Diffstat:
2 files changed, 7 insertions(+), 18 deletions(-)
diff --git a/pkg/web/handlers/chess.go b/pkg/web/handlers/chess.go
@@ -586,12 +586,6 @@ func ChessGameHandler(c echo.Context) error {
isFlipped = true
}
- //isYourTurnFn := func() bool {
- // return authUser.ID == g.Player1.ID && game.Position().Turn() == chess.White ||
- // authUser.ID == g.Player2.ID && game.Position().Turn() == chess.Black
- //}
- //isYourTurn := isYourTurnFn()
-
send := func(s string) {
_, _ = c.Response().Write([]byte(s))
}
@@ -619,13 +613,12 @@ func ChessGameHandler(c echo.Context) error {
if isSpectator {
card1 = g.DrawSpectatorCard(0, key, isFlipped, authUser.ChessSoundsEnabled, authUser.CanUseChessAnalyze)
} else {
- card1 = g.DrawPlayerCard(0, key, isFlipped, false, authUser.ChessSoundsEnabled, authUser.CanUseChessAnalyze)
+ card1 = g.DrawPlayerCard(0, key, isFlipped, authUser.ChessSoundsEnabled, authUser.CanUseChessAnalyze)
}
send(card1)
go func(c echo.Context, key string, p1ID, p2ID database.UserID) {
- p1Online := false
- p2Online := false
+ var p1Online, p2Online bool
var once utils.Once
for {
select {
@@ -874,14 +867,10 @@ func arrow(s1, s2 chess.Square, isFlipped bool) (out string) {
"} ", a, cy2, cx2)
var h string
if isDiag {
- dist /= 2
- // sqrt(100^2 + 100^2) = 141.42
- // sqrt(30^2 + 30^2) = 42.43
- h = fmt.Sprintf("calc(%d*141.42%% + 42.43%% + 55%%)", dist-1)
+ h = fmt.Sprintf("calc(%d*141.42%% + 42.43%% + 55%%)", dist/2-1)
} else if isLine {
h = fmt.Sprintf("calc(%d*100%% + 55%%)", dist-1)
} else {
- // sqrt(100^2 + 200^2) = 223.60
h = fmt.Sprintf("calc(223.60%% - 45%%)")
}
out += fmt.Sprintf("#arrow .rectangle { height: %s !important; }", h)
diff --git a/pkg/web/handlers/interceptors/chess.go b/pkg/web/handlers/interceptors/chess.go
@@ -417,11 +417,11 @@ func (g *ChessGame) renderBoardB64(isFlipped bool) string {
return imgB64
}
-func (g *ChessGame) DrawPlayerCard(moveIdx int, key string, isBlack, isYourTurn, soundsEnabled, canUseChessAnalyze bool) string {
- return g.drawPlayerCard(moveIdx, key, isBlack, false, isYourTurn, soundsEnabled, canUseChessAnalyze)
+func (g *ChessGame) DrawPlayerCard(moveIdx int, key string, isBlack, soundsEnabled, canUseChessAnalyze bool) string {
+ return g.drawPlayerCard(moveIdx, key, isBlack, false, soundsEnabled, canUseChessAnalyze)
}
-func (g *ChessGame) drawPlayerCard(moveIdx int, key string, isBlack, isSpectator, isYourTurn, soundsEnabled, canUseChessAnalyze bool) string {
+func (g *ChessGame) drawPlayerCard(moveIdx int, key string, isBlack, isSpectator, soundsEnabled, canUseChessAnalyze bool) string {
htmlTmpl := `
<style>
#p1Status {
@@ -598,7 +598,7 @@ func (g *ChessGame) drawPlayerCard(moveIdx int, key string, isBlack, isSpectator
}
func (g *ChessGame) DrawSpectatorCard(moveIdx int, key string, isFlipped, soundsEnabled, canUseChessAnalyze bool) string {
- return g.drawPlayerCard(moveIdx, key, isFlipped, true, false, soundsEnabled, canUseChessAnalyze)
+ return g.drawPlayerCard(moveIdx, key, isFlipped, true, soundsEnabled, canUseChessAnalyze)
}
func (g *ChessGame) SetAnalyzing() bool {