dkforest

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

commit b3bb8453fccbc773cc078e0e850ee2b6ac8701f5
parent 39fcb0bef524a7d15080e6d45dd83367dee1b4fa
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Tue,  5 Dec 2023 20:03:31 -0500

cleanup

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

diff --git a/pkg/web/handlers/poker.go b/pkg/web/handlers/poker.go @@ -318,7 +318,7 @@ func (g *PokerGame) Deal(roomID string) { card = g.Ongoing.Deck[idx] idx++ evt := PokerEvent{ - ID: "card" + strconv.Itoa(idx), + ID: "card" + itoa(idx), Name: "", Idx: idx, Top: BurnStackY + (pos * 2), @@ -332,7 +332,7 @@ func (g *PokerGame) Deal(roomID string) { card = g.Ongoing.Deck[idx] idx++ evt := PokerEvent{ - ID: "card" + strconv.Itoa(idx), + ID: "card" + itoa(idx), Name: card, Idx: idx, Top: 150, @@ -367,7 +367,7 @@ func (g *PokerGame) Deal(roomID string) { top = d.Top2 } evt := PokerEvent{ - ID: "card" + strconv.Itoa(idx), + ID: "card" + itoa(idx), Name: name, Idx: idx, Top: top, @@ -586,7 +586,7 @@ func PokerBetHandler(c echo.Context) error { default: } } - return c.HTML(http.StatusOK, `<form method="post"><input type="number" name="bet" value="`+strconv.Itoa(bet)+`" style="width: 90px;" /><button>Bet</button></form>`) + return c.HTML(http.StatusOK, `<form method="post"><input type="number" name="bet" value="`+itoa(bet)+`" style="width: 90px;" /><button>Bet</button></form>`) } func PokerCallHandler(c echo.Context) error { @@ -736,7 +736,7 @@ func buildYourCardsHtml(authUser *database.User, g *PokerGame) string { func buildCardsHtml() (html string) { for i := 52; i >= 1; i-- { - html += `<div class="card-holder" id="card` + strconv.Itoa(i) + `"><div class="back"></div><div class="card"><div class=inner></div></div></div>` + html += `<div class="card-holder" id="card` + itoa(i) + `"><div class="back"></div><div class="card"><div class=inner></div></div></div>` } return } @@ -745,9 +745,9 @@ func buildTakeSeatHtml(authUser *database.User, g *PokerGame, roomID string) str takeSeatBtns := "" seated, _ := g.IsSeated(authUser.Username.String()) for i, p := range g.Players { - takeSeatBtns += `<iframe src="/poker/` + roomID + `/sit/` + strconv.Itoa(i+1) + `" class="takeSeat takeSeat` + strconv.Itoa(i+1) + `"></iframe>` + takeSeatBtns += `<iframe src="/poker/` + roomID + `/sit/` + itoa(i+1) + `" class="takeSeat takeSeat` + itoa(i+1) + `"></iframe>` if p.Username != "" || seated { - takeSeatBtns += `<style>.takeSeat` + strconv.Itoa(i+1) + ` { display: none; }</style>` + takeSeatBtns += `<style>.takeSeat` + itoa(i+1) + ` { display: none; }</style>` } } return takeSeatBtns @@ -759,13 +759,13 @@ func buildMainPotHtml(g *PokerGame) string { if g.Ongoing != nil { mainPot = g.Ongoing.MainPot } - html += `<style>#mainPot:before { content: "Pot: ` + strconv.Itoa(mainPot) + `"; }</style>` + html += `<style>#mainPot:before { content: "Pot: ` + itoa(mainPot) + `"; }</style>` return html } func buildCountdownsHtml() (html string) { for i := 1; i <= NbPlayers; i++ { - html += `<div id="countdown` + strconv.Itoa(i) + `" class="timer" style="--duration: ` + strconv.Itoa(MaxUserCountdown) + `;--size: 30;"><div class="mask"></div></div>` + html += `<div id="countdown` + itoa(i) + `" class="timer" style="--duration: ` + itoa(MaxUserCountdown) + `;--size: 30;"><div class="mask"></div></div>` } return } @@ -784,11 +784,11 @@ func buildSeatsHtml(g *PokerGame) string { seats := ` <div>` for i, p := range g.Players { - seats += `<div id="seat` + strconv.Itoa(i+1) + `"></div>` - seats += `<div id="seat` + strconv.Itoa(i+1) + `_cash"></div>` + seats += `<div id="seat` + itoa(i+1) + `"></div>` + seats += `<div id="seat` + itoa(i+1) + `_cash"></div>` if p.Username != "" { - seats += `<style>#seat` + strconv.Itoa(i+1) + `:before { content: "` + p.Username + `"; }</style>` - seats += `<style>#seat` + strconv.Itoa(i+1) + `_cash:before { content: "` + strconv.Itoa(p.Cash) + `"; }</style>` + seats += `<style>#seat` + itoa(i+1) + `:before { content: "` + p.Username + `"; }</style>` + seats += `<style>#seat` + itoa(i+1) + `_cash:before { content: "` + itoa(p.Cash) + `"; }</style>` } } seats += ` @@ -801,16 +801,16 @@ func drawSeatsHtml(authUser *database.User, g *PokerGame) string { seated, _ := g.IsSeated(authUser.Username.String()) for i, p := range g.Players { if p.Username != "" || seated { - html += `.takeSeat` + strconv.Itoa(i+1) + ` { display: none; }` + html += `.takeSeat` + itoa(i+1) + ` { display: none; }` } else { - html += `.takeSeat` + strconv.Itoa(i+1) + ` { display: block; }` + html += `.takeSeat` + itoa(i+1) + ` { display: block; }` } if p.Username != "" { - html += `#seat` + strconv.Itoa(i+1) + `:before { content: "` + p.Username + `"; }` - html += `#seat` + strconv.Itoa(i+1) + `_cash:before { content: "` + strconv.Itoa(p.Cash) + `"; }` + html += `#seat` + itoa(i+1) + `:before { content: "` + p.Username + `"; }` + html += `#seat` + itoa(i+1) + `_cash:before { content: "` + itoa(p.Cash) + `"; }` } else { - html += `#seat` + strconv.Itoa(i+1) + `:before { content: ""; }` - html += `#seat` + strconv.Itoa(i+1) + `_cash:before { content: ""; }` + html += `#seat` + itoa(i+1) + `:before { content: ""; }` + html += `#seat` + itoa(i+1) + `_cash:before { content: ""; }` } } html += "</style>" @@ -821,7 +821,7 @@ func drawCountDownStyle(evt PokerWaitTurnEvent) string { html := "<style>" html += `#countdown1, #countdown2, #countdown3, #countdown4, #countdown5, #countdown6 { display: none; }` if evt.Idx == -1 { - html += `#mainPot:before { content: "Pot: ` + strconv.Itoa(evt.MainPot) + `"; }` + html += `#mainPot:before { content: "Pot: ` + itoa(evt.MainPot) + `"; }` } else if evt.Idx == 0 { html += `#countdown1 { top: 50px; left: 600px; display: block; animation: time calc(var(--duration) * 1s) steps(1000, start) forwards; }` } else if evt.Idx == 1 { @@ -834,7 +834,7 @@ func drawCountDownStyle(evt PokerWaitTurnEvent) string { } func getPokerEventHtml(payload PokerEvent, animationTime string) string { - transform := `transform: translate(` + strconv.Itoa(payload.Left) + `px, ` + strconv.Itoa(payload.Top) + `px)` + transform := `transform: translate(` + itoa(payload.Left) + `px, ` + itoa(payload.Top) + `px)` if payload.Angle != "" { transform += ` rotateZ(` + payload.Angle + `)` } @@ -844,7 +844,7 @@ func getPokerEventHtml(payload PokerEvent, animationTime string) string { transform += ";" pokerEvtHtml := `<style> #` + payload.ID + ` { - z-index: ` + strconv.Itoa(payload.Idx) + `; + z-index: ` + itoa(payload.Idx) + `; transition: ` + animationTime + ` ease-in-out; ` + transform + ` } @@ -853,6 +853,10 @@ func getPokerEventHtml(payload PokerEvent, animationTime string) string { return pokerEvtHtml } +func itoa(i int) string { + return strconv.Itoa(i) +} + var pokerCss = `<style> html, body { height: 100%; width: 100%; } body { @@ -862,7 +866,7 @@ body { position: absolute; top: 0; left: 0; - transform: translateX(` + strconv.Itoa(DealerStackX) + `px) translateY(` + strconv.Itoa(DealerStackY) + `px) rotateY(` + BackfacingDeg + `); + transform: translateX(` + itoa(DealerStackX) + `px) translateY(` + itoa(DealerStackY) + `px) rotateY(` + BackfacingDeg + `); transform-style: preserve-3d; backface-visibility: hidden; width:50px; @@ -1073,7 +1077,7 @@ Loop: html := `<style>#deckStr:before { content: "` + evt.DeckStr + `"; }</style>` for i, p := range g.Players { if p.Username != "" { - html += `<style>#seat` + strconv.Itoa(i+1) + `_cash:before { content: "` + strconv.Itoa(p.Cash) + `"; }</style>` + html += `<style>#seat` + itoa(i+1) + `_cash:before { content: "` + itoa(p.Cash) + `"; }</style>` } } send(html) @@ -1081,12 +1085,12 @@ Loop: continue } else if evt, ok := payload.(YourCardEvent); ok { - send(`<style>#yourCard` + strconv.Itoa(evt.Idx) + `:before { content: "` + evt.Name + `"; color: ` + colorForCard(evt.Name) + `; }</style>`) + 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` + strconv.Itoa(evt.PlayerIdx+1) + `_cash:before { content: "` + strconv.Itoa(evt.Cash) + `"; }</style>` + html := `<style>#seat` + itoa(evt.PlayerIdx+1) + `_cash:before { content: "` + itoa(evt.Cash) + `"; }</style>` send(html) c.Response().Flush() continue @@ -1097,9 +1101,9 @@ Loop: continue } else if evt, ok := payload.(PlayerFoldEvent); ok { - transition := `transition: 1s ease-in-out; transform: translateX(` + strconv.Itoa(BurnStackX) + `px) translateY(` + strconv.Itoa(BurnStackY) + `px) rotateY(` + BackfacingDeg + `);` - html := `<style>#card` + strconv.Itoa(evt.Card1Idx) + ` { ` + transition + ` } - #card` + strconv.Itoa(evt.Card2Idx) + ` { ` + transition + ` }</style>` + 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 @@ -1107,10 +1111,10 @@ Loop: } else if evt, ok := payload.(ShowCardsEvent); ok { // TODO: Proper showing cards html := `<style>` - html += `#card` + strconv.Itoa(evt.Cards[0].Idx) + ` { transition: 1s ease-in-out; transform: rotateY(0); }` - html += `#card` + strconv.Itoa(evt.Cards[1].Idx) + ` { transition: 1s ease-in-out; transform: rotateY(0); }` - html += `#card` + strconv.Itoa(evt.Cards[0].Idx) + ` .card .inner:before { content: "` + evt.Cards[0].Name + `"; color: ` + colorForCard(evt.Cards[0].Name) + `; }` - html += `#card` + strconv.Itoa(evt.Cards[1].Idx) + ` .card .inner:before { content: "` + evt.Cards[1].Name + `"; color: ` + colorForCard(evt.Cards[1].Name) + `; }` + 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() @@ -1119,8 +1123,8 @@ Loop: } else if _, ok := payload.(ResetCardsEvent); ok { html := `<style>` for i := 1; i <= 52; i++ { - html += `#card` + strconv.Itoa(i) + ` { transition: 1s ease-in-out; transform: translateX(` + strconv.Itoa(DealerStackX) + `px) translateY(` + strconv.Itoa(DealerStackY) + `px) rotateY(` + BackfacingDeg + `); } - #card` + strconv.Itoa(i) + ` .card .inner:before { content: ""; }` + 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: ""; }