dkforest

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

commit b6b3cc528b5320c675926f5621bde29ef8f8c0ca
parent b47da0b68d034c57244897f277d6928c6dc2176c
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon, 17 Jul 2023 21:29:12 -0400

simplify code

Diffstat:
Mpkg/hashset/hashset.go | 4++++
Mpkg/web/handlers/api/v1/chat.go | 2+-
Mpkg/web/handlers/interceptors/werewolf.go | 4++--
3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/pkg/hashset/hashset.go b/pkg/hashset/hashset.go @@ -38,6 +38,10 @@ func (h *HashSet[V]) Len() int { return len(h.items) } +func (h *HashSet[V]) Empty() bool { + return len(h.items) == 0 +} + // Clear clears the set, removing all values. func (h *HashSet[V]) Clear() { h.items = make(map[V]struct{}) diff --git a/pkg/web/handlers/api/v1/chat.go b/pkg/web/handlers/api/v1/chat.go @@ -269,7 +269,7 @@ Loop: // Delete msg from the map that keep track of unread messages. // If the map is now empty, we hide the read-marker. msgsMap.Delete(msgTyp.Msg.ID) - if msgsMap.Len() == 0 { + if msgsMap.Empty() { updateReadMarker() } diff --git a/pkg/web/handlers/interceptors/werewolf.go b/pkg/web/handlers/interceptors/werewolf.go @@ -427,7 +427,7 @@ func (b *Werewolf) StartGame(db *database.DkfDB) { } b.Narrate("Players still alive: "+b.alivePlayersStr(), nil, nil) - if b.werewolfSet.Len() == 0 { + if b.werewolfSet.Empty() { b.Narrate("Townspeople win", nil, nil) break } else if b.townspersonSet.Len() <= 1 { @@ -458,7 +458,7 @@ func (b *Werewolf) StartGame(db *database.DkfDB) { b.Narrate("Players still alive: "+b.alivePlayersStr(), nil, nil) - if b.werewolfSet.Len() == 0 { + if b.werewolfSet.Empty() { b.Narrate("Townspeople win", nil, nil) break } else if b.townspersonSet.Len() == 1 {