From 3c94e08dbf0d7323a5aa1bb9707878f80e293029 Mon Sep 17 00:00:00 2001 From: oakes Date: Sun, 16 Mar 2014 13:31:18 -0400 Subject: [PATCH] Allow passing a custom error function for screens --- src/play_clj/core.clj | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/play_clj/core.clj b/src/play_clj/core.clj index 4b44bc4..4c691f8 100644 --- a/src/play_clj/core.clj +++ b/src/play_clj/core.clj @@ -106,21 +106,19 @@ object" [n & {:keys [] :as options}] `(defonce ~n (defgame* ~options))) -(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 game & screens] +(defn set-screen-with-options! + "Internal use only" + [^Game game screens error-fn] (let [add-inputs! (fn [] (input! :set-input-processor (InputMultiplexer.)) (doseq [{:keys [input-listeners]} screens] (doseq [listener input-listeners] (add-input! listener)))) run-fn! (fn [k & args] - (doseq [screen screens] - (apply (get screen k) args)))] + (try + (doseq [screen screens] + (apply (get screen k) args)) + (catch Exception e (error-fn e))))] (.setScreen game (reify Screen (show [this] (add-inputs!) (run-fn! :show)) (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)) (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! "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