dkforest

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

commit 330251232a7d564e56f121409317efef1f7f5eb8
parent eb9054a3bb5d4913dbc6602de9a0f15f86d18224
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Wed, 27 Dec 2023 16:11:55 -0500

disgusting

Diffstat:
Mpkg/web/handlers/poker/events.go | 9+++++++--
Mpkg/web/handlers/poker/poker.go | 42++++++++++++++++++++++++++----------------
2 files changed, 33 insertions(+), 18 deletions(-)

diff --git a/pkg/web/handlers/poker/events.go b/pkg/web/handlers/poker/events.go @@ -6,8 +6,13 @@ import ( ) type PokerEvent struct { - ID string - Idx int + ID string + // ID1 is the ID of the next card in the stack. + // We need to pre-set it's z-index because z-index and transform are not working properly together. + // And the z-index is actually set once the transform is completed. + // So this hack makes it look like the next card from the stack move over the other cards... + ID1 string + ZIdx int Name string Top int Left int diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -337,6 +337,7 @@ func pubCashBonus(g *Game, seatIdx int, amount database.PokerChip, isGain bool) type playerCard struct { idx int + zIdx int name string } @@ -628,7 +629,7 @@ func (g *Game) unSitPlayer(gPlayers *seatedPlayers, seatedPlayer *seatedPlayer) player.folded.Store(true) player.cards.RWith(func(playerCards []playerCard) { for _, card := range playerCards { - evt := PokerEvent{ID: "card" + itoa(card.idx), Name: "", Idx: card.idx, Top: BurnStackY, Left: BurnStackX, Angle: "0deg", Reveal: false} + evt := PokerEvent{ID: "card" + itoa(card.idx), Name: "", ZIdx: card.zIdx, Top: BurnStackY, Left: BurnStackX, Angle: "0deg", Reveal: false} PubSub.Pub(g.roomID.Topic(), evt) ongoing.events.Append(evt) } @@ -687,8 +688,8 @@ func showCards(g *Game, seats []Seat) { } else if p.seatIdx == 2 { seatData.Top -= 8 } - evt1 := PokerEvent{ID: "card" + itoa(firstCard.idx), Name: firstCard.name, Idx: firstCard.idx, Top: seatData.Top, Left: seatData.Left, Reveal: true} - evt2 := PokerEvent{ID: "card" + itoa(secondCard.idx), Name: secondCard.name, Idx: secondCard.idx, Top: seatData.Top, Left: seatData.Left + 53, Reveal: true} + evt1 := PokerEvent{ID: "card" + itoa(firstCard.idx), Name: firstCard.name, ZIdx: firstCard.zIdx, Top: seatData.Top, Left: seatData.Left, Reveal: true} + evt2 := PokerEvent{ID: "card" + itoa(secondCard.idx), Name: secondCard.name, ZIdx: secondCard.zIdx, Top: seatData.Top, Left: seatData.Left + 53, Reveal: true} PubSub.Pub(roomTopic, evt1) PubSub.Pub(roomTopic, evt2) ongoing.events.Append(evt1, evt2) @@ -755,13 +756,13 @@ type autoAction struct { func foldPlayer(g *Game, p *PokerPlayer) { roomTopic := g.roomID.Topic() p.folded.Store(true) - var firstCardIdx, secondCardIdx int + var firstCard, secondCard playerCard p.cards.RWith(func(pCards []playerCard) { - firstCardIdx = pCards[0].idx - secondCardIdx = pCards[1].idx + firstCard = pCards[0] + secondCard = pCards[1] }) - evt1 := PokerEvent{ID: "card" + itoa(firstCardIdx), Name: "", Idx: firstCardIdx, Top: BurnStackY, Left: BurnStackX, Angle: "0deg", Reveal: false} - evt2 := PokerEvent{ID: "card" + itoa(secondCardIdx), Name: "", Idx: secondCardIdx, Top: BurnStackY, Left: BurnStackX, Angle: "0deg", Reveal: false} + evt1 := PokerEvent{ID: "card" + itoa(firstCard.idx), Name: "", ZIdx: firstCard.zIdx, Top: BurnStackY, Left: BurnStackX, Angle: "0deg", Reveal: false} + evt2 := PokerEvent{ID: "card" + itoa(secondCard.idx), Name: "", ZIdx: secondCard.zIdx, Top: BurnStackY, Left: BurnStackX, Angle: "0deg", Reveal: false} PubSub.Pub(roomTopic, evt1) PubSub.Pub(roomTopic, evt2) g.ongoing.events.Append(evt1, evt2) @@ -1161,8 +1162,9 @@ func burnCard(g *Game, idx, burnIdx *int) { *idx++ evt := PokerEvent{ ID: "card" + itoa(*idx), + ID1: "card" + itoa(*idx+1), Name: "", - Idx: *idx, + ZIdx: *idx + 53, Top: BurnStackY + (*burnIdx * 2), Left: BurnStackX + (*burnIdx * 4), } @@ -1177,8 +1179,9 @@ func dealCard(g *Game, idx *int, dealCardIdx int) { *idx++ evt := PokerEvent{ ID: "card" + itoa(*idx), + ID1: "card" + itoa(*idx+1), Name: card, - Idx: *idx, + ZIdx: *idx + 53, Top: DealY, Left: DealX + (dealCardIdx * DealSpacing), Reveal: true, @@ -1226,13 +1229,13 @@ func dealPlayersCards(g *Game, seats []Seat, idx *int) { seatData1.Left += 53 } - evt := PokerEvent{ID: "card" + itoa(*idx), Name: "", Idx: *idx, Top: top, Left: left, Angle: seatData.Angle} - evt1 := PokerEvent{ID: "card" + itoa(*idx), Name: card, Idx: *idx, Top: seatData1.Top, Left: seatData1.Left, Reveal: true, UserID: pUserID} + evt := PokerEvent{ID: "card" + itoa(*idx), ID1: "card" + itoa(*idx+1), Name: "", ZIdx: *idx + 104, Top: top, Left: left, Angle: seatData.Angle} + evt1 := PokerEvent{ID: "card" + itoa(*idx), ID1: "card" + itoa(*idx+1), Name: card, ZIdx: *idx + 104, Top: seatData1.Top, Left: seatData1.Left, Reveal: true, UserID: pUserID} PubSub.Pub(roomTopic, evt) PubSub.Pub(roomUserTopic, evt1) - p.cards.Append(playerCard{idx: *idx, name: card}) + p.cards.Append(playerCard{idx: *idx, zIdx: *idx + 104, name: card}) ongoing.events.Append(evt, evt1) } @@ -1984,7 +1987,7 @@ func drawResetCardsEvent() (html string) { html += `<style>` for i := 1; i <= 52; i++ { idxStr := itoa(i) - html += `#card` + idxStr + ` { transition: ` + animationTime.String() + ` ease-in-out; transform: translateX(` + itoa(DealerStackX) + `px) translateY(` + itoa(DealerStackY) + `px) rotateY(` + BackfacingDeg + `); } + html += `#card` + idxStr + ` { z-index: ` + itoa(53-i) + `; transition: ` + animationTime.String() + ` ease-in-out; transform: translateX(` + itoa(DealerStackX) + `px) translateY(` + itoa(DealerStackY) + `px) rotateY(` + BackfacingDeg + `); } #card` + idxStr + ` .card .inner:before { content: ""; }` } html += ` @@ -2065,9 +2068,16 @@ func getPokerEventHtml(payload PokerEvent, animationTime string) string { transform += utils.Ternary(payload.Angle != "", ` rotateZ(`+payload.Angle+`)`, ``) transform += utils.Ternary(!payload.Reveal, ` rotateY(`+BackfacingDeg+`)`, ``) transform += ";" - pokerEvtHtml := `<style> + pokerEvtHtml := `<style>` + if payload.ID1 != "" { + pokerEvtHtml += ` + #` + payload.ID1 + ` { + z-index: ` + itoa(payload.ZIdx+1) + `; + }` + } + pokerEvtHtml += ` #` + payload.ID + ` { - z-index: ` + itoa(payload.Idx) + `; + z-index: ` + itoa(payload.ZIdx) + `; transition: ` + animationTime + ` ease-in-out; ` + transform + ` }