diff --git a/doclet/resources/classes.edn b/doclet/resources/classes.edn index d52304f..5b26d33 100644 --- a/doclet/resources/classes.edn +++ b/doclet/resources/classes.edn @@ -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} diff --git a/src/play_clj/core.clj b/src/play_clj/core.clj index e154612..1c71ef1 100644 --- a/src/play_clj/core.clj +++ b/src/play_clj/core.clj @@ -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] diff --git a/src/play_clj/core_utils.clj b/src/play_clj/core_utils.clj index a9d9010..0f04991 100644 --- a/src/play_clj/core_utils.clj +++ b/src/play_clj/core_utils.clj @@ -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