Allow tracking timers globally
This commit is contained in:
@@ -100,10 +100,15 @@ specified path.
|
||||
|
||||
(defn ^:private create-and-add-timer!
|
||||
[{:keys [update-fn!] :as screen} id]
|
||||
(some-> (get-in screen [:timers id]) .stop)
|
||||
(let [timer (timer*)]
|
||||
(update-fn! assoc-in [[:timers id] timer])
|
||||
timer))
|
||||
; remove timer if it already exists
|
||||
(when-let [old-timer (get-in screen [:timers id])]
|
||||
(.stop old-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!
|
||||
"Returns a [Timer](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/utils/Timer.html)
|
||||
|
||||
@@ -5,15 +5,6 @@
|
||||
|
||||
; 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
|
||||
[k]
|
||||
(throw (Exception. (str "The keyword " k " is not found."))))
|
||||
@@ -25,6 +16,32 @@
|
||||
(throw-key-not-found k))
|
||||
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
|
||||
|
||||
(def ^:const main-package "com.badlogic.gdx")
|
||||
|
||||
Reference in New Issue
Block a user