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})
|
||||
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]
|
||||
(update-indices id (entity id) value)
|
||||
(let [gsnew
|
||||
|
@ -68,9 +73,11 @@
|
|||
(defn q [indextype query]
|
||||
(q-in @*gamestate* indextype query))
|
||||
|
||||
(defmethod update-index :name [indextype indexold id entityold entitynew]
|
||||
(-> indexold
|
||||
(remove-id-from-index id (get entityold :name))
|
||||
(add-id-to-index id (get entitynew :name))))
|
||||
(defn define-id-index [indextype & [key]]
|
||||
(let [key (or key indextype)]
|
||||
(defmethod update-index indextype [indextype indexold id entityold entitynew]
|
||||
(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