Add the ability to query arbitrary game states without using with-gs
This commit is contained in:
parent
a32058babd
commit
6b56991689
|
@ -3,7 +3,6 @@
|
||||||
(defmulti update-index (fn [indextype indexold id entityold entitynew] indextype))
|
(defmulti update-index (fn [indextype indexold id entityold entitynew] indextype))
|
||||||
(defmulti query-index (fn [indextype index query] indextype))
|
(defmulti query-index (fn [indextype index query] indextype))
|
||||||
|
|
||||||
|
|
||||||
(def gs-empty {:entities {} :indices {} :id-lim 0})
|
(def gs-empty {:entities {} :indices {} :id-lim 0})
|
||||||
|
|
||||||
(def ^:dynamic *gamestate* (ref gs-empty))
|
(def ^:dynamic *gamestate* (ref gs-empty))
|
||||||
|
@ -17,7 +16,8 @@
|
||||||
|
|
||||||
(defn get-gs [] @*gamestate*)
|
(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]
|
(defn- update-indices [id entityold entitynew]
|
||||||
(ref-set *gamestate*
|
(ref-set *gamestate*
|
||||||
|
@ -62,8 +62,11 @@
|
||||||
(assoc-in @*gamestate* [:entities id] value))]
|
(assoc-in @*gamestate* [:entities id] value))]
|
||||||
(ref-set *gamestate* gsnew)))
|
(ref-set *gamestate* gsnew)))
|
||||||
|
|
||||||
|
(defn q-in [gamestate indextype query]
|
||||||
|
(query-index indextype (get-in gamestate [:indices indextype]) query))
|
||||||
|
|
||||||
(defn q [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]
|
(defmethod update-index :name [indextype indexold id entityold entitynew]
|
||||||
(-> indexold
|
(-> indexold
|
||||||
|
@ -71,4 +74,3 @@
|
||||||
(add-id-to-index id (get entitynew :name))))
|
(add-id-to-index id (get entitynew :name))))
|
||||||
|
|
||||||
(defmethod query-index :name [indextype index query] (or (get index query) #{}))
|
(defmethod query-index :name [indextype index query] (or (get index query) #{}))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue