commit bb55f3d613ce494a1e82ed29b4d8713a2e432bd9
parent 19b759500e2ec6cd9f3104f195fc81e1aa0bfba9
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Sun, 3 Dec 2023 22:00:39 -0500
poker stuff
Diffstat:
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go
@@ -581,6 +581,10 @@ func MaxInt[T Ints](vals ...T) T {
return max
}
+func Shuffle[T any](s []T) {
+ rand.Shuffle(len(s), func(i, j int) { s[i], s[j] = s[j], s[i] })
+}
+
type Ints interface {
int | int64
}
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -775,12 +775,13 @@ func PokerHandler(c echo.Context) error {
_, _ = c.Response().Write([]byte(s))
}
- names := []string{
+ deck := []string{
"A♠", "2♠", "3♠", "4♠", "5♠", "6♠", "7♠", "8♠", "9♠", "10♠", "J♠", "Q♠", "K♠",
"A♥", "2♥", "3♥", "4♥", "5♥", "6♥", "7♥", "8♥", "9♥", "10♥", "J♥", "Q♥", "K♥",
"A♣", "2♣", "3♣", "4♣", "5♣", "6♣", "7♣", "8♣", "9♣", "10♣", "J♣", "Q♣", "K♣",
"A♦", "2♦", "3♦", "4♦", "5♦", "6♦", "7♦", "8♦", "9♦", "10♦", "J♦", "Q♦", "K♦",
}
+ utils.Shuffle(deck)
quit := hutils.CloseSignalChan(c)
myTopic := "room_" + authUser.ID.String()
@@ -792,7 +793,9 @@ func PokerHandler(c echo.Context) error {
case <-quit:
return
}
- PokerPubSub.Pub(myTopic, PokerEvent{ID: "card" + strconv.Itoa(i), Name: utils.RandChoice(names)})
+ var card string
+ card, deck = deck[0], deck[1:]
+ PokerPubSub.Pub(myTopic, PokerEvent{ID: "card" + strconv.Itoa(i), Name: card})
}
}()
@@ -888,6 +891,11 @@ Loop:
continue
}
fmt.Println(payload)
+ color := "black"
+ if strings.Contains(payload.Name, "♥") ||
+ strings.Contains(payload.Name, "♦") {
+ color = "red"
+ }
send(`<style>
#` + payload.ID + ` {
animation-name:fly-in;
@@ -896,7 +904,7 @@ Loop:
animation-timing-function:ease-in-out;
animation-fill-mode: forwards;
}
-#` + payload.ID + ` .card:before { content: "` + payload.Name + `"; }
+#` + payload.ID + ` .card:before { content: "` + payload.Name + `"; color: ` + color + `; }
</style>`)
c.Response().Flush()
}