commit ef64b5be37aad7202f1ff5d533b92c2cae555434
parent 854d9713a3fc64a13324f18b0bc60051942eddb8
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Tue, 6 Jun 2023 22:14:43 -0700
simplify code
Diffstat:
1 file changed, 5 insertions(+), 14 deletions(-)
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -4826,18 +4826,12 @@ func ChessGameHandler(c echo.Context) error {
return c.Redirect(http.StatusFound, "/")
}
- var isFlipped bool
- if authUser.ID == g.Player2.ID {
- isFlipped = true
- }
+ isFlipped := authUser.ID == g.Player2.ID
if c.Request().Method == http.MethodPost {
msg := c.Request().PostFormValue("message")
if msg == "resign" {
- resignColor := chess.White
- if isFlipped {
- resignColor = chess.Black
- }
+ resignColor := utils.Ternary(isFlipped, chess.Black, chess.White)
g.Game.Resign(resignColor)
v1.ChessPubSub.Pub(key, true)
} else {
@@ -4848,9 +4842,9 @@ func ChessGameHandler(c echo.Context) error {
return c.Redirect(http.StatusFound, c.Request().Referer())
}
- var isSpectator bool
- if authUser.ID != g.Player1.ID && authUser.ID != g.Player2.ID {
- isSpectator = true
+ isSpectator := authUser.ID != g.Player1.ID && authUser.ID != g.Player2.ID
+ if isSpectator && c.QueryParam("r") != "" {
+ isFlipped = true
}
isYourTurnFn := func() bool {
@@ -4891,9 +4885,6 @@ func ChessGameHandler(c echo.Context) error {
var card1 string
if isSpectator {
- if c.QueryParam("r") != "" {
- isFlipped = true
- }
card1 = g.DrawSpectatorCard(isFlipped)
} else {
card1 = g.DrawPlayerCard("", false, isFlipped, isYourTurn)