Overhaul the symbol system again

This commit is contained in:
oakes
2014-01-29 15:01:55 -05:00
parent 5ecdf787b7
commit 1cb42d38a6
7 changed files with 46 additions and 59 deletions

View File

@@ -21,7 +21,8 @@
(color 1 1 1 1)" (color 1 1 1 1)"
[& args] [& args]
`~(if (keyword? (first args)) `~(if (keyword? (first args))
`(Color. ^Color (u/static-upper :graphics :Color ~(first args))) `(Color. ^Color ~(u/gdx-field :graphics :Color
(u/key->upper (first args))))
`(Color. ~@args))) `(Color. ~@args)))
; interop ; interop
@@ -99,7 +100,7 @@
(key-code :a) (key-code :a)
(key-code :page-down)" (key-code :page-down)"
[k] [k]
`(u/static-upper "Input$Keys" ~k)) `~(u/gdx-field "Input$Keys" (u/key->upper k)))
(defmacro is-pressed? (defmacro is-pressed?
"Returns a boolean indicating if the key cooresponding to `k` is being pressed "Returns a boolean indicating if the key cooresponding to `k` is being pressed

View File

@@ -143,8 +143,8 @@
(play-mode :loop-reversed) (play-mode :loop-reversed)
(play-mode :normal) (play-mode :normal)
(play-mode :reversed)" (play-mode :reversed)"
[key] [k]
`(u/static-upper :graphics :g2d :Animation ~key)) `~(u/gdx-field :graphics :g2d :Animation (u/key->upper k)))
(defn animation* (defn animation*
"The function version of `animation`" "The function version of `animation`"

View File

@@ -32,11 +32,11 @@
; bodies ; bodies
(defmacro ^:private body-type (defn ^:private body-type
"Internal use only" "Internal use only"
[k] [k]
`(symbol (str u/main-package ".physics.box2d.BodyDef$BodyType/" (u/gdx-class :physics :box2d :BodyDef
(u/key->pascal ~k) "Body"))) (str "BodyType/" (u/key->pascal k) "Body")))
(defmacro body-def (defmacro body-def
"Returns a [BodyDef](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/physics/box2d/BodyDef.html) "Returns a [BodyDef](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/physics/box2d/BodyDef.html)
@@ -102,11 +102,10 @@
; joints ; joints
(defmacro ^:private joint-init (defn ^:private joint-init
"Internal use only" "Internal use only"
[k] [k]
`(symbol (str u/main-package ".physics.box2d.joints." (u/gdx :physics :box2d :joints (str (u/key->pascal k) "JointDef.")))
(u/key->pascal ~k) "JointDef.")))
(defmacro joint-def (defmacro joint-def
"Returns a subclass of [JointDef](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/physics/box2d/JointDef.html) "Returns a subclass of [JointDef](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/physics/box2d/JointDef.html)

View File

@@ -98,11 +98,10 @@
; attribute ; attribute
(defmacro ^:private attribute-init (defn ^:private attribute-init
"Internal use only" "Internal use only"
[k] [k]
`(symbol (str u/main-package ".graphics.g3d.attributes." (u/gdx :graphics :g3d :attributes (str (u/key->pascal k) "Attribute.")))
(u/key->pascal ~k) "Attribute.")))
(defmacro attribute (defmacro attribute
"Returns a subclass of [Attribute](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/Attribute.html) "Returns a subclass of [Attribute](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/Attribute.html)
@@ -116,20 +115,16 @@
(attribute-type :color :diffuse)" (attribute-type :color :diffuse)"
[type k] [type k]
`(u/static-pascal :graphics `~(u/gdx-field :graphics :g3d :attributes
:g3d (str (u/key->pascal type) "Attribute")
:attributes (u/key->pascal k)))
~(str (u/key->pascal type) "Attribute")
~k))
(defmacro attribute! (defmacro attribute!
"Calls a single method on a subclass of [Attribute](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/Attribute.html) "Calls a single method on a subclass of [Attribute](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/Attribute.html)
(attribute! :color :create-diffuse (color :blue)" (attribute! :color :create-diffuse (color :blue))"
[type k & options] [type k & options]
`((u/static-camel :graphics `(~(u/gdx-field :graphics :g3d :attributes
:g3d (str (u/key->pascal type) "Attribute")
:attributes (u/key->camel k))
~(str (u/key->pascal type) "Attribute")
~k)
~@options)) ~@options))

View File

@@ -11,35 +11,35 @@
(defmacro geometry! (defmacro geometry!
"Calls a single method on [GeometryUtils](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/GeometryUtils.html)" "Calls a single method on [GeometryUtils](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/GeometryUtils.html)"
[k & options] [k & options]
`(~(u/static-camel :math :GeometryUtils k) ~@options)) `(~(u/gdx-field :math :GeometryUtils (u/key->camel k)) ~@options))
(defmacro interpolation (defmacro interpolation
"Returns a static class in [Interpolation](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Interpolation.html) "Returns a static class in [Interpolation](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Interpolation.html)
(interpolation :bounce)" (interpolation :bounce)"
[k] [k]
`~(static-class :math :Interpolation k)) `~(u/gdx-class :math :Interpolation (u/key->pascal k)))
(defmacro intersector! (defmacro intersector!
"Calls a single method on [Intersector](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Intersector.html) "Calls a single method on [Intersector](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Intersector.html)
(intersector! :is-point-in-triangle 0 1 0 0 1 2 3 0)" (intersector! :is-point-in-triangle 0 1 0 0 1 2 3 0)"
[k & options] [k & options]
`(~(u/static-camel :math :Intersector k) ~@options)) `(~(u/gdx-field :math :Intersector (u/key->pascal k)) ~@options))
(defmacro math! (defmacro math!
"Calls a single method on [MathUtils](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/MathUtils.html) "Calls a single method on [MathUtils](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/MathUtils.html)
(math! :ceil 0.1)" (math! :ceil 0.1)"
[k & options] [k & options]
`(~(u/static-camel :math :MathUtils k) ~@options)) `(~(u/gdx-field :math :MathUtils (u/key->camel k)) ~@options))
(defmacro plane-side (defmacro plane-side
"Returns a static field in [Plane.PlaneSide](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Plane.PlaneSide.html) "Returns a static field in [Plane.PlaneSide](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Plane.PlaneSide.html)
(plane-side :back)" (plane-side :back)"
[k] [k]
`~(u/static-class :math :Plane (str "PlaneSide/" (u/key->pascal k)))) `~(u/gdx-field :math :Plane (str "PlaneSide/" (u/key->pascal k))))
; bezier ; bezier

View File

@@ -18,8 +18,8 @@
(drawable :texture-region)" (drawable :texture-region)"
[k & options] [k & options]
`(~(symbol (str u/main-package ".scenes.scene2d.utils." `(~(u/gdx :scenes :scene2d :utils
(u/key->pascal k) "Drawable.")) (str (u/key->pascal k) "Drawable."))
~@options)) ~@options))
(defmacro style (defmacro style
@@ -27,9 +27,9 @@
(style :check-box)" (style :check-box)"
[k & options] [k & options]
`(~(symbol (str u/main-package ".scenes.scene2d.ui." `(~(u/gdx-class :scenes :scene2d :ui
(u/key->pascal k) "$" (u/key->pascal k)
(u/key->pascal k) "Style.")) (str (u/key->pascal k) "Style."))
~@options)) ~@options))
(defmacro skin (defmacro skin
@@ -45,7 +45,7 @@ based on the file at `path`
(align :center)" (align :center)"
[k] [k]
`(u/static-camel :scenes :scene2d :utils :Align ~k)) `~(u/gdx-field :scenes :scene2d :utils :Align (u/key->camel k)))
(defn cell! (defn cell!
"Calls a single method on a [Cell](https://github.com/libgdx/libgdx/blob/master/gdx/src/com/esotericsoftware/tablelayout/Cell.java) "Calls a single method on a [Cell](https://github.com/libgdx/libgdx/blob/master/gdx/src/com/esotericsoftware/tablelayout/Cell.java)

View File

@@ -63,36 +63,28 @@
[k] [k]
(symbol (str "." (key->camel k)))) (symbol (str "." (key->camel k))))
; static methods/fields ; classes/methods/fields
(defn static-symbol (defn ^:private add-divider
"Returns a fully-qualified static method or field" "Internal use only"
[k-list ^String divider ^String str-name] [args divider]
(symbol (str main-package "." (join-keys k-list) divider str-name))) (let [[a1 a2] (take-last 2 args)]
(conj (vec (drop-last 2 args)) (str (name a1) divider a2))))
(defmacro static-upper (defn gdx
"Returns a fully-qualified static method or field whose last item is formatted "Returns a fully-qualified LibGDX symbol"
in upper case"
[& args] [& args]
`~(static-symbol (butlast args) "/" (key->upper (last args)))) (symbol (str main-package "." (join-keys args))))
(defmacro static-pascal (defn gdx-field
"Returns a fully-qualified static method or field whose last item is formatted "Returns a fully-qualified LibGDX static method or field"
in pascal case"
[& args] [& args]
`~(static-symbol (butlast args) "/" (key->pascal (last args)))) (apply gdx (add-divider args "/")))
(defmacro static-camel (defn gdx-class
"Returns a fully-qualified static method or field whose last item is formatted "Returns a fully-qualified LibGDX static class"
in camel case"
[& args] [& args]
`~(static-symbol (butlast args) "/" (key->camel (last args)))) (apply gdx (add-divider args "$")))
(defmacro static-class
"Returns a fully-qualified static class whose last item is formatted in
pascal case"
[& args]
`~(static-symbol (butlast args) "$" (key->pascal (last args))))
(defmacro scaling (defmacro scaling
"Returns a static field from [Scaling](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/utils/Scaling.html) "Returns a static field from [Scaling](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/utils/Scaling.html)
@@ -106,7 +98,7 @@ pascal case"
(scaling :stretch-x) (scaling :stretch-x)
(scaling :stretch-y)" (scaling :stretch-y)"
[k] [k]
`(static-camcel :utils :Scaling ~k)) `~(gdx-field :utils :Scaling k))
; java interop ; java interop