dkforest

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

commit a0373fa1e6ad6bbf29f725428be8a7951befd8e7
parent b11ca02d5ce0b4dd231edde987b4f50eb5d00aa0
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon, 12 Jun 2023 12:16:12 -0700

cleanup

Diffstat:
Mpkg/web/handlers/handlers.go | 25++++++++-----------------
Mpkg/web/handlers/interceptors/chess.go | 17+++++++++++++----
2 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -5075,15 +5075,6 @@ func ChessGameHandler(c echo.Context) error { } send(fmt.Sprintf(`<div id="div_0">%s</div>`, card1)) - const ( - whiteKingID = "img_4" - blackKingID = "img_60" - whiteKingSideRookID = "img_7" - blackKingSideRookID = "img_63" - whiteQueenSideRookID = "img_0" - blackQueenSideRookID = "img_56" - ) - go func(c echo.Context, key string, p1ID, p2ID database.UserID) { p1Online := false p2Online := false @@ -5183,13 +5174,13 @@ Loop: // Animate rook during castle if payload.Move.S1() == chess.E1 && payload.Move.HasTag(chess.KingSideCastle) { - animate(chess.H1, chess.F1, whiteKingSideRookID) + animate(chess.H1, chess.F1, interceptors.WhiteKingSideRookID) } else if payload.Move.S1() == chess.E8 && payload.Move.HasTag(chess.KingSideCastle) { - animate(chess.H8, chess.F8, blackKingSideRookID) + animate(chess.H8, chess.F8, interceptors.BlackKingSideRookID) } else if payload.Move.S1() == chess.E1 && payload.Move.HasTag(chess.QueenSideCastle) { - animate(chess.A1, chess.D1, whiteQueenSideRookID) + animate(chess.A1, chess.D1, interceptors.WhiteQueenSideRookID) } else if payload.Move.S1() == chess.E8 && payload.Move.HasTag(chess.QueenSideCastle) { - animate(chess.A8, chess.D8, blackQueenSideRookID) + animate(chess.A8, chess.D8, interceptors.BlackQueenSideRookID) } // En passant if payload.EnPassant != "" { @@ -5217,13 +5208,13 @@ Loop: int(payload.Move.S1()), int(payload.Move.S2()), interceptors.LastMoveColor)) // Reset kings background to transparent - send(fmt.Sprintf(`<style>#%s { background-color: transparent !important; }</style>`, whiteKingID)) - send(fmt.Sprintf(`<style>#%s { background-color: transparent !important; }</style>`, blackKingID)) + send(fmt.Sprintf(`<style>#%s { background-color: transparent !important; }</style>`, interceptors.WhiteKingID)) + send(fmt.Sprintf(`<style>#%s { background-color: transparent !important; }</style>`, interceptors.BlackKingID)) // Render "checks" red background if payload.CheckW { - send(fmt.Sprintf(`<style>#%s { background-color: %s !important; }</style>`, whiteKingID, interceptors.CheckColor)) + send(fmt.Sprintf(`<style>#%s { background-color: %s !important; }</style>`, interceptors.WhiteKingID, interceptors.CheckColor)) } else if payload.CheckB { - send(fmt.Sprintf(`<style>#%s { background-color: %s !important; }</style>`, blackKingID, interceptors.CheckColor)) + send(fmt.Sprintf(`<style>#%s { background-color: %s !important; }</style>`, interceptors.BlackKingID, interceptors.CheckColor)) } c.Response().Flush() diff --git a/pkg/web/handlers/interceptors/chess.go b/pkg/web/handlers/interceptors/chess.go @@ -589,6 +589,15 @@ func (g *ChessGame) MoveStr(m string) { _ = g.Game.MoveStr(m) } +const ( + WhiteKingID = "img_4" + BlackKingID = "img_60" + WhiteKingSideRookID = "img_7" + BlackKingSideRookID = "img_63" + WhiteQueenSideRookID = "img_0" + BlackQueenSideRookID = "img_56" +) + func (g *ChessGame) updatePiecesCache(mov chess.Move) { idStr1 := g.PiecesCache[mov.S1()] delete(g.PiecesCache, mov.S1()) @@ -601,16 +610,16 @@ func (g *ChessGame) updatePiecesCache(mov chess.Move) { } if mov.S1() == chess.E1 && mov.HasTag(chess.KingSideCastle) { delete(g.PiecesCache, chess.H1) - g.PiecesCache[chess.F1] = "img_7" + g.PiecesCache[chess.F1] = WhiteKingSideRookID } else if mov.S1() == chess.E8 && mov.HasTag(chess.KingSideCastle) { delete(g.PiecesCache, chess.H8) - g.PiecesCache[chess.F8] = "img_63" + g.PiecesCache[chess.F8] = BlackKingSideRookID } else if mov.S1() == chess.E1 && mov.HasTag(chess.QueenSideCastle) { delete(g.PiecesCache, chess.A1) - g.PiecesCache[chess.D1] = "img_0" + g.PiecesCache[chess.D1] = WhiteQueenSideRookID } else if mov.S1() == chess.E8 && mov.HasTag(chess.QueenSideCastle) { delete(g.PiecesCache, chess.A8) - g.PiecesCache[chess.D8] = "img_56" + g.PiecesCache[chess.D8] = BlackQueenSideRookID } }