commit 9b97c27126b475f7743633b76a5771601725429d
parent 238edd1b95bd1f7884557f3c64f29497fb92d969
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Sun, 11 Jun 2023 15:32:59 -0700
cleanup
Diffstat:
1 file changed, 14 insertions(+), 51 deletions(-)
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -5230,66 +5230,29 @@ Loop:
}(payload, c)
}
- 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())
+ animateCastle := func(s1, s2 chess.Square, id string) {
+ x1, y1 := int(s1.File()), int(s1.Rank())
+ x2, y2 := int(s2.File()), int(s2.Rank())
if isFlipped {
x1 = 7 - x1
- x = 7 - x
+ x2 = 7 - x2
} else {
y1 = 7 - y1
- y = 7 - y
+ y2 = 7 - y2
}
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)))
+ _, _ = 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, x2, y2)))
+ _, _ = c.Response().Write([]byte(fmt.Sprintf(`<style>#%s { animation-name: move_anim_%d; animation-duration: 400ms; animation-fill-mode: forwards; }</style>`, id, i)))
+ }
+
+ if payload.Turn == chess.White && payload.Move.HasTag(chess.KingSideCastle) {
+ animateCastle(chess.H1, chess.F1, "img_7")
} 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
- }
- 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)))
+ animateCastle(chess.H8, chess.F8, "img_63")
} 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
- }
- 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)))
+ animateCastle(chess.A1, chess.D1, "img_0")
} 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
- }
- 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)))
+ animateCastle(chess.A8, chess.D8, "img_56")
}
_, _ = c.Response().Write([]byte(`<style>.square { background-color: transparent !important; }</style>`))