Add pref! macro

This commit is contained in:
oakes
2014-04-24 14:34:28 -04:00
parent 7917d4e458
commit c5b67ed7a9
3 changed files with 23 additions and 1 deletions

View File

@@ -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}

View File

@@ -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]

View File

@@ -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