From dd304b73446a26d8091f0ae86e45a85579c33adc Mon Sep 17 00:00:00 2001 From: oakes Date: Thu, 31 Jul 2014 00:15:49 -0400 Subject: [PATCH] Start work on REPL convenience functions --- src/play_clj/repl.clj | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/play_clj/repl.clj diff --git a/src/play_clj/repl.clj b/src/play_clj/repl.clj new file mode 100644 index 0000000..2ccde12 --- /dev/null +++ b/src/play_clj/repl.clj @@ -0,0 +1,27 @@ +(ns play-clj.repl + (:require [clojure.pprint :refer :all] + [play-clj.core :refer :all])) + +(defn entities + "Returns the entities in `screen-object`, optionally filtered by a supplied +function. + + (entities main-screen :player)" + ([screen-object] + (-> screen-object :entities deref)) + ([screen-object filter-fn] + (filter filter-fn (entities screen-object)))) + +(defn entities! + "Associates values to the entities in `screen-object` that match the supplied +function. + + (entities! main-screen :player :health 10)" + [screen-object filter-fn & args] + (on-gl (swap! (:entities screen-object) + (fn [entities] + (for [e entities] + (if (filter-fn e) + (apply assoc e args) + e))))) + (entities screen-object filter-fn))