Add set-screen-wrapper! function
This commit is contained in:
@@ -120,7 +120,7 @@
|
|||||||
"Creates and displays a screen for the `game` object, using one or more
|
"Creates and displays a screen for the `game` object, using one or more
|
||||||
`screen` maps in the order they were provided.
|
`screen` maps in the order they were provided.
|
||||||
|
|
||||||
(set-screen! hello-world main-screen text-screen)"
|
(set-screen! my-game main-screen text-screen)"
|
||||||
[^Game game & screens]
|
[^Game game & screens]
|
||||||
(let [add-inputs! (fn []
|
(let [add-inputs! (fn []
|
||||||
(input! :set-input-processor (InputMultiplexer.))
|
(input! :set-input-processor (InputMultiplexer.))
|
||||||
@@ -139,6 +139,23 @@
|
|||||||
(resume [this] (run-fn! :resume))
|
(resume [this] (run-fn! :resume))
|
||||||
(dispose [this])))))
|
(dispose [this])))))
|
||||||
|
|
||||||
|
(defn set-screen-wrapper!
|
||||||
|
"Sets a function that wraps around all screen functions, allowing you to
|
||||||
|
handle errors and perform other custom actions each time they run.
|
||||||
|
|
||||||
|
; default behavior
|
||||||
|
(set-screen-wrapper! (fn [screen screen-fn]
|
||||||
|
(screen-fn)))
|
||||||
|
; if there is an error, print it out and switch to a blank screen
|
||||||
|
; (this is useful because it makes error recovery easier in a REPL)
|
||||||
|
(set-screen-wrapper! (fn [screen screen-fn]
|
||||||
|
(try (screen-fn)
|
||||||
|
(catch Exception e
|
||||||
|
(.printStackTrace e)
|
||||||
|
(set-screen! my-game blank-screen)))))"
|
||||||
|
[wrapper-fn]
|
||||||
|
(intern 'play-clj.core 'wrapper wrapper-fn))
|
||||||
|
|
||||||
(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. Returns the updated
|
is the atom storing the screen map behind the scenes. Returns the updated
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
(defmacro on-gl
|
(defmacro on-gl
|
||||||
"Runs the macro body on the GL thread.
|
"Runs the macro body on the GL thread.
|
||||||
|
|
||||||
(on-gl (set-screen! hello-world main-screen))"
|
(on-gl (set-screen! my-game main-screen))"
|
||||||
[& body]
|
[& body]
|
||||||
`(app! :post-runnable (fn [] ~@body)))
|
`(app! :post-runnable (fn [] ~@body)))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user