dkforest

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

commit bf76ff1eea95319e5c8614e06f167373d710e4f5
parent 2a22d5afc7b5606a1db91fca6490bdfb918e0a0c
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon,  4 Dec 2023 02:59:19 -0500

deal cards

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

diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -756,12 +756,13 @@ func BHCHandler(c echo.Context) error { } type PokerEvent struct { - ID string - Idx int - Name string - Top int - Left int - Burn bool + ID string + Idx int + Name string + Top int + Left int + Burn bool + Angle string } var PokerPubSub = pubsub.NewPubSub[PokerEvent]() @@ -793,12 +794,138 @@ func PokerHandler(c echo.Context) error { myTopic := "room_" + authUser.ID.String() go func() { + type Seat struct { + Top int + Left int + Angle string + } + seats := []Seat{ + {Top: 50, Left: 600, Angle: "-90deg"}, + {Top: 150, Left: 570, Angle: "-80deg"}, + {Top: 250, Left: 530, Angle: "-70deg"}, + //{Top: 150, Left: 550}, + //{Top: 150, Left: 550}, + //{Top: 150, Left: 550}, + //{Top: 150, Left: 550}, + //{Top: 150, Left: 550}, + //{Top: 150, Left: 550}, + //{Top: 150, Left: 550}, + } + var card string idx := 0 + // Seat 1 + select { + case <-time.After(time.Second): + case <-quit: + return + } + idx++ + card, deck = deck[0], deck[1:] + PokerPubSub.Pub(myTopic, PokerEvent{ + ID: "card" + strconv.Itoa(idx), + Name: "", + Idx: idx, + Top: seats[0].Top, + Left: seats[0].Left, + Angle: seats[0].Angle, + Burn: true, + }) + + // Seat 2 + select { + case <-time.After(time.Second): + case <-quit: + return + } + idx++ + card, deck = deck[0], deck[1:] + PokerPubSub.Pub(myTopic, PokerEvent{ + ID: "card" + strconv.Itoa(idx), + Name: "", + Idx: idx, + Top: seats[1].Top, + Left: seats[1].Left, + Angle: seats[1].Angle, + Burn: true, + }) + + // Seat 3 + select { + case <-time.After(time.Second): + case <-quit: + return + } + idx++ + card, deck = deck[0], deck[1:] + PokerPubSub.Pub(myTopic, PokerEvent{ + ID: "card" + strconv.Itoa(idx), + Name: "", + Idx: idx, + Top: seats[2].Top, + Left: seats[2].Left, + Angle: seats[2].Angle, + Burn: true, + }) + + // Seat 1 + select { + case <-time.After(time.Second): + case <-quit: + return + } + idx++ + card, deck = deck[0], deck[1:] + PokerPubSub.Pub(myTopic, PokerEvent{ + ID: "card" + strconv.Itoa(idx), + Name: "", + Idx: idx, + Top: seats[0].Top + 5, + Left: seats[0].Left, + Angle: seats[0].Angle, + Burn: true, + }) + + // Seat 2 + select { + case <-time.After(time.Second): + case <-quit: + return + } + idx++ + card, deck = deck[0], deck[1:] + PokerPubSub.Pub(myTopic, PokerEvent{ + ID: "card" + strconv.Itoa(idx), + Name: "", + Idx: idx, + Top: seats[1].Top + 5, + Left: seats[1].Left, + Angle: seats[1].Angle, + Burn: true, + }) + + // Seat 3 + select { + case <-time.After(time.Second): + case <-quit: + return + } + idx++ + card, deck = deck[0], deck[1:] + PokerPubSub.Pub(myTopic, PokerEvent{ + ID: "card" + strconv.Itoa(idx), + Name: "", + Idx: idx, + Top: seats[2].Top + 5, + Left: seats[2].Left, + Angle: seats[2].Angle, + Burn: true, + }) + // Burn select { - case <-time.After(2 * time.Second): + case <-time.After(time.Second): case <-quit: return } @@ -816,7 +943,7 @@ func PokerHandler(c echo.Context) error { // Flop (3 first cards) for i := 1; i <= 3; i++ { select { - case <-time.After(2 * time.Second): + case <-time.After(time.Second): case <-quit: return } @@ -832,7 +959,7 @@ func PokerHandler(c echo.Context) error { // Burn select { - case <-time.After(2 * time.Second): + case <-time.After(time.Second): case <-quit: return } @@ -842,14 +969,14 @@ func PokerHandler(c echo.Context) error { ID: "card" + strconv.Itoa(idx), Name: "", Idx: idx, - Top: 30, - Left: 400, + Top: 32, + Left: 404, Burn: true, }) // Turn (4th card) select { - case <-time.After(2 * time.Second): + case <-time.After(time.Second): case <-quit: return } @@ -864,7 +991,7 @@ func PokerHandler(c echo.Context) error { // Burn select { - case <-time.After(2 * time.Second): + case <-time.After(time.Second): case <-quit: return } @@ -874,14 +1001,14 @@ func PokerHandler(c echo.Context) error { ID: "card" + strconv.Itoa(idx), Name: "", Idx: idx, - Top: 30, - Left: 400, + Top: 34, + Left: 408, Burn: true, }) // River (5th card) select { - case <-time.After(2 * time.Second): + case <-time.After(time.Second): case <-quit: return } @@ -1002,6 +1129,9 @@ Loop: //animation-timing-function: ease-in-out; //animation-fill-mode: forwards; transform := `transform: translate(` + strconv.Itoa(payload.Left) + `px, ` + strconv.Itoa(payload.Top) + `px)` + if payload.Angle != "" { + transform += ` rotateZ(` + payload.Angle + `)` + } if payload.Burn { transform += ` rotateY(180deg)` }