dkforest

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

commit f195370487ddc07bc82f8c95661760a6c201ee48
parent 5e6523991a176723f61b7508c4aef2fd3d11d0a0
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon,  4 Dec 2023 18:19:18 -0500

cool

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

diff --git a/pkg/web/handlers/poker.go b/pkg/web/handlers/poker.go @@ -46,6 +46,7 @@ var PokerInstance = NewPoker() type Ongoing struct { Deck []string Players []string + Events []PokerEvent } type PokerGame struct { @@ -125,7 +126,7 @@ func (g *PokerGame) Deal(roomID string) { if d.Reveal { name = card } - PokerPubSub.Pub(myTopic, PokerEvent{ + evt := PokerEvent{ ID: "card" + strconv.Itoa(idx), Name: name, Idx: idx, @@ -133,83 +134,97 @@ func (g *PokerGame) Deal(roomID string) { Left: d.Left, Angle: d.Angle, Burn: !d.Reveal, - }) + } + PokerPubSub.Pub(myTopic, evt) + g.Ongoing.Events = append(g.Ongoing.Events, evt) } // Burn time.Sleep(time.Second) idx++ card, g.Ongoing.Deck = g.Ongoing.Deck[0], g.Ongoing.Deck[1:] - PokerPubSub.Pub(myTopic, PokerEvent{ + evt := PokerEvent{ ID: "card" + strconv.Itoa(idx), Name: "", Idx: idx, Top: 30, Left: 400, Burn: true, - }) + } + PokerPubSub.Pub(myTopic, evt) + g.Ongoing.Events = append(g.Ongoing.Events, evt) // Flop (3 first cards) for i := 1; i <= 3; i++ { time.Sleep(time.Second) idx++ card, g.Ongoing.Deck = g.Ongoing.Deck[0], g.Ongoing.Deck[1:] - PokerPubSub.Pub(myTopic, PokerEvent{ + evt := PokerEvent{ ID: "card" + strconv.Itoa(idx), Name: card, Idx: idx, Top: 150, Left: 100 + (i * 55), - }) + } + PokerPubSub.Pub(myTopic, evt) + g.Ongoing.Events = append(g.Ongoing.Events, evt) } // Burn time.Sleep(time.Second) idx++ card, g.Ongoing.Deck = g.Ongoing.Deck[0], g.Ongoing.Deck[1:] - PokerPubSub.Pub(myTopic, PokerEvent{ + evt = PokerEvent{ ID: "card" + strconv.Itoa(idx), Name: "", Idx: idx, Top: 32, Left: 404, Burn: true, - }) + } + PokerPubSub.Pub(myTopic, evt) + g.Ongoing.Events = append(g.Ongoing.Events, evt) // Turn (4th card) time.Sleep(time.Second) idx++ card, g.Ongoing.Deck = g.Ongoing.Deck[0], g.Ongoing.Deck[1:] - PokerPubSub.Pub(myTopic, PokerEvent{ + evt = PokerEvent{ ID: "card" + strconv.Itoa(idx), Name: card, Idx: idx, Top: 150, Left: 100 + (4 * 55), - }) + } + PokerPubSub.Pub(myTopic, evt) + g.Ongoing.Events = append(g.Ongoing.Events, evt) // Burn time.Sleep(time.Second) idx++ card, g.Ongoing.Deck = g.Ongoing.Deck[0], g.Ongoing.Deck[1:] - PokerPubSub.Pub(myTopic, PokerEvent{ + evt = PokerEvent{ ID: "card" + strconv.Itoa(idx), Name: "", Idx: idx, Top: 34, Left: 408, Burn: true, - }) + } + PokerPubSub.Pub(myTopic, evt) + g.Ongoing.Events = append(g.Ongoing.Events, evt) // River (5th card) time.Sleep(time.Second) idx++ card, g.Ongoing.Deck = g.Ongoing.Deck[0], g.Ongoing.Deck[1:] - PokerPubSub.Pub(myTopic, PokerEvent{ + evt = PokerEvent{ ID: "card" + strconv.Itoa(idx), Name: card, Idx: idx, Top: 150, Left: 100 + (5 * 55), - }) + } + PokerPubSub.Pub(myTopic, evt) + g.Ongoing.Events = append(g.Ongoing.Events, evt) }() } @@ -491,6 +506,32 @@ body { deckHash := deckSha256 send(`<div>` + deckStr + `</div>`) send(`<div>` + deckHash + `</div>`) + if g.Ongoing != nil { + for _, payload := range g.Ongoing.Events { + color := "black" + if strings.Contains(payload.Name, "♥") || + strings.Contains(payload.Name, "♦") { + color = "red" + } + 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)` + } + transform += ";" + pokerEvtHtml := `<style> +#` + payload.ID + ` { + z-index: ` + strconv.Itoa(payload.Idx) + `; + transition: 0s ease-in-out; + ` + transform + ` +} +#` + payload.ID + ` .card .inner:before { content: "` + payload.Name + `"; color: ` + color + `; } +</style>` + send(pokerEvtHtml) + } + } c.Response().Flush() Loop: for { @@ -532,14 +573,15 @@ Loop: transform += ` rotateY(180deg)` } transform += ";" - send(`<style> + pokerEvtHtml := `<style> #` + payload.ID + ` { z-index: ` + strconv.Itoa(payload.Idx) + `; transition: 1s ease-in-out; ` + transform + ` } #` + payload.ID + ` .card .inner:before { content: "` + payload.Name + `"; color: ` + color + `; } -</style>`) +</style>` + send(pokerEvtHtml) c.Response().Flush() continue }