commit 9235acb55ecc27a7558b7f05ab25a2fc80e6c5e3
parent 503f4b1031c90c75d9dfa8963f8203672c562627
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Mon, 4 Dec 2023 22:50:15 -0500
fix
Diffstat:
1 file changed, 27 insertions(+), 15 deletions(-)
diff --git a/pkg/web/handlers/poker.go b/pkg/web/handlers/poker.go
@@ -53,9 +53,10 @@ type PlayerEvent struct {
var PokerInstance = NewPoker()
type Ongoing struct {
- Deck []string
- Players []PokerPlayer
- Events []PokerEvent
+ Deck []string
+ Players []PokerPlayer
+ Events []PokerEvent
+ WaitTurnEvent PokerWaitTurnEvent
}
type PokerPlayer struct {
@@ -95,7 +96,7 @@ func (g *PokerGame) Deal(roomID string) {
players[idx] = PokerPlayer{Username: g.Players[idx]}
}
- g.Ongoing = &Ongoing{Deck: deck, Players: players}
+ g.Ongoing = &Ongoing{Deck: deck, Players: players, WaitTurnEvent: PokerWaitTurnEvent{Idx: -1}}
go func() {
myTopic := "room_" + roomID
@@ -103,7 +104,9 @@ func (g *PokerGame) Deal(roomID string) {
waitPlayersActionFn := func() {
for i, p := range g.Ongoing.Players {
if p.Username != "" {
- PokerPubSub.Pub(myTopic, PokerWaitTurnEvent{Idx: i})
+ evt := PokerWaitTurnEvent{Idx: i}
+ PokerPubSub.Pub(myTopic, evt)
+ g.Ongoing.WaitTurnEvent = evt
fmt.Println("WAIT FOR ACTION", p)
waitCh := time.After(10 * time.Second)
LOOP:
@@ -124,7 +127,9 @@ func (g *PokerGame) Deal(roomID string) {
}
}
}
- PokerPubSub.Pub(myTopic, PokerWaitTurnEvent{Idx: -1})
+ evt := PokerWaitTurnEvent{Idx: -1}
+ PokerPubSub.Pub(myTopic, evt)
+ g.Ongoing.WaitTurnEvent = evt
}
type Seat struct {
@@ -599,6 +604,18 @@ body {
#countdown { position: absolute; display: none; z-index: 100; }
</style>`)
+ drawCountDownStyle := func(evt PokerWaitTurnEvent) {
+ if evt.Idx == -1 {
+ send(`<style>#countdown { display: none; }</style>`)
+ } else if evt.Idx == 0 {
+ send(`<style>#countdown { top: 50px; left: 600px; display: block; }</style>`)
+ } else if evt.Idx == 1 {
+ send(`<style>#countdown { top: 150px; left: 574px; display: block; }</style>`)
+ } else if evt.Idx == 2 {
+ send(`<style>#countdown { top: 250px; left: 530px; display: block; }</style>`)
+ }
+ }
+
drawSeats := func() {
seated, _ := g.IsSeated(authUser.Username.String())
for i, p := range g.Players {
@@ -661,6 +678,9 @@ body {
send(actions)
deckHash := deckSha256
send(`<div id="countdown">CD</div>`)
+ if g.Ongoing != nil {
+ drawCountDownStyle(g.Ongoing.WaitTurnEvent)
+ }
send(`<div>` + deckStr + `</div>`)
send(`<div>` + deckHash + `</div>`)
if g.Ongoing != nil {
@@ -706,15 +726,7 @@ Loop:
continue
} else if evt, ok := payload.(PokerWaitTurnEvent); ok {
- if evt.Idx == -1 {
- send(`<style>#countdown { display: none; }</style>`)
- } else if evt.Idx == 0 {
- send(`<style>#countdown { top: 50px; left: 600px; display: block; }</style>`)
- } else if evt.Idx == 1 {
- send(`<style>#countdown { top: 150px; left: 574px; display: block; }</style>`)
- } else if evt.Idx == 2 {
- send(`<style>#countdown { top: 250px; left: 530px; display: block; }</style>`)
- }
+ drawCountDownStyle(evt)
c.Response().Flush()
continue