Start work on REPL convenience functions

This commit is contained in:
oakes
2014-07-31 00:15:49 -04:00
parent d442a9168e
commit dd304b7344

27
src/play_clj/repl.clj Normal file
View File

@@ -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))