dkforest

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

commit 6f3c7c49ca79cc5adefdbe285eeafd1eacf04270
parent 6b6b7201c3b6725cffc0dbc13a85f6899bc56397
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sun, 11 Jun 2023 14:54:02 -0700

fix rook after castle

Diffstat:
Mpkg/web/handlers/handlers.go | 34+++++++++++++++++++++++++++++-----
Mpkg/web/handlers/interceptors/chess.go | 1-
2 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -5094,7 +5094,7 @@ func ChessGameHandler(c echo.Context) error { user2, _ := db.GetUserByID(30814) interceptors.ChessInstance.NewGame(key, user1, user2) g = interceptors.ChessInstance.GetGame(key) - chessGameQueenSideCastle(g) + chessGameKingSideCastle(g) //return c.Redirect(http.StatusFound, "/") } @@ -5231,41 +5231,65 @@ Loop: } if payload.Turn == chess.White && payload.Move.HasTag(chess.KingSideCastle) { + x1 := int(chess.H1.File()) + y1 := int(chess.H1.Rank()) x := int(chess.F1.File()) y := int(chess.F1.Rank()) if isFlipped { + x1 = 7 - x1 x = 7 - x } else { + y1 = 7 - y1 y = 7 - y } - _, _ = c.Response().Write([]byte(fmt.Sprintf(`<style>#img_7 { left: calc(%d*12.5%%) !important; top: calc(%d*12.5%%) !important; }</style>`, x, y))) + i++ + _, _ = c.Response().Write([]byte(fmt.Sprintf(`<style>@keyframes move_anim_%d { from { left: calc(%d*12.5%%); top: calc(%d*12.5%%); } to { left: calc(%d*12.5%%); top: calc(%d*12.5%%); } }</style>`, i, x1, y1, x, y))) + _, _ = c.Response().Write([]byte(fmt.Sprintf(`<style>#img_7 { animation-name: move_anim_%d; animation-duration: 400ms; animation-fill-mode: forwards; }</style>`, i))) } else if payload.Turn == chess.Black && payload.Move.HasTag(chess.KingSideCastle) { + x1 := int(chess.H8.File()) + y1 := int(chess.H8.Rank()) x := int(chess.F8.File()) y := int(chess.F8.Rank()) if isFlipped { + x1 = 7 - x1 x = 7 - x } else { + y1 = 7 - y1 y = 7 - y } - _, _ = c.Response().Write([]byte(fmt.Sprintf(`<style>#img_63 { left: calc(%d*12.5%%) !important; top: calc(%d*12.5%%) !important; }</style>`, x, y))) + i++ + _, _ = c.Response().Write([]byte(fmt.Sprintf(`<style>@keyframes move_anim_%d { from { left: calc(%d*12.5%%); top: calc(%d*12.5%%); } to { left: calc(%d*12.5%%); top: calc(%d*12.5%%); } }</style>`, i, x1, y1, x, y))) + _, _ = c.Response().Write([]byte(fmt.Sprintf(`<style>#img_63 { animation-name: move_anim_%d; animation-duration: 400ms; animation-fill-mode: forwards; }</style>`, i))) } else if payload.Turn == chess.White && payload.Move.HasTag(chess.QueenSideCastle) { + x1 := int(chess.A1.File()) + y1 := int(chess.A1.Rank()) x := int(chess.D1.File()) y := int(chess.D1.Rank()) if isFlipped { + x1 = 7 - x1 x = 7 - x } else { + y1 = 7 - y1 y = 7 - y } - _, _ = c.Response().Write([]byte(fmt.Sprintf(`<style>#img_0 { left: calc(%d*12.5%%) !important; top: calc(%d*12.5%%) !important; }</style>`, x, y))) + i++ + _, _ = c.Response().Write([]byte(fmt.Sprintf(`<style>@keyframes move_anim_%d { from { left: calc(%d*12.5%%); top: calc(%d*12.5%%); } to { left: calc(%d*12.5%%); top: calc(%d*12.5%%); } }</style>`, i, x1, y1, x, y))) + _, _ = c.Response().Write([]byte(fmt.Sprintf(`<style>#img_0 { animation-name: move_anim_%d; animation-duration: 400ms; animation-fill-mode: forwards; }</style>`, i))) } else if payload.Turn == chess.Black && payload.Move.HasTag(chess.QueenSideCastle) { + x1 := int(chess.A8.File()) + y1 := int(chess.A8.Rank()) x := int(chess.D8.File()) y := int(chess.D8.Rank()) if isFlipped { + x1 = 7 - x1 x = 7 - x } else { + y1 = 7 - y1 y = 7 - y } - _, _ = c.Response().Write([]byte(fmt.Sprintf(`<style>#img_56 { left: calc(%d*12.5%%) !important; top: calc(%d*12.5%%) !important; }</style>`, x, y))) + i++ + _, _ = c.Response().Write([]byte(fmt.Sprintf(`<style>@keyframes move_anim_%d { from { left: calc(%d*12.5%%); top: calc(%d*12.5%%); } to { left: calc(%d*12.5%%); top: calc(%d*12.5%%); } }</style>`, i, x1, y1, x, y))) + _, _ = c.Response().Write([]byte(fmt.Sprintf(`<style>#img_56 { animation-name: move_anim_%d; animation-duration: 400ms; animation-fill-mode: forwards; }</style>`, i))) } _, _ = c.Response().Write([]byte(`<style>.square { background-color: transparent !important; }</style>`)) diff --git a/pkg/web/handlers/interceptors/chess.go b/pkg/web/handlers/interceptors/chess.go @@ -204,7 +204,6 @@ input[type=checkbox]:checked + label { x := i % 8 y := i / 8 pidStr := g.PiecesCache[sq] - //out += `<img id="` + pidStr + `" src="/public/img/chess/` + p.Color().String() + pieceTypeMap[p.Type()] + `.png" alt="" style="left: calc(` + strconv.Itoa(x) + `*12.5%); top: calc(` + strconv.Itoa(y) + `*12.5%);` out += `<div id="` + pidStr + `" class="img" style="left: calc(` + strconv.Itoa(x) + `*12.5%); top: calc(` + strconv.Itoa(y) + `*12.5%); background-image: url(/public/img/chess/` + p.Color().String() + pieceTypeMap[p.Type()] + `.png);` if last != nil && p.Color() == g.Game.Position().Turn() && p.Type() == chess.King && last.HasTag(chess.Check) { out += ` background-color: rgba(255, 0, 0, 0.4);`