From dba57240ddede254882555c80abeb3f37c503092 Mon Sep 17 00:00:00 2001 From: oakes Date: Thu, 31 Jul 2014 21:10:27 -0400 Subject: [PATCH] Add and rename REPL functions --- src/play_clj/repl.clj | 49 ++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/src/play_clj/repl.clj b/src/play_clj/repl.clj index 3401a13..8617f28 100644 --- a/src/play_clj/repl.clj +++ b/src/play_clj/repl.clj @@ -1,26 +1,45 @@ (ns play-clj.repl (:require [play-clj.core :refer :all])) -(defn entities +(defn s + "Returns the screen map in `screen-object`. + + (s main-screen)" + [screen-object] + (-> screen-object :screen deref)) + +(defn s! + "Associates values to the screen map in `screen-object`. Returns the new +screen map. + + (s! main-screen :camera (orthographic))" + [screen-object & args] + (apply swap! (:screen screen-object) assoc args)) + +(defn e "Returns the entities in `screen-object`, optionally filtered by a supplied function. - (entities main-screen :player)" + (e main-screen :player)" ([screen-object] (-> screen-object :entities deref)) ([screen-object filter-fn] - (filter filter-fn (entities screen-object)))) + (filter filter-fn (e screen-object)))) -(defn entities! - "Associates values to the entities in `screen-object` that match the supplied -function. +(defn e! + "Resets the entities in `screen-object`, or associates values to the entities +in `screen-object` that match the supplied function. Returns the entities that +were changed. - (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)) + (e! main-screen []) + (e! main-screen :player :health 10)" + ([screen-object new-entities] + (reset! (:entities screen-object) new-entities)) + ([screen-object filter-fn & args] + (swap! (:entities screen-object) + (fn [entities] + (for [e entities] + (if (filter-fn e) + (apply assoc e args) + e)))) + (e screen-object filter-fn)))