commit 01452f637d40d939ea0a7c582589d48c9196d3ac
parent f8315101f743188e18272ead3ed8dd104f61b4c3
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Tue, 5 Dec 2023 22:40:18 -0500
display winner and winner hand
Diffstat:
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/pkg/web/handlers/poker/events.go b/pkg/web/handlers/poker/events.go
@@ -15,7 +15,9 @@ type GameStartedEvent struct {
}
type GameIsDoneEvent struct {
- DeckStr string
+ Winner string
+ WinnerHand string
+ DeckStr string
}
type ResetCardsEvent struct {
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -459,6 +459,7 @@ END:
// TODO: evaluate hands, and crown winner
var winner *PokerPlayer
+ var winnerHand string
var minScore int32 = math.MaxInt32
for _, p := range g.Ongoing.Players {
if p != nil {
@@ -476,6 +477,7 @@ END:
if e < minScore {
winner = p
minScore = e
+ winnerHand = poker.RankString(e)
}
}
}
@@ -491,7 +493,7 @@ END:
}
g.IsGameDone = true
- PokerPubSub.Pub(roomTopic, GameIsDoneEvent{DeckStr: strings.Join(g.Ongoing.Deck, "")})
+ PokerPubSub.Pub(roomTopic, GameIsDoneEvent{DeckStr: strings.Join(g.Ongoing.Deck, ""), Winner: winner.Username, WinnerHand: winnerHand})
// Wait a minimum of X seconds before allowing a new game
time.Sleep(MinTimeAfterGame * time.Second)
@@ -751,6 +753,12 @@ func buildMainPotHtml(g *PokerGame) string {
return html
}
+func buildWinnerHtml() string {
+ html := `<div id="winner"></div>`
+ html += `<style>#winner:before { content: ""; }</style>`
+ return html
+}
+
func buildCountdownsHtml() (html string) {
for i := 1; i <= NbPlayers; i++ {
html += `<div id="countdown` + itoa(i) + `" class="timer" style="--duration: ` + itoa(MaxUserCountdown) + `;--size: 30;"><div class="mask"></div></div>`
@@ -801,12 +809,15 @@ func drawGameStartedEvent(evt GameStartedEvent) string {
}
func drawGameIsDoneHtml(g *PokerGame, evt GameIsDoneEvent) (html string) {
- html += `<style>#deckStr:before { content: "` + evt.DeckStr + `"; }</style>`
+ html += `<style>`
+ html += `#deckStr:before { content: "` + evt.DeckStr + `"; }`
for i, p := range g.Players {
if p != nil {
- html += `<style>#seat` + itoa(i+1) + `_cash:before { content: "` + itoa(p.Cash) + `"; }</style>`
+ html += `#seat` + itoa(i+1) + `_cash:before { content: "` + itoa(p.Cash) + `"; }`
}
}
+ html += `#winner:before { content: "Winner: ` + evt.Winner + ` (` + evt.WinnerHand + `)"; }`
+ html += "</style>"
return
}
@@ -839,6 +850,7 @@ func drawResetCardsEvent() (html string) {
#yourCard2:before { content: ""; }
#deckHash:before { content: ""; }
#deckStr:before { content: ""; }
+ #winner:before { content: ""; }
#mainPot:before { content: "Pot: 0"; }
</style>`
return
@@ -1037,6 +1049,7 @@ body {
#countdown5 { position: absolute; display: none; z-index: 100; }
#countdown6 { position: absolute; display: none; z-index: 100; }
#mainPot { position: absolute; top: 240px; left: 250px; }
+#winner { position: absolute; top: 265px; left: 250px; }
#yourCard1 { font-size: 22px; display: inline-block; margin-right: 15px; }
#yourCard2 { font-size: 22px; display: inline-block; }
#errorMsg { position: absolute; top: 500px; left: 150px; color: darkred; }
@@ -1125,6 +1138,7 @@ func PokerHandler(c echo.Context) error {
send(`<div id="errorMsg"></div>`)
send(`<div id="seat1Pot"></div>`) // TODO
send(buildMainPotHtml(g))
+ send(buildWinnerHtml())
send(buildCountdownsHtml())
send(`<div id="deckStr"></div>`)