Provide a cleaner way to wrap screen functions
This commit is contained in:
@@ -40,6 +40,11 @@
|
|||||||
(when (not= e-old e-new)
|
(when (not= e-old e-new)
|
||||||
(compare-and-set! e-atom e-old e-new)))
|
(compare-and-set! e-atom e-old e-new)))
|
||||||
|
|
||||||
|
(defn ^:private wrapper
|
||||||
|
"Internal use only"
|
||||||
|
[screen f]
|
||||||
|
(f))
|
||||||
|
|
||||||
(defn defscreen*
|
(defn defscreen*
|
||||||
"Internal use only"
|
"Internal use only"
|
||||||
[{:keys [screen entities
|
[{:keys [screen entities
|
||||||
@@ -48,7 +53,8 @@
|
|||||||
(let [execute-fn! (fn [func & {:keys [] :as options}]
|
(let [execute-fn! (fn [func & {:keys [] :as options}]
|
||||||
(when func
|
(when func
|
||||||
(let [old-entities @entities]
|
(let [old-entities @entities]
|
||||||
(some->> (func (merge @screen options) old-entities)
|
(some->> #(func (merge @screen options) old-entities)
|
||||||
|
(wrapper screen)
|
||||||
list
|
list
|
||||||
flatten
|
flatten
|
||||||
(remove nil?)
|
(remove nil?)
|
||||||
@@ -115,9 +121,13 @@ object"
|
|||||||
[n & {:keys [] :as options}]
|
[n & {:keys [] :as options}]
|
||||||
`(defonce ~n (defgame* ~options)))
|
`(defonce ~n (defgame* ~options)))
|
||||||
|
|
||||||
(defn set-screen-with-options!
|
(defn set-screen!
|
||||||
"Internal use only"
|
"Creates a [Screen](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/Screen.html)
|
||||||
[^Game game screens & {:keys [wrap]}]
|
object, sets it as the screen for the `game`, and runs the functions from
|
||||||
|
`screens` in the order they are provided in
|
||||||
|
|
||||||
|
(set-screen! hello-world main-screen text-screen)"
|
||||||
|
[^Game game & screens]
|
||||||
(let [add-inputs! (fn []
|
(let [add-inputs! (fn []
|
||||||
(input! :set-input-processor (InputMultiplexer.))
|
(input! :set-input-processor (InputMultiplexer.))
|
||||||
(doseq [{:keys [input-listeners]} screens]
|
(doseq [{:keys [input-listeners]} screens]
|
||||||
@@ -125,9 +135,7 @@ object"
|
|||||||
(add-input! listener))))
|
(add-input! listener))))
|
||||||
run-fn! (fn [k & args]
|
run-fn! (fn [k & args]
|
||||||
(doseq [screen screens]
|
(doseq [screen screens]
|
||||||
(if wrap
|
(apply (get screen k) args)))]
|
||||||
(wrap screen k args)
|
|
||||||
(apply (get screen k) args))))]
|
|
||||||
(.setScreen game (reify Screen
|
(.setScreen game (reify Screen
|
||||||
(show [this] (add-inputs!) (run-fn! :show))
|
(show [this] (add-inputs!) (run-fn! :show))
|
||||||
(render [this d] (run-fn! :render d))
|
(render [this d] (run-fn! :render d))
|
||||||
@@ -137,15 +145,6 @@ object"
|
|||||||
(resume [this] (run-fn! :resume))
|
(resume [this] (run-fn! :resume))
|
||||||
(dispose [this])))))
|
(dispose [this])))))
|
||||||
|
|
||||||
(defn set-screen!
|
|
||||||
"Creates a [Screen](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/Screen.html)
|
|
||||||
object, sets it as the screen for the `game`, and runs the functions from
|
|
||||||
`screens` in the order they are provided in
|
|
||||||
|
|
||||||
(set-screen! hello-world main-screen text-screen)"
|
|
||||||
[game & screens]
|
|
||||||
(set-screen-with-options! game screens))
|
|
||||||
|
|
||||||
(defn update!
|
(defn update!
|
||||||
"Runs the equivalent of `(swap! screen-atom assoc ...)`, where `screen-atom`
|
"Runs the equivalent of `(swap! screen-atom assoc ...)`, where `screen-atom`
|
||||||
is the atom storing the screen map behind the scenes, and returns the new screen
|
is the atom storing the screen map behind the scenes, and returns the new screen
|
||||||
|
|||||||
Reference in New Issue
Block a user