commit bd2d2902069b2bf01bb5952040f1666efb6fb099
parent 5f27eab28a7593b8c27413ab695e2874defc9a80
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Tue, 26 Dec 2023 12:09:39 -0500
add cash-bonus animation
Diffstat:
2 files changed, 67 insertions(+), 0 deletions(-)
diff --git a/pkg/web/handlers/poker/events.go b/pkg/web/handlers/poker/events.go
@@ -30,6 +30,12 @@ type GameIsDoneEvent struct {
type ResetCardsEvent struct {
}
+type CashBonusEvent struct {
+ PlayerSeatIdx int
+ Gain database.PokerChip
+ Animation bool
+}
+
type PlayerBetEvent struct {
PlayerSeatIdx int
Player database.Username
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -93,6 +93,7 @@ func (p *Poker) newGame(db *database.DkfDB, roomID RoomID, pokerTableID int64,
pokerTableIsTest: pokerTableIsTest,
playersEventCh: make(chan playerEvent),
Players: rwmtx.New(make(seatedPlayers, NbPlayers)),
+ seatsAnimation: make([]bool, NbPlayers),
dealerSeatIdx: atomic.Int32{},
}
g.dealerSeatIdx.Store(-1)
@@ -332,6 +333,7 @@ type playerCard struct {
type Game struct {
Players rwmtx.RWMtx[seatedPlayers]
+ seatsAnimation []bool
ongoing *ongoingGame
db *database.DkfDB
roomID RoomID
@@ -1441,6 +1443,10 @@ func applyGains(g *Game, playersGain []PlayerGain, mainPot, rake database.PokerC
g.newLogEvent(fmt.Sprintf("Winner #%d: %s %s -> %d", el.Group, el.Player.username, el.HandStr, el.Gain))
winnersStr += el.Player.username.String() + " "
el.Player.gain(tx, pokerTableID, el.Gain)
+
+ 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]})
}
for _, op := range ongoing.players {
op.gain(tx, pokerTableID, 0)
@@ -1650,6 +1656,8 @@ func BuildPayloadHtml(g *Game, authUser *database.User, payload any) (html strin
html += drawPlayerFoldEvent(evt)
case ResetCardsEvent:
html += drawResetCardsEvent()
+ case CashBonusEvent:
+ html += drawCashBonus(evt)
case RedrawSeatsEvent:
html += drawSeatsStyle(authUser, g)
case PokerSeatTakenEvent:
@@ -1807,6 +1815,7 @@ func buildSeatsHtml(g *Game, authUser *database.User) (html string) {
for i := range gPlayers {
idxStr := itoa(i + 1)
html += `<div class="seat" id="seat` + idxStr + `">`
+ html += ` <div class="cash-bonus"></div>`
html += ` <div class="throne"></div>`
html += ` <iframe src="/poker/` + g.roomID.String() + `/sit/` + idxStr + `" class="takeSeat takeSeat` + idxStr + `"></iframe>`
html += ` <div class="inner"></div>`
@@ -1820,6 +1829,14 @@ func buildSeatsHtml(g *Game, authUser *database.User) (html string) {
return html
}
+func drawCashBonus(evt CashBonusEvent) (html string) {
+ 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 += `</style>`
+ return
+}
+
func drawSeatsStyle(authUser *database.User, g *Game) string {
ongoing := g.ongoing
html := "<style>"
@@ -2416,4 +2433,48 @@ body {
}
}
+@keyframes cashBonusAnimation {
+ 0% {
+ opacity: 1;
+ transform: translateY(0);
+ }
+ 66.66% {
+ opacity: 1;
+ transform: translateY(0);
+ transform: translateY(-15px);
+ }
+ 100% {
+ opacity: 0;
+ transform: translateY(-30px); /* Adjust the distance it moves up */
+ }
+}
+
+@keyframes cashBonusAnimation1 {
+ 0% {
+ opacity: 1;
+ transform: translateY(0);
+ }
+ 66.66% {
+ opacity: 1;
+ transform: translateY(0);
+ transform: translateY(-15px);
+ }
+ 100% {
+ opacity: 0;
+ transform: translateY(-30px); /* Adjust the distance it moves up */
+ }
+}
+
+.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;
+ opacity: 0;
+ font-family: Arial,Helvetica,sans-serif;
+}
+
</style>`