dkforest

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

commit bd4ef26b9fbf044c1cb593fe52f8a86b3485e9cd
parent b8494cd9661f4942e369672d95574d4fb956f219
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Tue,  5 Dec 2023 02:30:39 -0500

main pot stuff

Diffstat:
Mpkg/web/handlers/poker.go | 32++++++++++++++++++++++++++++----
1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/pkg/web/handlers/poker.go b/pkg/web/handlers/poker.go @@ -64,6 +64,7 @@ type Ongoing struct { Players []*PokerPlayer Events []PokerEvent WaitTurnEvent PokerWaitTurnEvent + MainPot int } type PokerPlayer struct { @@ -158,13 +159,22 @@ func (g *PokerGame) Deal(roomID string) { if evt.Fold { player.Folded = true PokerPubSub.Pub(myTopic, PlayerFoldEvent{Card1Idx: player.Cards[0].Idx, Card2Idx: player.Cards[1].Idx}) + } else if evt.Check { + } else if evt.Call { + } else if evt.Bet > 0 { + g.Ongoing.Players[i].Bet += evt.Bet } - g.Ongoing.Players[i].Bet += evt.Bet break } } } - evt := PokerWaitTurnEvent{Idx: -1} + + for i := range g.Ongoing.Players { + g.Ongoing.MainPot += g.Ongoing.Players[i].Bet + g.Ongoing.Players[i].Bet = 0 + } + + evt := PokerWaitTurnEvent{Idx: -1, MainPot: g.Ongoing.MainPot} PokerPubSub.Pub(myTopic, evt) g.Ongoing.WaitTurnEvent = evt } @@ -350,7 +360,8 @@ type PlayerFoldEvent struct { } type PokerWaitTurnEvent struct { - Idx int + Idx int + MainPot int } type YourCardEvent struct { @@ -540,6 +551,16 @@ func buildTakeSeatHtml(authUser *database.User, g *PokerGame, roomID string) str return takeSeatBtns } +func buildMainPotHtml(g *PokerGame) string { + html := `<div id="mainPot"></div>` + mainPot := 0 + if g.Ongoing != nil { + mainPot = g.Ongoing.MainPot + } + html += `<style>#mainPot:before { content: "Pot: ` + strconv.Itoa(mainPot) + `"; }</style>` + return html +} + func buildSeatsHtml(g *PokerGame) string { seats := ` <div>` @@ -648,6 +669,7 @@ body { #seat1 { position: absolute; top: 80px; left: 700px; } #seat2 { position: absolute; top: 200px; left: 670px; } #seat3 { position: absolute; top: 300px; left: 610px; } +#seat1Pot { position: absolute; top: 80px; left: 500px; } .takeSeat1 { position: absolute; top: 80px; left: 700px; } .takeSeat2 { position: absolute; top: 200px; left: 670px; } .takeSeat3 { position: absolute; top: 300px; left: 610px; } @@ -667,6 +689,7 @@ body { drawCountDownStyle := func(evt PokerWaitTurnEvent) { if evt.Idx == -1 { send(`<style>#countdown { display: none; }</style>`) + send(`<style>#mainPot:before { content: "Pot: ` + strconv.Itoa(evt.MainPot) + `"; }</style>`) } else if evt.Idx == 0 { send(`<style>#countdown { top: 50px; left: 600px; display: block; }</style>`) } else if evt.Idx == 1 { @@ -737,7 +760,8 @@ body { actions += `<iframe src="/poker/` + roomID + `/unsit" id="unSitBtn"></iframe>` send(actions) deckHash := deckMd5 - send(`<div id="mainPot">POT: 0</div>`) + send(`<div id="seat1Pot">BET: 0</div>`) + send(buildMainPotHtml(g)) send(`<div id="countdown">CD</div>`) if g.Ongoing != nil { drawCountDownStyle(g.Ongoing.WaitTurnEvent)