Generalize wrapping code
This commit is contained in:
@@ -108,17 +108,17 @@ object"
|
|||||||
|
|
||||||
(defn set-screen-with-options!
|
(defn set-screen-with-options!
|
||||||
"Internal use only"
|
"Internal use only"
|
||||||
[^Game game screens error-fn]
|
[^Game game screens & {:keys [wrap]}]
|
||||||
(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]
|
||||||
(try
|
(doseq [screen screens]
|
||||||
(doseq [screen screens]
|
(if wrap
|
||||||
(apply (get screen k) args))
|
(wrap (get screen k) args)
|
||||||
(catch Exception e (error-fn e))))]
|
(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))
|
||||||
@@ -135,7 +135,7 @@ object, sets it as the screen for the `game`, and runs the functions from
|
|||||||
|
|
||||||
(set-screen! hello-world main-screen text-screen)"
|
(set-screen! hello-world main-screen text-screen)"
|
||||||
[game & screens]
|
[game & screens]
|
||||||
(set-screen-with-options! game screens #(throw %)))
|
(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`
|
||||||
|
|||||||
Reference in New Issue
Block a user