dkforest

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

commit b16a9f103d66027e6790e714c1c3ec8fb734be57
parent 155eeb470e9c15bf92797a71f20f4fa1d7598778
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sun, 11 Jun 2023 15:38:14 -0700

cleanup

Diffstat:
Mpkg/web/handlers/handlers.go | 48+++++++++++++++++++-----------------------------
1 file changed, 19 insertions(+), 29 deletions(-)

diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -5185,17 +5185,22 @@ Loop: continue } - x1, y1 := int(payload.Move.S1().File()), int(payload.Move.S1().Rank()) - x2, y2 := int(payload.Move.S2().File()), int(payload.Move.S2().Rank()) - if isFlipped { - x1 = 7 - x1 - x2 = 7 - x2 - } else { - y1 = 7 - y1 - y2 = 7 - y2 + animate := 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 + x2 = 7 - x2 + } else { + y1 = 7 - y1 + 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, 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))) } - 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))) + + animate(payload.Move.S1(), payload.Move.S2(), payload.IDStr1) _, _ = c.Response().Write([]byte(fmt.Sprintf(`<style>#%s { animation-name: move_anim_%d; animation-duration: 400ms; animation-fill-mode: forwards; }</style>`, payload.IDStr1, i))) if payload.IDStr2 != "" { _, _ = c.Response().Write([]byte(`<style>#` + payload.IDStr2 + ` { display: none; }</style>`)) @@ -5225,29 +5230,14 @@ Loop: }(payload, c) } - 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 - x2 = 7 - x2 - } else { - y1 = 7 - y1 - 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, 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") + animate(chess.H1, chess.F1, "img_7") } else if payload.Turn == chess.Black && payload.Move.HasTag(chess.KingSideCastle) { - animateCastle(chess.H8, chess.F8, "img_63") + animate(chess.H8, chess.F8, "img_63") } else if payload.Turn == chess.White && payload.Move.HasTag(chess.QueenSideCastle) { - animateCastle(chess.A1, chess.D1, "img_0") + animate(chess.A1, chess.D1, "img_0") } else if payload.Turn == chess.Black && payload.Move.HasTag(chess.QueenSideCastle) { - animateCastle(chess.A8, chess.D8, "img_56") + animate(chess.A8, chess.D8, "img_56") } _, _ = c.Response().Write([]byte(`<style>.square { background-color: transparent !important; }</style>`))