dkforest

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

commit f0c37db4076a15a55d4326ebcadcf2ba0f322983
parent b3bb8453fccbc773cc078e0e850ee2b6ac8701f5
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Tue,  5 Dec 2023 20:09:43 -0500

cleanup

Diffstat:
Mpkg/web/handlers/poker.go | 120++++++++++++++++++++++++++++++++++---------------------------------------------
1 file changed, 51 insertions(+), 69 deletions(-)

diff --git a/pkg/web/handlers/poker.go b/pkg/web/handlers/poker.go @@ -796,6 +796,50 @@ func buildSeatsHtml(g *PokerGame) string { return seats } +func drawGameIsDoneHtml(g *PokerGame, evt GameIsDoneEvent) (html string) { + html += `<style>#deckStr:before { content: "` + evt.DeckStr + `"; }</style>` + for i, p := range g.Players { + if p.Username != "" { + html += `<style>#seat` + itoa(i+1) + `_cash:before { content: "` + itoa(p.Cash) + `"; }</style>` + } + } + return +} + +func drawPlayerFoldEvent(evt PlayerFoldEvent) (html string) { + transition := `transition: 1s ease-in-out; transform: translateX(` + itoa(BurnStackX) + `px) translateY(` + itoa(BurnStackY) + `px) rotateY(` + BackfacingDeg + `);` + html = `<style>#card` + itoa(evt.Card1Idx) + ` { ` + transition + ` } + #card` + itoa(evt.Card2Idx) + ` { ` + transition + ` }</style>` + return +} + +func drawShowCardsEvent(evt ShowCardsEvent) (html string) { + // TODO: Proper showing cards + html += `<style>` + html += `#card` + itoa(evt.Cards[0].Idx) + ` { transition: 1s ease-in-out; transform: rotateY(0); }` + html += `#card` + itoa(evt.Cards[1].Idx) + ` { transition: 1s ease-in-out; transform: rotateY(0); }` + html += `#card` + itoa(evt.Cards[0].Idx) + ` .card .inner:before { content: "` + evt.Cards[0].Name + `"; color: ` + colorForCard(evt.Cards[0].Name) + `; }` + html += `#card` + itoa(evt.Cards[1].Idx) + ` .card .inner:before { content: "` + evt.Cards[1].Name + `"; color: ` + colorForCard(evt.Cards[1].Name) + `; }` + html += `</style>` + return +} + +func drawResetCardsEvent() (html string) { + html += `<style>` + for i := 1; i <= 52; i++ { + html += `#card` + itoa(i) + ` { transition: 1s ease-in-out; transform: translateX(` + itoa(DealerStackX) + `px) translateY(` + itoa(DealerStackY) + `px) rotateY(` + BackfacingDeg + `); } + #card` + itoa(i) + ` .card .inner:before { content: ""; }` + } + html += ` + #yourCard1:before { content: ""; } + #yourCard2:before { content: ""; } + #deckHash:before { content: ""; } + #deckStr:before { content: ""; } + #mainPot:before { content: "Pot: 0"; } + </style>` + return +} + func drawSeatsHtml(authUser *database.User, g *PokerGame) string { html := "<style>" seated, _ := g.IsSeated(authUser.Username.String()) @@ -1065,93 +1109,31 @@ Loop: if _, ok := payload.(PokerSeatLeftEvent); ok { send(drawSeatsHtml(authUser, g)) - c.Response().Flush() - continue - } else if evt, ok := payload.(GameStartedEvent); ok { send(`<style>#deckHash:before { content: "` + evt.DeckHash + `"; }</style>`) - c.Response().Flush() - continue - } else if evt, ok := payload.(GameIsDoneEvent); ok { - html := `<style>#deckStr:before { content: "` + evt.DeckStr + `"; }</style>` - for i, p := range g.Players { - if p.Username != "" { - html += `<style>#seat` + itoa(i+1) + `_cash:before { content: "` + itoa(p.Cash) + `"; }</style>` - } - } - send(html) - c.Response().Flush() - continue - + send(drawGameIsDoneHtml(g, evt)) } else if evt, ok := payload.(YourCardEvent); ok { send(`<style>#yourCard` + itoa(evt.Idx) + `:before { content: "` + evt.Name + `"; color: ` + colorForCard(evt.Name) + `; }</style>`) - c.Response().Flush() - continue - } else if evt, ok := payload.(PlayerBetEvent); ok { - html := `<style>#seat` + itoa(evt.PlayerIdx+1) + `_cash:before { content: "` + itoa(evt.Cash) + `"; }</style>` - send(html) - c.Response().Flush() - continue - + send(`<style>#seat` + itoa(evt.PlayerIdx+1) + `_cash:before { content: "` + itoa(evt.Cash) + `"; }</style>`) } else if evt, ok := payload.(ErrorMsgEvent); ok { send(`<style>#errorMsg:before { content: "` + evt.Message + `"; }</style>`) - c.Response().Flush() - continue - } else if evt, ok := payload.(PlayerFoldEvent); ok { - transition := `transition: 1s ease-in-out; transform: translateX(` + itoa(BurnStackX) + `px) translateY(` + itoa(BurnStackY) + `px) rotateY(` + BackfacingDeg + `);` - html := `<style>#card` + itoa(evt.Card1Idx) + ` { ` + transition + ` } - #card` + itoa(evt.Card2Idx) + ` { ` + transition + ` }</style>` - send(html) - c.Response().Flush() - continue - + send(drawPlayerFoldEvent(evt)) } else if evt, ok := payload.(ShowCardsEvent); ok { - // TODO: Proper showing cards - html := `<style>` - html += `#card` + itoa(evt.Cards[0].Idx) + ` { transition: 1s ease-in-out; transform: rotateY(0); }` - html += `#card` + itoa(evt.Cards[1].Idx) + ` { transition: 1s ease-in-out; transform: rotateY(0); }` - html += `#card` + itoa(evt.Cards[0].Idx) + ` .card .inner:before { content: "` + evt.Cards[0].Name + `"; color: ` + colorForCard(evt.Cards[0].Name) + `; }` - html += `#card` + itoa(evt.Cards[1].Idx) + ` .card .inner:before { content: "` + evt.Cards[1].Name + `"; color: ` + colorForCard(evt.Cards[1].Name) + `; }` - html += `</style>` - send(html) - c.Response().Flush() - continue - + send(drawShowCardsEvent(evt)) } else if _, ok := payload.(ResetCardsEvent); ok { - html := `<style>` - for i := 1; i <= 52; i++ { - html += `#card` + itoa(i) + ` { transition: 1s ease-in-out; transform: translateX(` + itoa(DealerStackX) + `px) translateY(` + itoa(DealerStackY) + `px) rotateY(` + BackfacingDeg + `); } - #card` + itoa(i) + ` .card .inner:before { content: ""; }` - } - html += ` - #yourCard1:before { content: ""; } - #yourCard2:before { content: ""; } - #deckHash:before { content: ""; } - #deckStr:before { content: ""; } - #mainPot:before { content: "Pot: 0"; } - </style>` - send(html) - c.Response().Flush() - continue - + send(drawResetCardsEvent()) } else if _, ok := payload.(PokerSeatTakenEvent); ok { send(drawSeatsHtml(authUser, g)) - c.Response().Flush() - continue - } else if evt, ok := payload.(PokerWaitTurnEvent); ok { send(drawCountDownStyle(evt)) - c.Response().Flush() - continue - } else if payload, ok := payload.(PokerEvent); ok { send(getPokerEventHtml(payload, "1s")) - c.Response().Flush() - continue } + c.Response().Flush() + continue } return nil }