Make the filter-fn the first arg to be consistent with filter

This commit is contained in:
oakes
2014-08-02 22:25:57 -04:00
parent 1ed5ff9a2a
commit 40c1bc617a

View File

@@ -20,26 +20,23 @@ screen map.
"Returns the entities in `screen-object`, optionally filtered by a supplied "Returns the entities in `screen-object`, optionally filtered by a supplied
function. function.
(e main-screen :player?)" (e :player? main-screen)
(e texture? main-screen)"
([screen-object] ([screen-object]
(-> screen-object :entities deref)) (-> screen-object :entities deref))
([screen-object filter-fn] ([filter-fn screen-object]
(vec (filter filter-fn (e screen-object))))) (vec (filter filter-fn (e screen-object)))))
(defn e! (defn e!
"Resets the entities in `screen-object`, or associates values to the entities "Associates values to the entities in `screen-object` that match the supplied
in `screen-object` that match the supplied function. Returns the entities that function. Returns the entities that were changed.
were changed.
(e! main-screen []) (e! :player? main-screen :health 10)"
(e! main-screen :player? :health 10)" [filter-fn screen-object & args]
([screen-object new-entities] (swap! (:entities screen-object)
(reset! (:entities screen-object) new-entities)) (fn [entities]
([screen-object filter-fn & args] (vec (for [e entities]
(swap! (:entities screen-object) (if (filter-fn e)
(fn [entities] (apply assoc e args)
(vec (for [e entities] e)))))
(if (filter-fn e) (e filter-fn screen-object))
(apply assoc e args)
e)))))
(e screen-object filter-fn)))