commit 28484f4cc42ff4d6fd9062d7a6461757392bbf3f
parent da229e68071e85b172548a3ca76a877503886347
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Tue, 19 Dec 2023 00:26:45 -0500
cleanup
Diffstat:
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -138,7 +138,7 @@ func (p *SeatedPlayer) isEligible(pokerTableMinBet database.PokerChip) bool {
type PokerPlayer struct {
*SeatedPlayer
Bet utils.RWMtx[database.PokerChip]
- Cards utils.RWMtx[[]PlayerCard]
+ Cards utils.RWMtx[[]playerCard]
Folded atomic.Bool
Unsit atomic.Bool
GameBet database.PokerChip
@@ -200,12 +200,14 @@ func (p *PokerPlayer) doBetAndNotif(db *database.DkfDB, pokerTableID int64, bet
PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerSeatIdx: p.SeatIdx, Player: p.Username, Bet: bet, TotalBet: p.GetBet(), Cash: p.GetCash()})
}
-type PlayerCard struct {
- Idx int
- Name string
+type playerCard struct {
+ idx int
+ name string
}
type PokerGame struct {
+ Players utils.RWMtx[[]*SeatedPlayer]
+ Ongoing *Ongoing
db *database.DkfDB
roomID RoomID
pokerTableID int64
@@ -213,8 +215,6 @@ type PokerGame struct {
PokerTableMinBet database.PokerChip
pokerTableIsTest bool
playersEventCh chan PlayerEvent
- Players utils.RWMtx[[]*SeatedPlayer]
- Ongoing *Ongoing
dealerSeatIdx atomic.Int32
isGameStarted atomic.Bool
}
@@ -289,9 +289,9 @@ func (g *Ongoing) computeWinners() (winner []gameResult) {
}
var playerCard1, playerCard2 string
- p.Cards.RWith(func(pCards *[]PlayerCard) {
- playerCard1 = (*pCards)[0].Name
- playerCard2 = (*pCards)[1].Name
+ p.Cards.RWith(func(pCards *[]playerCard) {
+ playerCard1 = (*pCards)[0].name
+ playerCard2 = (*pCards)[1].name
})
communityCards := g.communityCards
@@ -482,9 +482,9 @@ func (g *PokerGame) unSitPlayer1(gPlayers *[]*SeatedPlayer, seatedPlayer *Seated
if player := ongoing.getPlayer(seatedPlayerUserID); player != nil {
g.UnSit(player.UserID)
player.Folded.Store(true)
- player.Cards.RWith(func(playerCards *[]PlayerCard) {
+ player.Cards.RWith(func(playerCards *[]playerCard) {
for _, card := range *playerCards {
- evt := PokerEvent{ID: "card" + itoa(card.Idx), Name: "", Idx: card.Idx, Top: BurnStackY, Left: BurnStackX, Angle: "0deg", Reveal: false}
+ evt := PokerEvent{ID: "card" + itoa(card.idx), Name: "", Idx: card.idx, Top: BurnStackY, Left: BurnStackX, Angle: "0deg", Reveal: false}
PokerPubSub.Pub(roomTopic, evt)
ongoing.addEvent(evt)
}
@@ -534,8 +534,8 @@ func showCards(g *PokerGame, seats []Seat) {
roomTopic := g.roomID.Topic()
for _, p := range ongoing.Players {
if !p.Folded.Load() {
- var firstCard, secondCard PlayerCard
- p.Cards.RWith(func(pCards *[]PlayerCard) {
+ var firstCard, secondCard playerCard
+ p.Cards.RWith(func(pCards *[]playerCard) {
firstCard = (*pCards)[0]
secondCard = (*pCards)[1]
})
@@ -547,8 +547,8 @@ func showCards(g *PokerGame, seats []Seat) {
} else if p.SeatIdx == 2 {
seatData.Top -= 8
}
- evt1 := PokerEvent{ID: "card" + itoa(firstCard.Idx), Name: firstCard.Name, Idx: firstCard.Idx, Top: seatData.Top, Left: seatData.Left, Reveal: true}
- evt2 := PokerEvent{ID: "card" + itoa(secondCard.Idx), Name: secondCard.Name, Idx: secondCard.Idx, Top: seatData.Top, Left: seatData.Left + 53, Reveal: true}
+ evt1 := PokerEvent{ID: "card" + itoa(firstCard.idx), Name: firstCard.name, Idx: firstCard.idx, Top: seatData.Top, Left: seatData.Left, Reveal: true}
+ evt2 := PokerEvent{ID: "card" + itoa(secondCard.idx), Name: secondCard.name, Idx: secondCard.idx, Top: seatData.Top, Left: seatData.Left + 53, Reveal: true}
PokerPubSub.Pub(roomTopic, evt1)
PokerPubSub.Pub(roomTopic, evt2)
ongoing.addEvent(evt1, evt2)
@@ -613,9 +613,9 @@ func foldPlayer(g *PokerGame, p *PokerPlayer) {
roomTopic := g.roomID.Topic()
p.Folded.Store(true)
var firstCardIdx, secondCardIdx int
- p.Cards.RWith(func(pCards *[]PlayerCard) {
- firstCardIdx = (*pCards)[0].Idx
- secondCardIdx = (*pCards)[1].Idx
+ p.Cards.RWith(func(pCards *[]playerCard) {
+ firstCardIdx = (*pCards)[0].idx
+ secondCardIdx = (*pCards)[1].idx
})
evt1 := PokerEvent{ID: "card" + itoa(firstCardIdx), Name: "", Idx: firstCardIdx, Top: BurnStackY, Left: BurnStackX, Angle: "0deg", Reveal: false}
evt2 := PokerEvent{ID: "card" + itoa(secondCardIdx), Name: "", Idx: secondCardIdx, Top: BurnStackY, Left: BurnStackX, Angle: "0deg", Reveal: false}
@@ -1051,8 +1051,8 @@ func dealPlayersCards(g *PokerGame, seats []Seat, idx *int) {
PokerPubSub.Pub(roomTopic, evt)
PokerPubSub.Pub(roomUserTopic, evt1)
- p.Cards.With(func(pCards *[]PlayerCard) {
- *pCards = append(*pCards, PlayerCard{Idx: *idx, Name: card})
+ p.Cards.With(func(pCards *[]playerCard) {
+ *pCards = append(*pCards, playerCard{idx: *idx, name: card})
})
ongoing.addEvent(evt, evt1)