Allow tracking timers globally
This commit is contained in:
@@ -100,10 +100,15 @@ specified path.
|
|||||||
|
|
||||||
(defn ^:private create-and-add-timer!
|
(defn ^:private create-and-add-timer!
|
||||||
[{:keys [update-fn!] :as screen} id]
|
[{:keys [update-fn!] :as screen} id]
|
||||||
(some-> (get-in screen [:timers id]) .stop)
|
; remove timer if it already exists
|
||||||
(let [timer (timer*)]
|
(when-let [old-timer (get-in screen [:timers id])]
|
||||||
(update-fn! assoc-in [[:timers id] timer])
|
(.stop old-timer)
|
||||||
timer))
|
(some-> u/*timers* (swap! disj old-timer)))
|
||||||
|
; create timer, add to screen map, and return it
|
||||||
|
(let [new-timer (timer*)]
|
||||||
|
(update-fn! assoc-in [[:timers id] new-timer])
|
||||||
|
(some-> u/*timers* (swap! conj new-timer))
|
||||||
|
new-timer))
|
||||||
|
|
||||||
(defn add-timer!
|
(defn add-timer!
|
||||||
"Returns a [Timer](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/utils/Timer.html)
|
"Returns a [Timer](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/utils/Timer.html)
|
||||||
|
|||||||
@@ -5,15 +5,6 @@
|
|||||||
|
|
||||||
; misc
|
; misc
|
||||||
|
|
||||||
(def ^:dynamic *asset-manager* nil)
|
|
||||||
|
|
||||||
(defn load-asset
|
|
||||||
[path type]
|
|
||||||
(when-let [^AssetManager am *asset-manager*]
|
|
||||||
(.load am path type)
|
|
||||||
(.finishLoading am)
|
|
||||||
(.get am path type)))
|
|
||||||
|
|
||||||
(defn throw-key-not-found
|
(defn throw-key-not-found
|
||||||
[k]
|
[k]
|
||||||
(throw (Exception. (str "The keyword " k " is not found."))))
|
(throw (Exception. (str "The keyword " k " is not found."))))
|
||||||
@@ -25,6 +16,32 @@
|
|||||||
(throw-key-not-found k))
|
(throw-key-not-found k))
|
||||||
obj))
|
obj))
|
||||||
|
|
||||||
|
; assets
|
||||||
|
|
||||||
|
(def ^:dynamic *asset-manager* nil)
|
||||||
|
|
||||||
|
(defn load-asset
|
||||||
|
[path type]
|
||||||
|
(when-let [^AssetManager am *asset-manager*]
|
||||||
|
(.load am path type)
|
||||||
|
(.finishLoading am)
|
||||||
|
(.get am path type)))
|
||||||
|
|
||||||
|
; timers
|
||||||
|
|
||||||
|
(def ^:dynamic *timers* nil)
|
||||||
|
|
||||||
|
(defn track-timers!
|
||||||
|
[]
|
||||||
|
(intern 'play-clj.utils '*timers* (atom #{})))
|
||||||
|
|
||||||
|
(defn stop-timers!
|
||||||
|
[]
|
||||||
|
(when *timers*
|
||||||
|
(doseq [t (deref *timers*)]
|
||||||
|
(.stop t))
|
||||||
|
(reset! *timers* #{})))
|
||||||
|
|
||||||
; converting keys
|
; converting keys
|
||||||
|
|
||||||
(def ^:const main-package "com.badlogic.gdx")
|
(def ^:const main-package "com.badlogic.gdx")
|
||||||
|
|||||||
Reference in New Issue
Block a user