commit 65954df546348facef9b82f99532c61446d99bfa
parent bd2d2902069b2bf01bb5952040f1666efb6fb099
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Tue, 26 Dec 2023 12:26:15 -0500
add animations
Diffstat:
2 files changed, 20 insertions(+), 13 deletions(-)
diff --git a/pkg/web/handlers/poker/events.go b/pkg/web/handlers/poker/events.go
@@ -34,6 +34,7 @@ type CashBonusEvent struct {
PlayerSeatIdx int
Gain database.PokerChip
Animation bool
+ IsGain bool
}
type PlayerBetEvent struct {
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -321,9 +321,13 @@ func (p *PokerPlayer) refundBet(db *database.DkfDB, pokerTableID int64) {
p.gain(db, pokerTableID, p.GetBet())
}
-func (p *PokerPlayer) doBetAndNotif(db *database.DkfDB, pokerTableID int64, bet database.PokerChip, roomTopic string) {
- p.doBet(db, pokerTableID, bet)
- PubSub.Pub(roomTopic, PlayerBetEvent{PlayerSeatIdx: p.seatIdx, Player: p.username, Bet: bet, TotalBet: p.GetBet(), Cash: p.getCash()})
+func (p *PokerPlayer) doBetAndNotif(g *Game, bet database.PokerChip) {
+ p.doBet(g.db, g.pokerTableID, bet)
+ PubSub.Pub(g.roomID.Topic(), PlayerBetEvent{PlayerSeatIdx: p.seatIdx, Player: p.username, Bet: bet, TotalBet: p.GetBet(), Cash: p.getCash()})
+
+ seatIdx := p.seatIdx
+ g.seatsAnimation[seatIdx] = !g.seatsAnimation[seatIdx]
+ PubSub.Pub(g.roomID.Topic(), CashBonusEvent{PlayerSeatIdx: seatIdx, Gain: bet, Animation: g.seatsAnimation[seatIdx]})
}
type playerCard struct {
@@ -827,7 +831,7 @@ func doCall(g *Game, p *PokerPlayer,
return doAllIn(g, p, newlyAllInPlayers, lastBetPlayerIdx, playerToPlayIdx)
} else {
p.status.Set("call")
- p.doBetAndNotif(g.db, g.pokerTableID, bet, g.roomID.Topic())
+ p.doBetAndNotif(g, bet)
logMsg := fmt.Sprintf("%s call (%d)", pUsername, bet)
g.newLogEvent(logMsg)
}
@@ -844,7 +848,7 @@ func doAllIn(g *Game, p *PokerPlayer,
PubSub.Pub(g.roomID.Topic(), PokerMinRaiseUpdatedEvent{MinRaise: bet})
}
g.ongoing.minBet.Set(utils.MaxInt(p.GetBet()+bet, minBet))
- p.doBetAndNotif(g.db, g.pokerTableID, bet, g.roomID.Topic())
+ p.doBetAndNotif(g, bet)
logMsg := fmt.Sprintf("%s all-in (%d)", p.username, bet)
if p.isAllIn() {
*newlyAllInPlayers = append(*newlyAllInPlayers, p)
@@ -861,7 +865,6 @@ func doRaise(g *Game, p *PokerPlayer,
func doBet(g *Game, p *PokerPlayer,
newlyAllInPlayers *[]*PokerPlayer, lastBetPlayerIdx *int, playerToPlayIdx int, evtBet database.PokerChip) int {
- roomTopic := g.roomID.Topic()
roomUserTopic := g.roomID.UserTopic(p.userID)
minBet := g.ongoing.minBet.Get()
minRaise := g.ongoing.minRaise.Get()
@@ -884,7 +887,7 @@ func doBet(g *Game, p *PokerPlayer,
g.ongoing.minRaise.Set(evtBet)
g.ongoing.minBet.Set(playerTotalBet)
- p.doBetAndNotif(g.db, g.pokerTableID, bet, roomTopic)
+ p.doBetAndNotif(g, bet)
g.newLogEvent(fmt.Sprintf("%s %s %d", p.username, betLbl, g.ongoing.minRaise.Get()))
if p.hasChecked {
p.status.Set("check-" + betLbl)
@@ -1383,7 +1386,7 @@ func applyBigBlindBet(g *Game, bigBlindBet database.PokerChip, bbIdx int) {
func applyBlindBet(g *Game, playerIdx int, bet database.PokerChip, name string) {
p := g.ongoing.players[playerIdx]
- p.doBetAndNotif(g.db, g.pokerTableID, bet, g.roomID.Topic())
+ p.doBetAndNotif(g, bet)
g.newLogEvent(fmt.Sprintf("%s %s %d", p.username, name, bet))
}
@@ -1446,7 +1449,7 @@ func applyGains(g *Game, playersGain []PlayerGain, mainPot, rake database.PokerC
seatIdx := el.Player.seatIdx
g.seatsAnimation[seatIdx] = !g.seatsAnimation[seatIdx]
- PubSub.Pub(g.roomID.Topic(), CashBonusEvent{PlayerSeatIdx: seatIdx, Gain: el.Gain, Animation: g.seatsAnimation[seatIdx]})
+ PubSub.Pub(g.roomID.Topic(), CashBonusEvent{PlayerSeatIdx: seatIdx, Gain: el.Gain, Animation: g.seatsAnimation[seatIdx], IsGain: true})
}
for _, op := range ongoing.players {
op.gain(tx, pokerTableID, 0)
@@ -1830,9 +1833,14 @@ func buildSeatsHtml(g *Game, authUser *database.User) (html string) {
}
func drawCashBonus(evt CashBonusEvent) (html string) {
+ color := utils.Ternary(evt.IsGain, "#1ee91e", "red")
+ dur := utils.Ternary(evt.IsGain, "5s", "2s")
+ fontSize := utils.Ternary(evt.IsGain, "25px", "18px")
html += `<style>`
- html += fmt.Sprintf(`#seat%d .cash-bonus { animation: %s 5s cubic-bezier(0.25, 0.1, 0.25, 1) forwards; }`, evt.PlayerSeatIdx+1, utils.Ternary(evt.Animation, "cashBonusAnimation", "cashBonusAnimation1"))
- html += fmt.Sprintf(`#seat%d .cash-bonus:before { content: "+%s"; }`, evt.PlayerSeatIdx+1, evt.Gain)
+ html += fmt.Sprintf(`#seat%d .cash-bonus { animation: %s %s cubic-bezier(0.25, 0.1, 0.25, 1) forwards; color: %s; font-size: %s; }`,
+ evt.PlayerSeatIdx+1, utils.Ternary(evt.Animation, "cashBonusAnimation", "cashBonusAnimation1"), dur, color, fontSize)
+ html += fmt.Sprintf(`#seat%d .cash-bonus:before { content: "%s%s"; }`,
+ evt.PlayerSeatIdx+1, utils.Ternary(evt.IsGain, "+", "-"), evt.Gain)
html += `</style>`
return
}
@@ -2468,8 +2476,6 @@ body {
.cash-bonus {
z-index: 54;
position: absolute;
- font-size: 25px;
- color: #1ee91e;
background-color: rgba(0, 0, 0, 0.99);
padding: 1px 5px;
border-radius: 5px;