more id indices and a helper for building them
This commit is contained in:
parent
48fbf954c9
commit
f3f5d007f9
|
@ -54,6 +54,11 @@
|
||||||
(assoc index key #{id})
|
(assoc index key #{id})
|
||||||
index)))
|
index)))
|
||||||
|
|
||||||
|
(defn update-id-index-by-key [key indexold id entityold entitynew]
|
||||||
|
(-> indexold
|
||||||
|
(remove-id-from-index id (get entityold key))
|
||||||
|
(add-id-to-index id (get entitynew key))))
|
||||||
|
|
||||||
(defn set-entity [id value]
|
(defn set-entity [id value]
|
||||||
(update-indices id (entity id) value)
|
(update-indices id (entity id) value)
|
||||||
(let [gsnew
|
(let [gsnew
|
||||||
|
@ -68,9 +73,11 @@
|
||||||
(defn q [indextype query]
|
(defn q [indextype query]
|
||||||
(q-in @*gamestate* indextype query))
|
(q-in @*gamestate* indextype query))
|
||||||
|
|
||||||
(defmethod update-index :name [indextype indexold id entityold entitynew]
|
(defn define-id-index [indextype & [key]]
|
||||||
(-> indexold
|
(let [key (or key indextype)]
|
||||||
(remove-id-from-index id (get entityold :name))
|
(defmethod update-index indextype [indextype indexold id entityold entitynew]
|
||||||
(add-id-to-index id (get entitynew :name))))
|
(update-id-index-by-key key indexold id entityold entitynew))
|
||||||
|
(defmethod query-index indextype [indextype index query] (or (get index query) #{}))))
|
||||||
|
|
||||||
(defmethod query-index :name [indextype index query] (or (get index query) #{}))
|
(define-id-index :name)
|
||||||
|
(define-id-index :type)
|
||||||
|
|
Loading…
Reference in a new issue