dkforest

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

commit f00200b5a50117e07fb63816fe219caa1558e89a
parent a15c40758ab2fd0d2f01cc3164f48b5a6e026630
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon,  4 Dec 2023 02:06:16 -0500

poker

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

diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -761,6 +761,7 @@ type PokerEvent struct { Name string Top int Left int + Burn bool } var PokerPubSub = pubsub.NewPubSub[PokerEvent]() @@ -792,23 +793,83 @@ func PokerHandler(c echo.Context) error { myTopic := "room_" + authUser.ID.String() go func() { + var card string idx := 0 - for i := 1; i <= 5; i++ { + for i := 1; i <= 3; i++ { select { case <-time.After(2 * time.Second): case <-quit: return } idx++ - var card string card, deck = deck[0], deck[1:] PokerPubSub.Pub(myTopic, PokerEvent{ ID: "card" + strconv.Itoa(i), Name: card, Idx: idx, - Top: 100, + Top: 150, Left: 100 + (i * 55), }) } + + // Burn + select { + case <-time.After(2 * time.Second): + case <-quit: + return + } + idx++ + card, deck = deck[0], deck[1:] + PokerPubSub.Pub(myTopic, PokerEvent{ + ID: "card" + strconv.Itoa(4), Name: card, + Idx: idx, + Top: 30, + Left: 400, + Burn: true, + }) + + select { + case <-time.After(2 * time.Second): + case <-quit: + return + } + idx++ + card, deck = deck[0], deck[1:] + PokerPubSub.Pub(myTopic, PokerEvent{ + ID: "card" + strconv.Itoa(5), Name: card, + Idx: idx, + Top: 150, + Left: 100 + (4 * 55), + }) + + // Burn + select { + case <-time.After(2 * time.Second): + case <-quit: + return + } + idx++ + card, deck = deck[0], deck[1:] + PokerPubSub.Pub(myTopic, PokerEvent{ + ID: "card" + strconv.Itoa(6), Name: card, + Idx: idx, + Top: 30, + Left: 400, + Burn: true, + }) + + select { + case <-time.After(2 * time.Second): + case <-quit: + return + } + idx++ + card, deck = deck[0], deck[1:] + PokerPubSub.Pub(myTopic, PokerEvent{ + ID: "card" + strconv.Itoa(7), Name: card, + Idx: idx, + Top: 150, + Left: 100 + (5 * 55), + }) }() sub := PokerPubSub.Subscribe([]string{myTopic}) @@ -837,7 +898,7 @@ body { position: absolute; top: 0; left: 0; - transform: rotateY( 180deg ); + transform: rotateY( 180deg ) translateX(-250px) translateY(30px); transform-style: preserve-3d; backface-visibility: hidden; width:50px; @@ -917,11 +978,16 @@ Loop: //animation-direction: alternate; //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.Burn { + transform += ` rotateY(180deg)` + } + transform += ";" send(`<style> #` + payload.ID + ` { z-index: ` + strconv.Itoa(payload.Idx) + `; transition: 1s ease-in-out; - transform: translate(` + strconv.Itoa(payload.Left) + `px, ` + strconv.Itoa(payload.Top) + `px); + ` + transform + ` } #` + payload.ID + ` .card:before { content: "` + payload.Name + `"; color: ` + color + `; } </style>`)