forked from LibreGaming/matchbot
Prune empty game if removing its only player
Signed-off-by: Sebastian Crane <seabass-labrax@gmx.com>
This commit is contained in:
parent
5c0918f990
commit
ae06d012ea
|
@ -1,7 +1,8 @@
|
|||
;; SPDX-License-Identifier: Apache-2.0
|
||||
;; SPDX-FileCopyrightText: 2021 Sebastian Crane <seabass-labrax@gmx.com>
|
||||
|
||||
(ns game)
|
||||
(ns game
|
||||
(:require [clojure.set :refer [superset?]]))
|
||||
|
||||
(defn get-players-of-game [state game]
|
||||
(get-in state [:games game]))
|
||||
|
@ -10,7 +11,10 @@
|
|||
(update-in state [:games game] #(set (conj % player))))
|
||||
|
||||
(defn remove-player-of-game [state game player]
|
||||
(update-in state [:games game] #(disj % player)))
|
||||
(update state :games
|
||||
#(if (superset? (set [player]) (% game))
|
||||
(dissoc % game)
|
||||
(update % game disj player))))
|
||||
|
||||
(defn get-games [state]
|
||||
(keys (:games state)))
|
||||
|
|
Loading…
Reference in New Issue