Add :on-dispose

This commit is contained in:
oakes
2014-09-01 22:53:48 -04:00
parent b7c33a563b
commit bf77d6b82d

View File

@@ -63,7 +63,8 @@
(defn defscreen* (defn defscreen*
[screen entities [screen entities
{:keys [on-show on-render on-hide on-pause on-resize on-resume on-timer] {:keys [on-show on-render on-hide on-pause
on-resize on-resume on-dispose on-timer]
:as options}] :as options}]
(let [execute-fn! (fn [func & {:keys [] :as options}] (let [execute-fn! (fn [func & {:keys [] :as options}]
(when func (when func
@@ -92,6 +93,7 @@
[:total-time 0 [:total-time 0
:execute-fn! execute-fn! :execute-fn! execute-fn!
:update-fn! update-fn! :update-fn! update-fn!
:options options
:on-timer on-timer :on-timer on-timer
:input-listeners (input-listeners options execute-fn!) :input-listeners (input-listeners options execute-fn!)
:ui-listeners (ui-listeners options execute-fn!)]) :ui-listeners (ui-listeners options execute-fn!)])
@@ -109,7 +111,8 @@
:resize (fn [w h] :resize (fn [w h]
(execute-fn! on-resize :width w :height h) (execute-fn! on-resize :width w :height h)
(update-screen! @screen)) (update-screen! @screen))
:resume #(execute-fn! on-resume)})) :resume #(execute-fn! on-resume)
:dispose #(execute-fn! on-dispose)}))
(defmacro defscreen (defmacro defscreen
"Defines a screen, and creates vars for all the functions inside of it. All "Defines a screen, and creates vars for all the functions inside of it. All
@@ -505,6 +508,7 @@ keywords and functions in pairs."
(let [run-fn! (fn [k & args] (let [run-fn! (fn [k & args]
(doseq [screen screen-objects] (doseq [screen screen-objects]
(apply (get screen k) args)))] (apply (get screen k) args)))]
(some-> game-object .getScreen .dispose)
(.setScreen game-object (.setScreen game-object
(reify Screen (reify Screen
(show [this] (show [this]
@@ -518,7 +522,7 @@ keywords and functions in pairs."
(pause [this] (run-fn! :pause)) (pause [this] (run-fn! :pause))
(resize [this w h] (run-fn! :resize w h)) (resize [this w h] (run-fn! :resize w h))
(resume [this] (run-fn! :resume)) (resume [this] (run-fn! :resume))
(dispose [this]))))) (dispose [this] (run-fn! :dispose))))))
(defn set-screen-wrapper! (defn set-screen-wrapper!
"Sets a function that wraps around all screen functions, allowing you to "Sets a function that wraps around all screen functions, allowing you to