diff --git a/src/hottub/gs.clj b/src/hottub/gs.clj index 2abd84c..ef808f6 100644 --- a/src/hottub/gs.clj +++ b/src/hottub/gs.clj @@ -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) #{})) -