dkforest

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

commit c2ad7c1ef938c431fba235bd03d28f10955763fc
parent 9235acb55ecc27a7558b7f05ab25a2fc80e6c5e3
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon,  4 Dec 2023 23:09:16 -0500

reset cards (deal new game)

Diffstat:
Mpkg/web/handlers/poker.go | 29++++++++++++++++++++++++-----
1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/pkg/web/handlers/poker.go b/pkg/web/handlers/poker.go @@ -75,9 +75,17 @@ type PokerGame struct { } func (g *PokerGame) Deal(roomID string) { + myTopic := "room_" + roomID + if g.Ongoing != nil { - fmt.Println("game already ongoing") - return + if !g.IsGameOver { + fmt.Println("game already ongoing") + return + } else { + g.IsGameOver = false + PokerPubSub.Pub(myTopic, ResetCardsEvent{}) + time.Sleep(time.Second) + } } if g.CountSeated() < 2 { fmt.Println("need at least 2 players") @@ -99,8 +107,6 @@ func (g *PokerGame) Deal(roomID string) { g.Ongoing = &Ongoing{Deck: deck, Players: players, WaitTurnEvent: PokerWaitTurnEvent{Idx: -1}} go func() { - myTopic := "room_" + roomID - waitPlayersActionFn := func() { for i, p := range g.Ongoing.Players { if p.Username != "" { @@ -290,6 +296,9 @@ type PokerEvent struct { Angle string } +type ResetCardsEvent struct { +} + type PokerWaitTurnEvent struct { Idx int } @@ -711,7 +720,6 @@ Loop: continue } else if evt, ok := payload.(YourCardEvent); ok { - fmt.Println("YOUR CARD:", authUser.Username, evt.Idx, evt.Name) if evt.Idx == 1 { send(`<style>#yourCard1:before { content: "` + evt.Name + `"; }</style>`) } else { @@ -720,6 +728,17 @@ Loop: c.Response().Flush() continue + } else if _, ok := payload.(ResetCardsEvent); ok { + html := `<style>` + for i := 1; i <= 52; i++ { + html += `#card` + strconv.Itoa(i) + ` { transition: 1s ease-in-out; transform: translateX(250px) translateY(30px) rotateY(180deg); } + #card` + strconv.Itoa(i) + ` .card .inner:before { content: ""; }` + } + html += "</style>" + send(html) + c.Response().Flush() + continue + } else if _, ok := payload.(PokerSeatTakenEvent); ok { drawSeats() c.Response().Flush()