Add pref! macro
This commit is contained in:
@@ -175,6 +175,7 @@
|
||||
"polygon-shape!" :methods}
|
||||
"Polyline" {"polyline" :methods
|
||||
"polyline!" :methods}
|
||||
"Preferences" {"pref!" :methods}
|
||||
"PrismaticJointDef" {"joint-def :prismatic" :fields}
|
||||
"ProgressBar.ProgressBarStyle" {"style :progress-bar" :constructors}
|
||||
"PulleyJointDef" {"joint-def :pulley" :fields}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
[play-clj.math :as m]
|
||||
[play-clj.utils :as u])
|
||||
(:import [com.badlogic.gdx Application Audio Files Game Gdx Graphics Input
|
||||
InputMultiplexer InputProcessor Net Screen]
|
||||
InputMultiplexer InputProcessor Net Preferences Screen]
|
||||
[com.badlogic.gdx.audio Sound]
|
||||
[com.badlogic.gdx.assets AssetManager]
|
||||
[com.badlogic.gdx.assets.loaders AsynchronousAssetLoader]
|
||||
|
||||
@@ -49,6 +49,27 @@ specified path.
|
||||
(PixmapIO/writePNG handle pic)
|
||||
(pixmap! pic :dispose))))
|
||||
|
||||
(defmacro pref!
|
||||
"Retrieves and stores preferences. The `name` should be a unique string.
|
||||
|
||||
; define the name we'll be using
|
||||
(def ^:const pref-name \"my-game.settings\")
|
||||
; store a single preference
|
||||
(pref! pref-name :put-float \"player-health\" 40)
|
||||
; store multiple preferences
|
||||
(pref! pref-name :put {\"player-health\" 40
|
||||
\"player-x\" 20
|
||||
\"player-y\" 50})
|
||||
; you may want to call this to make sure it's stored on disk
|
||||
(pref! pref-name :flush)
|
||||
; retrieve a single preference
|
||||
(pref! pref-name :get-float \"player-health\")"
|
||||
[name k & options]
|
||||
`(let [^Preferences p# (if (string? ~name)
|
||||
(app! :get-preferences ~name)
|
||||
~name)]
|
||||
(u/call! p# ~k ~@options)))
|
||||
|
||||
; static fields
|
||||
|
||||
(defmacro scaling
|
||||
|
||||
Reference in New Issue
Block a user