commit 76bdb9e2df2504510e01d429b8f815a004923c00
parent b8507e2a947006f1dfac561d368486ee14fabc22
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Wed, 20 Dec 2023 23:15:20 -0500
configurable animation time
Diffstat:
1 file changed, 22 insertions(+), 19 deletions(-)
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -975,7 +975,7 @@ RoundIsSettled:
g.newLogEvent(fmt.Sprintf("--"))
setWaitTurn(g, -1)
- time.Sleep(time.Second)
+ time.Sleep(animationTime)
mainPot := ongoing.getMainPot()
@@ -1014,7 +1014,7 @@ func refundUncalledBet(db *database.DkfDB, ongoing *ongoingGame, pokerTableID in
if diff > 0 {
firstPlayer.refundPartialBet(db, pokerTableID, diff)
PokerPubSub.Pub(roomTopic, RedrawSeatsEvent{})
- time.Sleep(time.Second)
+ time.Sleep(animationTime)
}
}
@@ -1084,7 +1084,7 @@ func dealPlayersCards(g *PokerGame, seats []Seat, idx *int) {
}
roomUserTopic := roomID.UserTopic(pUserID)
seatData := seats[p.seatIdx]
- time.Sleep(time.Second)
+ time.Sleep(animationTime)
card = ongoing.deck[*idx]
*idx++
left := seatData.Left
@@ -1159,26 +1159,26 @@ func dealerThread(g *PokerGame) {
g.newLogEvent(fmt.Sprintf("-- New game --"))
applySmallBlindBet(g, bigBlindBet, sbIdx)
- time.Sleep(time.Second)
+ time.Sleep(animationTime)
applyBigBlindBet(g, bigBlindBet, bbIdx)
- time.Sleep(time.Second)
+ time.Sleep(animationTime)
// Deal players cards
dealPlayersCards(g, seats, &idx)
// Wait for players to bet/call/check/fold...
- time.Sleep(time.Second)
+ time.Sleep(animationTime)
skip := utils.Ternary(isHeadsUpGame, 1, 2)
if execBettingRound(g, skip, bigBlindBet) {
goto END
}
// Flop (3 first cards)
- time.Sleep(time.Second)
+ time.Sleep(animationTime)
burnCard(g, &idx, &burnIdx)
for i := 1; i <= 3; i++ {
- time.Sleep(time.Second)
+ time.Sleep(animationTime)
dealCard(g, &idx, i)
}
@@ -1190,31 +1190,31 @@ func dealerThread(g *PokerGame) {
skip = utils.Ternary(isHeadsUpGame, 1, 0)
// Wait for players to bet/call/check/fold...
- time.Sleep(time.Second)
+ time.Sleep(animationTime)
if execBettingRound(g, skip, 0) {
goto END
}
// Turn (4th card)
- time.Sleep(time.Second)
+ time.Sleep(animationTime)
burnCard(g, &idx, &burnIdx)
- time.Sleep(time.Second)
+ time.Sleep(animationTime)
dealCard(g, &idx, 4)
// Wait for players to bet/call/check/fold...
- time.Sleep(time.Second)
+ time.Sleep(animationTime)
if execBettingRound(g, skip, 0) {
goto END
}
// River (5th card)
- time.Sleep(time.Second)
+ time.Sleep(animationTime)
burnCard(g, &idx, &burnIdx)
- time.Sleep(time.Second)
+ time.Sleep(animationTime)
dealCard(g, &idx, 5)
// Wait for players to bet/call/check/fold...
- time.Sleep(time.Second)
+ time.Sleep(animationTime)
if execBettingRound(g, skip, 0) {
goto END
}
@@ -1493,7 +1493,7 @@ func (g *PokerGame) Deal(roomID RoomID, userID database.UserID) {
PokerPubSub.Pub(roomUserTopic, ErrorMsgEvent{Message: ""})
PokerPubSub.Pub(roomTopic, ResetCardsEvent{})
- time.Sleep(time.Second)
+ time.Sleep(animationTime)
go dealerThread(g)
}
@@ -1560,6 +1560,8 @@ func buildDealerTokenHtml(g *PokerGame) (html string) {
return
}
+const animationTime = 1000 * time.Millisecond
+
func BuildPayloadHtml(g *PokerGame, authUser *database.User, payload any) (html string) {
switch evt := payload.(type) {
case GameStartedEvent:
@@ -1589,7 +1591,8 @@ func BuildPayloadHtml(g *PokerGame, authUser *database.User, payload any) (html
case PokerYourTurnEvent:
html += drawYourTurnHtml(authUser)
case PokerEvent:
- html += getPokerEventHtml(evt, "1s")
+ fmt.Println(animationTime.String())
+ html += getPokerEventHtml(evt, animationTime.String())
case PokerMainPotUpdatedEvent:
html += drawMainPotHtml(evt)
}
@@ -1853,7 +1856,7 @@ func drawResetCardsEvent() (html string) {
html += `<style>`
for i := 1; i <= 52; i++ {
idxStr := itoa(i)
- html += `#card` + idxStr + ` { transition: 1s ease-in-out; transform: translateX(` + itoa(DealerStackX) + `px) translateY(` + itoa(DealerStackY) + `px) rotateY(` + BackfacingDeg + `); }
+ html += `#card` + idxStr + ` { transition: ` + animationTime.String() + ` ease-in-out; transform: translateX(` + itoa(DealerStackX) + `px) translateY(` + itoa(DealerStackY) + `px) rotateY(` + BackfacingDeg + `); }
#card` + idxStr + ` .card .inner:before { content: ""; }`
}
html += `
@@ -1866,7 +1869,7 @@ func drawResetCardsEvent() (html string) {
func drawPlayerFoldEvent(evt PlayerFoldEvent) (html string) {
idx1Str := itoa(evt.Card1Idx)
idx2Str := itoa(evt.Card2Idx)
- transition := fmt.Sprintf(`transition: 1s ease-in-out; transform: translateX(%spx) translateY(%spx) rotateY(%s);`, itoa(BurnStackX), itoa(BurnStackY), BackfacingDeg)
+ transition := fmt.Sprintf(`transition: `+animationTime.String()+` ease-in-out; transform: translateX(%spx) translateY(%spx) rotateY(%s);`, itoa(BurnStackX), itoa(BurnStackY), BackfacingDeg)
html = fmt.Sprintf(`<style>#card%s, #card%s { %s }</style>`, idx1Str, idx2Str, transition)
return
}