dkforest

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

commit fa6c0dc5f0d492d9bf3dbd2d342222b75ac5457b
parent a1c80066d0e5a817b2a6bdc42bd987578760d58b
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sun, 17 Dec 2023 22:38:05 -0500

proper render auto action text when page refresh

Diffstat:
Mpkg/web/handlers/poker/poker.go | 42++++++++++++++++++++++++++----------------
1 file changed, 26 insertions(+), 16 deletions(-)

diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -90,14 +90,15 @@ type PlayerEvent struct { var PokerInstance = NewPoker() type Ongoing struct { - Deck []string - Players []*PokerPlayer - Events utils.RWMtx[[]PokerEvent] - LogEvents utils.RWMtx[[]LogEvent] - CommunityCards []string - WaitTurnEvent utils.RWMtx[PokerWaitTurnEvent] - CreatedAt time.Time - mainPot atomic.Uint64 + Deck []string + Players []*PokerPlayer + Events utils.RWMtx[[]PokerEvent] + LogEvents utils.RWMtx[[]LogEvent] + CommunityCards []string + WaitTurnEvent utils.RWMtx[PokerWaitTurnEvent] + AutoActionEvent utils.RWMtx[AutoActionEvent] + CreatedAt time.Time + mainPot atomic.Uint64 } type SeatedPlayer struct { @@ -535,6 +536,12 @@ func setWaitTurn(g *PokerGame, seatIdx int) { g.Ongoing.WaitTurnEvent.With(func(v *PokerWaitTurnEvent) { *v = evt }) } +func setAutoAction(g *PokerGame, roomUserTopic, msg string) { + evt := AutoActionEvent{Message: msg} + PokerPubSub.Pub(roomUserTopic, evt) + g.Ongoing.AutoActionEvent.With(func(v *AutoActionEvent) { *v = evt }) +} + const ( NoAction = iota FoldAction @@ -730,24 +737,24 @@ RoundIsSettledLoop: evt.Call && autoAction.v == CallAction || evt.Check && autoAction.v == CheckAction { delete(autoCache, evt.Player) - PokerPubSub.Pub(roomUserTopic, AutoActionEvent{Message: ""}) + setAutoAction(g, roomUserTopic, "") return continueGetPlayerEventLoop } if evt.Fold { autoCache[evt.Player] = AutoAction{v: FoldAction, evt: evt} - PokerPubSub.Pub(roomUserTopic, AutoActionEvent{Message: "Will auto fold"}) + setAutoAction(g, roomUserTopic, "Will auto fold") } else if evt.Call { autoCache[evt.Player] = AutoAction{v: CallAction, evt: evt} - PokerPubSub.Pub(roomUserTopic, AutoActionEvent{Message: "Will auto call"}) + setAutoAction(g, roomUserTopic, "Will auto call") } else if evt.Check { autoCache[evt.Player] = AutoAction{v: CheckAction, evt: evt} - PokerPubSub.Pub(roomUserTopic, AutoActionEvent{Message: "Will auto check"}) + setAutoAction(g, roomUserTopic, "Will auto check") } else if evt.Bet > 0 { autoCache[evt.Player] = AutoAction{v: BetAction, evt: evt} - PokerPubSub.Pub(roomUserTopic, AutoActionEvent{Message: "Will auto bet " + evt.Bet.String()}) + setAutoAction(g, roomUserTopic, "Will auto bet"+evt.Bet.String()) } else if evt.AllIn { autoCache[evt.Player] = AutoAction{v: AllInAction, evt: evt} - PokerPubSub.Pub(roomUserTopic, AutoActionEvent{Message: "Will auto all-in"}) + setAutoAction(g, roomUserTopic, "Will auto all-in") } return continueGetPlayerEventLoop } @@ -789,7 +796,7 @@ RoundIsSettledLoop: } } delete(autoCache, pUsername) - PokerPubSub.Pub(roomUserTopic, AutoActionEvent{Message: ""}) + setAutoAction(g, roomUserTopic, "") return } @@ -848,7 +855,7 @@ RoundIsSettledLoop: RoundIsSettled: - PokerPubSub.Pub(roomTopic, AutoActionEvent{Message: ""}) + setAutoAction(g, roomTopic, "") PokerPubSub.Pub(roomTopic, ErrorMsgEvent{Message: ""}) g.newLogEvent(fmt.Sprintf("--")) setWaitTurn(g, -1) @@ -1669,6 +1676,9 @@ func buildBaseHtml(g *PokerGame, authUser *database.User, playerBuyIn database.P ongoing.WaitTurnEvent.RWith(func(v *PokerWaitTurnEvent) { html += drawCountDownStyle(*v) }) + ongoing.AutoActionEvent.RWith(func(v *AutoActionEvent) { + html += drawAutoActionMsgEvent(*v) + }) ongoing.Events.RWith(func(v *[]PokerEvent) { for _, evt := range *v {