commit ee3ef9da627d62ff7e546cc5efbcf3acfbecf2ab
parent 34ae8fdfb6c47c23b191e13c1889e39656a98569
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Sun, 11 Jun 2023 22:03:04 -0700
cleanup
Diffstat:
2 files changed, 23 insertions(+), 55 deletions(-)
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -4928,41 +4928,7 @@ func chessGameEnPassant(g *interceptors.ChessGame) {
func ChessGameFormHandler(c echo.Context) error {
key := c.Param("key")
out := cssReset
- out += `<style>
-.newBoard {
- position: relative;
- aspect-ratio: 1 / 1;
- width: 100%;
- min-height: 360px;
-}
-.newBoard .img {
- position: absolute;
- width: 12.5%;
- height: 12.5%;
- background-size: 100%;
-}
-label {
- position: absolute;
- width: 12.5%;
- height: 12.5%;
-}
-input[type=checkbox] {
- display:none;
-}
-input[type=checkbox] + label {
- display: inline-block;
- padding: 0 0 0 0;
- margin: 0 0 0 0;
- background-size: 100%;
- border: 3px solid transparent;
- box-sizing: border-box;
-}
-input[type=checkbox]:checked + label {
- display: inline-block;
- background-size: 100%;
- border: 3px solid red;
-}
-</style>`
+ out += interceptors.ChessCSS
authUser := c.Get("authUser").(*database.User)
g := interceptors.ChessInstance.GetGame(key)
isFlipped := authUser.ID == g.Player2.ID
diff --git a/pkg/web/handlers/interceptors/chess.go b/pkg/web/handlers/interceptors/chess.go
@@ -129,25 +129,7 @@ func GetID(row, col int, isFlipped bool) int {
return id
}
-func (g *ChessGame) renderBoardHTML1(position *chess.Position, isFlipped bool, imgB64 string) string {
- moves := g.Game.Moves()
- var last *chess.Move
- if len(moves) > 0 {
- last = moves[len(moves)-1]
- }
- boardMap := position.Board().SquareMap()
-
- pieceInCheck := func(p chess.Piece) bool {
- return last != nil && p.Color() == g.Game.Position().Turn() && p.Type() == chess.King && last.HasTag(chess.Check)
- }
- sqIsLastMove := func(sq chess.Square) bool {
- return last != nil && (last.S1() == sq || last.S2() == sq)
- }
- getPieceFileName := func(p chess.Piece) string {
- return p.Color().String() + pieceTypeMap[p.Type()]
- }
-
- htmlTmpl := `
+var ChessCSS = `
<style>
.newBoard {
position: relative;
@@ -185,7 +167,27 @@ input[type=checkbox]:checked + label {
background-size: 100%;
border: 3px solid red;
}
-</style>
+</style>`
+
+func (g *ChessGame) renderBoardHTML1(position *chess.Position, isFlipped bool, imgB64 string) string {
+ moves := g.Game.Moves()
+ var last *chess.Move
+ if len(moves) > 0 {
+ last = moves[len(moves)-1]
+ }
+ boardMap := position.Board().SquareMap()
+
+ pieceInCheck := func(p chess.Piece) bool {
+ return last != nil && p.Color() == g.Game.Position().Turn() && p.Type() == chess.King && last.HasTag(chess.Check)
+ }
+ sqIsLastMove := func(sq chess.Square) bool {
+ return last != nil && (last.S1() == sq || last.S2() == sq)
+ }
+ getPieceFileName := func(p chess.Piece) string {
+ return p.Color().String() + pieceTypeMap[p.Type()]
+ }
+
+ htmlTmpl := ChessCSS + `
<table class="newBoard">
{{ range $row := .Rows }}
<tr>