Add the ability to query arbitrary game states without using with-gs

This commit is contained in:
Jeremy Penner 2013-03-07 23:18:37 -05:00
parent a32058babd
commit 6b56991689

View file

@ -3,7 +3,6 @@
(defmulti update-index (fn [indextype indexold id entityold entitynew] indextype))
(defmulti query-index (fn [indextype index query] indextype))
(def gs-empty {:entities {} :indices {} :id-lim 0})
(def ^:dynamic *gamestate* (ref gs-empty))
@ -17,7 +16,8 @@
(defn get-gs [] @*gamestate*)
(defn entity [id] (get-in @*gamestate* [:entities id]))
(defn entity-in [gamestate id] (get-in gamestate [:entities id]))
(defn entity [id] (entity-in @*gamestate* id))
(defn- update-indices [id entityold entitynew]
(ref-set *gamestate*
@ -62,8 +62,11 @@
(assoc-in @*gamestate* [:entities id] value))]
(ref-set *gamestate* gsnew)))
(defn q-in [gamestate indextype query]
(query-index indextype (get-in gamestate [:indices indextype]) query))
(defn q [indextype query]
(query-index indextype (get-in @*gamestate* [:indices indextype]) query))
(q-in @*gamestate* indextype query))
(defmethod update-index :name [indextype indexold id entityold entitynew]
(-> indexold
@ -71,4 +74,3 @@
(add-id-to-index id (get entitynew :name))))
(defmethod query-index :name [indextype index query] (or (get index query) #{}))