commit 6f5554e3f2f6ea714060995ea1a6ae62227eef16
parent 95040ebadc092d9e6dfa72026950779c19846ea3
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Wed, 14 Jun 2023 23:57:26 -0700
fix promotions
Diffstat:
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/pkg/web/handlers/chess.go b/pkg/web/handlers/chess.go
@@ -515,7 +515,7 @@ func ChessGameHandler(c echo.Context) error {
logrus.Error(err)
return c.Redirect(http.StatusFound, "/")
}
- g.MakeMoves(queenSideCastleGame, db)
+ g.MakeMoves(promoWGame, db)
} else {
return c.Redirect(http.StatusFound, "/")
}
@@ -632,6 +632,7 @@ Loop:
if game.Outcome() != chess.NoOutcome && gameLoadedOver {
if payload.MoveIdx != 0 {
pos := game.Positions()[payload.MoveIdx]
+ boardMap := pos.Board().SquareMap()
moves := game.Moves()[:payload.MoveIdx]
lastMove := moves[len(moves)-1]
checkIDStr := ""
@@ -664,7 +665,10 @@ Loop:
if pos.Board().Piece(sq) != chess.NoPiece {
sqID := piecesCache[sq]
x1, y1 := squareCoord(sq, isFlipped)
- styles.Appendf(`#%s { display: block !important; left: calc(%d*12.5%%) !important; top: calc(%d*12.5%%) !important; }`,
+ p := boardMap[sq]
+ styles.Appendf("#%s { display: block !important; "+
+ "left: calc(%d*12.5%%) !important; top: calc(%d*12.5%%) !important; "+
+ "background-image: url(/public/img/chess/"+p.Color().String()+pieceTypeMap[p.Type()]+".png) !important; }",
sqID, x1, y1)
}
}
@@ -768,3 +772,12 @@ Loop:
}
return nil
}
+
+var pieceTypeMap = map[chess.PieceType]string{
+ chess.King: "K",
+ chess.Queen: "Q",
+ chess.Rook: "R",
+ chess.Bishop: "B",
+ chess.Knight: "N",
+ chess.Pawn: "P",
+}