Add and rename REPL functions
This commit is contained in:
@@ -1,26 +1,45 @@
|
|||||||
(ns play-clj.repl
|
(ns play-clj.repl
|
||||||
(:require [play-clj.core :refer :all]))
|
(: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
|
"Returns the entities in `screen-object`, optionally filtered by a supplied
|
||||||
function.
|
function.
|
||||||
|
|
||||||
(entities main-screen :player)"
|
(e main-screen :player)"
|
||||||
([screen-object]
|
([screen-object]
|
||||||
(-> screen-object :entities deref))
|
(-> screen-object :entities deref))
|
||||||
([screen-object filter-fn]
|
([screen-object filter-fn]
|
||||||
(filter filter-fn (entities screen-object))))
|
(filter filter-fn (e screen-object))))
|
||||||
|
|
||||||
(defn entities!
|
(defn e!
|
||||||
"Associates values to the entities in `screen-object` that match the supplied
|
"Resets the entities in `screen-object`, or associates values to the entities
|
||||||
function.
|
in `screen-object` that match the supplied function. Returns the entities that
|
||||||
|
were changed.
|
||||||
|
|
||||||
(entities! main-screen :player :health 10)"
|
(e! main-screen [])
|
||||||
[screen-object filter-fn & args]
|
(e! main-screen :player :health 10)"
|
||||||
(on-gl (swap! (:entities screen-object)
|
([screen-object new-entities]
|
||||||
(fn [entities]
|
(reset! (:entities screen-object) new-entities))
|
||||||
(for [e entities]
|
([screen-object filter-fn & args]
|
||||||
(if (filter-fn e)
|
(swap! (:entities screen-object)
|
||||||
(apply assoc e args)
|
(fn [entities]
|
||||||
e)))))
|
(for [e entities]
|
||||||
(entities screen-object filter-fn))
|
(if (filter-fn e)
|
||||||
|
(apply assoc e args)
|
||||||
|
e))))
|
||||||
|
(e screen-object filter-fn)))
|
||||||
|
|||||||
Reference in New Issue
Block a user