Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions src/clj/web/lobby.clj
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,15 @@
:spectatorhands
:started
:timer
:title])
:title
:old])

(defn lobby-summary
"Strips private server information from a game map, preparing to send the game to clients."
([lobby] (lobby-summary lobby nil))
([lobby participating?]
(-> lobby
(assoc :old (> (count (or (:messages lobby) [])) 10))
(update :password boolean)
(update :players #(prepare-players lobby %))
(update :spectators #(prepare-players lobby %))
Expand Down Expand Up @@ -233,19 +235,24 @@
(not (or user-blocked-players? players-blocked-user?))))
lobbies)))

(defn sorted-lobbies [lobbies]
"ideally we only sort these once"
(->> (map lobby-summary lobbies)
(sort-by :date)
(reverse)
(sort-by :started)))

(comment
(->> (for [x (range 5 10)]
{:date (doto (java.util.Calendar/getInstance)
(.set (+ 2000 (+ (rand-int x) (rand-int x))) 1 2))
:started (rand-nth [true false])})
(summaries-for-lobbies)))
(defn categorize-lobby
"Categorizes the lobby into one of the following categoris:
open-recent, open-old, started-allowing-spectators, or started-no-spectators"
[lobby]
(cond
(not (:started lobby)) (if (:old lobby) :open-old :open-recent)
(:allow-spectator lobby) :allowing-spectators
:else :no-spectators))

(defn sorted-lobbies
"Sorts `lobbies` into a list with opened games on top, and other games below.
Open games will be sorted oldest to newest, other games will be sorted newest to oldest."
[lobbies]
(let [grouped-lobbies (group-by #(categorize-lobby %)
(->> (map lobby-summary lobbies)
(sort-by :date)))
{:keys [open-recent open-old allowing-spectators no-spectators]} grouped-lobbies]
(concat open-recent open-old (reverse allowing-spectators) (reverse no-spectators))))

(defn prepare-lobby-list
[lobbies users]
Expand Down