Allow passing a custom error function for screens
This commit is contained in:
@@ -106,21 +106,19 @@ object"
|
|||||||
[n & {:keys [] :as options}]
|
[n & {:keys [] :as options}]
|
||||||
`(defonce ~n (defgame* ~options)))
|
`(defonce ~n (defgame* ~options)))
|
||||||
|
|
||||||
(defn set-screen!
|
(defn set-screen-with-options!
|
||||||
"Creates a [Screen](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/Screen.html)
|
"Internal use only"
|
||||||
object, sets it as the screen for the `game`, and runs the functions from
|
[^Game game screens error-fn]
|
||||||
`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]
|
||||||
(doseq [listener input-listeners]
|
(doseq [listener input-listeners]
|
||||||
(add-input! listener))))
|
(add-input! listener))))
|
||||||
run-fn! (fn [k & args]
|
run-fn! (fn [k & args]
|
||||||
(doseq [screen screens]
|
(try
|
||||||
(apply (get screen k) args)))]
|
(doseq [screen screens]
|
||||||
|
(apply (get screen k) args))
|
||||||
|
(catch Exception e (error-fn e))))]
|
||||||
(.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))
|
||||||
@@ -130,6 +128,15 @@ object, sets it as the screen for the `game`, and runs the functions from
|
|||||||
(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 #(throw %)))
|
||||||
|
|
||||||
(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