commit 769b5d74ae9def3c967a3428197794c225a4465a
parent a105bf0871c29647f1986494900dca064acb739e
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Tue, 5 Dec 2023 19:39:45 -0500
cleanup
Diffstat:
1 file changed, 61 insertions(+), 55 deletions(-)
diff --git a/pkg/web/handlers/poker.go b/pkg/web/handlers/poker.go
@@ -782,6 +782,63 @@ func buildSeatsHtml(g *PokerGame) string {
return seats
}
+func drawSeatsHtml(authUser *database.User, g *PokerGame) string {
+ html := "<style>"
+ seated, _ := g.IsSeated(authUser.Username.String())
+ for i, p := range g.Players {
+ if p.Username != "" || seated {
+ html += `.takeSeat` + strconv.Itoa(i+1) + ` { display: none; }`
+ } else {
+ html += `.takeSeat` + strconv.Itoa(i+1) + ` { display: block; }`
+ }
+ if p.Username != "" {
+ html += `#seat` + strconv.Itoa(i+1) + `:before { content: "` + p.Username + `"; }`
+ html += `#seat` + strconv.Itoa(i+1) + `_cash:before { content: "` + strconv.Itoa(p.Cash) + `"; }`
+ } else {
+ html += `#seat` + strconv.Itoa(i+1) + `:before { content: ""; }`
+ html += `#seat` + strconv.Itoa(i+1) + `_cash:before { content: ""; }`
+ }
+ }
+ html += "</style>"
+ return html
+}
+
+func drawCountDownStyle(evt PokerWaitTurnEvent) string {
+ html := "<style>"
+ html += `#countdown1, #countdown2, #countdown3, #countdown4, #countdown5, #countdown6 { display: none; }`
+ if evt.Idx == -1 {
+ html += `#mainPot:before { content: "Pot: ` + strconv.Itoa(evt.MainPot) + `"; }`
+ } else if evt.Idx == 0 {
+ html += `#countdown1 { top: 50px; left: 600px; display: block; animation: time calc(var(--duration) * 1s) steps(1000, start) forwards; }`
+ } else if evt.Idx == 1 {
+ html += `#countdown2 { top: 150px; left: 574px; display: block; animation: time calc(var(--duration) * 1s) steps(1000, start) forwards; }`
+ } else if evt.Idx == 2 {
+ html += `#countdown3 { top: 250px; left: 530px; display: block; animation: time calc(var(--duration) * 1s) steps(1000, start) forwards; }`
+ }
+ html += "</style>"
+ return html
+}
+
+func getPokerEventHtml(payload PokerEvent, animationTime string) string {
+ transform := `transform: translate(` + strconv.Itoa(payload.Left) + `px, ` + strconv.Itoa(payload.Top) + `px)`
+ if payload.Angle != "" {
+ transform += ` rotateZ(` + payload.Angle + `)`
+ }
+ if !payload.Reveal {
+ transform += ` rotateY(` + BackfacingDeg + `)`
+ }
+ transform += ";"
+ pokerEvtHtml := `<style>
+#` + payload.ID + ` {
+ z-index: ` + strconv.Itoa(payload.Idx) + `;
+ transition: ` + animationTime + ` ease-in-out;
+ ` + transform + `
+}
+#` + payload.ID + ` .card .inner:before { content: "` + payload.Name + `"; color: ` + colorForCard1(payload.Name) + `; }
+</style>`
+ return pokerEvtHtml
+}
+
var pokerCss = `<style>
html, body { height: 100%; width: 100%; }
body {
@@ -944,57 +1001,6 @@ func PokerHandler(c echo.Context) error {
send(cssReset)
send(pokerCss)
- drawCountDownStyle := func(evt PokerWaitTurnEvent) {
- send(`<style>#countdown1, #countdown2, #countdown3, #countdown4, #countdown5, #countdown6 { display: none; }</style>`)
- if evt.Idx == -1 {
- send(`<style>#mainPot:before { content: "Pot: ` + strconv.Itoa(evt.MainPot) + `"; }</style>`)
- } else if evt.Idx == 0 {
- send(`<style>#countdown1 { top: 50px; left: 600px; display: block; animation: time calc(var(--duration) * 1s) steps(1000, start) forwards; }</style>`)
- } else if evt.Idx == 1 {
- send(`<style>#countdown2 { top: 150px; left: 574px; display: block; animation: time calc(var(--duration) * 1s) steps(1000, start) forwards; }</style>`)
- } else if evt.Idx == 2 {
- send(`<style>#countdown3 { top: 250px; left: 530px; display: block; animation: time calc(var(--duration) * 1s) steps(1000, start) forwards; }</style>`)
- }
- }
-
- drawSeats := func() {
- seated, _ := g.IsSeated(authUser.Username.String())
- for i, p := range g.Players {
- if p.Username != "" || seated {
- send(`<style>.takeSeat` + strconv.Itoa(i+1) + ` { display: none; }</style>`)
- } else {
- send(`<style>.takeSeat` + strconv.Itoa(i+1) + ` { display: block; }</style>`)
- }
- if p.Username != "" {
- send(`<style>#seat` + strconv.Itoa(i+1) + `:before { content: "` + p.Username + `"; }</style>`)
- send(`<style>#seat` + strconv.Itoa(i+1) + `_cash:before { content: "` + strconv.Itoa(p.Cash) + `"; }</style>`)
- } else {
- send(`<style>#seat` + strconv.Itoa(i+1) + `:before { content: ""; }</style>`)
- send(`<style>#seat` + strconv.Itoa(i+1) + `_cash:before { content: ""; }</style>`)
- }
- }
- }
-
- getPokerEventHtml := func(payload PokerEvent, animationTime string) string {
- transform := `transform: translate(` + strconv.Itoa(payload.Left) + `px, ` + strconv.Itoa(payload.Top) + `px)`
- if payload.Angle != "" {
- transform += ` rotateZ(` + payload.Angle + `)`
- }
- if !payload.Reveal {
- transform += ` rotateY(` + BackfacingDeg + `)`
- }
- transform += ";"
- pokerEvtHtml := `<style>
-#` + payload.ID + ` {
- z-index: ` + strconv.Itoa(payload.Idx) + `;
- transition: ` + animationTime + ` ease-in-out;
- ` + transform + `
-}
-#` + payload.ID + ` .card .inner:before { content: "` + payload.Name + `"; color: ` + colorForCard1(payload.Name) + `; }
-</style>`
- return pokerEvtHtml
- }
-
cardsHtml := ""
for i := 52; i >= 1; i-- {
cardsHtml += `<div class="card-holder" id="card` + strconv.Itoa(i) + `"><div class="back"></div><div class="card"><div class=inner></div></div></div>`
@@ -1017,7 +1023,7 @@ func PokerHandler(c echo.Context) error {
send(`<div id="countdown5" class="timer" style="--duration: ` + strconv.Itoa(MaxUserCountdown) + `;--size: 30;"><div class="mask"></div></div>`)
send(`<div id="countdown6" class="timer" style="--duration: ` + strconv.Itoa(MaxUserCountdown) + `;--size: 30;"><div class="mask"></div></div>`)
if g.Ongoing != nil {
- drawCountDownStyle(g.Ongoing.WaitTurnEvent)
+ send(drawCountDownStyle(g.Ongoing.WaitTurnEvent))
}
send(`<div id="deckStr"></div>`)
if g.Ongoing != nil && g.IsGameDone {
@@ -1050,7 +1056,7 @@ Loop:
}
if _, ok := payload.(PokerSeatLeftEvent); ok {
- drawSeats()
+ send(drawSeatsHtml(authUser, g))
c.Response().Flush()
continue
@@ -1124,12 +1130,12 @@ Loop:
continue
} else if _, ok := payload.(PokerSeatTakenEvent); ok {
- drawSeats()
+ send(drawSeatsHtml(authUser, g))
c.Response().Flush()
continue
} else if evt, ok := payload.(PokerWaitTurnEvent); ok {
- drawCountDownStyle(evt)
+ send(drawCountDownStyle(evt))
c.Response().Flush()
continue