commit 175a17b946d1a209c176e8e70cda4b4114ad08e1
parent a5867d0a6f627cf05e7a066e164e75427277ce98
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Sun, 11 Jun 2023 21:46:03 -0700
dedup code
Diffstat:
2 files changed, 11 insertions(+), 21 deletions(-)
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -4971,16 +4971,6 @@ input[type=checkbox]:checked + label {
g := interceptors.ChessInstance.GetGame(key)
isFlipped := authUser.ID == g.Player2.ID
- getID := func(row, col int, isFlipped bool) int {
- var id int
- if isFlipped {
- id = row*8 + (7 - col)
- } else {
- id = (7-row)*8 + col
- }
- return id
- }
-
csrf, _ := c.Get("csrf").(string)
out += `<form method="post" action="/chess/` + key + `">
@@ -4988,7 +4978,7 @@ input[type=checkbox]:checked + label {
for row := 0; row < 8; row++ {
out += "<tr>"
for col := 0; col < 8; col++ {
- id := getID(row, col, isFlipped)
+ id := interceptors.GetID(row, col, isFlipped)
out += `<td><div class="idk">`
out += fmt.Sprintf(`<input name="sq_%d" id="sq_%d" type="checkbox" value="1" /><label for="sq_%d"></label>`, id, id, id)
out += "</div></td>"
@@ -5018,18 +5008,18 @@ input[type=checkbox]:checked + label {
func ChessGameHandler(c echo.Context) error {
authUser := c.Get("authUser").(*database.User)
- //db := c.Get("database").(*database.DkfDB)
+ db := c.Get("database").(*database.DkfDB)
key := c.Param("key")
g := interceptors.ChessInstance.GetGame(key)
if g == nil {
- //// Chess debug
- //user1, _ := db.GetUserByID(1)
- //user2, _ := db.GetUserByID(30814)
- //interceptors.ChessInstance.NewGame(key, user1, user2)
- //g = interceptors.ChessInstance.GetGame(key)
- ////chessGameKingSideCastle(g)
- return c.Redirect(http.StatusFound, "/")
+ // Chess debug
+ user1, _ := db.GetUserByID(1)
+ user2, _ := db.GetUserByID(30814)
+ interceptors.ChessInstance.NewGame(key, user1, user2)
+ g = interceptors.ChessInstance.GetGame(key)
+ chessGameEnPassant(g)
+ //return c.Redirect(http.StatusFound, "/")
}
isFlipped := authUser.ID == g.Player2.ID
diff --git a/pkg/web/handlers/interceptors/chess.go b/pkg/web/handlers/interceptors/chess.go
@@ -119,7 +119,7 @@ const (
LastMoveColor = "rgba(0, 255, 0, 0.2)"
)
-func getID(row, col int, isFlipped bool) int {
+func GetID(row, col int, isFlipped bool) int {
var id int
if isFlipped {
id = row*8 + (7 - col)
@@ -214,7 +214,7 @@ input[type=checkbox]:checked + label {
}
fns := template.FuncMap{
- "GetID": func(row, col int) int { return getID(row, col, isFlipped) },
+ "GetID": func(row, col int) int { return GetID(row, col, isFlipped) },
"IsLastMove": sqIsLastMove,
"PieceInCheck": pieceInCheck,
"GetPieceFileName": getPieceFileName,