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)"
[& 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)))
; interop
@@ -99,7 +100,7 @@
(key-code :a)
(key-code :page-down)"
[k]
`(u/static-upper "Input$Keys" ~k))
`~(u/gdx-field "Input$Keys" (u/key->upper k)))
(defmacro is-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 :normal)
(play-mode :reversed)"
[key]
`(u/static-upper :graphics :g2d :Animation ~key))
[k]
`~(u/gdx-field :graphics :g2d :Animation (u/key->upper k)))
(defn animation*
"The function version of `animation`"

View File

@@ -32,11 +32,11 @@
; bodies
(defmacro ^:private body-type
(defn ^:private body-type
"Internal use only"
[k]
`(symbol (str u/main-package ".physics.box2d.BodyDef$BodyType/"
(u/key->pascal ~k) "Body")))
(u/gdx-class :physics :box2d :BodyDef
(str "BodyType/" (u/key->pascal k) "Body")))
(defmacro body-def
"Returns a [BodyDef](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/physics/box2d/BodyDef.html)
@@ -102,11 +102,10 @@
; joints
(defmacro ^:private joint-init
(defn ^:private joint-init
"Internal use only"
[k]
`(symbol (str u/main-package ".physics.box2d.joints."
(u/key->pascal ~k) "JointDef.")))
(u/gdx :physics :box2d :joints (str (u/key->pascal k) "JointDef.")))
(defmacro joint-def
"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
(defmacro ^:private attribute-init
(defn ^:private attribute-init
"Internal use only"
[k]
`(symbol (str u/main-package ".graphics.g3d.attributes."
(u/key->pascal ~k) "Attribute.")))
(u/gdx :graphics :g3d :attributes (str (u/key->pascal k) "Attribute.")))
(defmacro attribute
"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)"
[type k]
`(u/static-pascal :graphics
:g3d
:attributes
~(str (u/key->pascal type) "Attribute")
~k))
`~(u/gdx-field :graphics :g3d :attributes
(str (u/key->pascal type) "Attribute")
(u/key->pascal k)))
(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)
(attribute! :color :create-diffuse (color :blue)"
(attribute! :color :create-diffuse (color :blue))"
[type k & options]
`((u/static-camel :graphics
:g3d
:attributes
~(str (u/key->pascal type) "Attribute")
~k)
`(~(u/gdx-field :graphics :g3d :attributes
(str (u/key->pascal type) "Attribute")
(u/key->camel k))
~@options))

View File

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

View File

@@ -18,8 +18,8 @@
(drawable :texture-region)"
[k & options]
`(~(symbol (str u/main-package ".scenes.scene2d.utils."
(u/key->pascal k) "Drawable."))
`(~(u/gdx :scenes :scene2d :utils
(str (u/key->pascal k) "Drawable."))
~@options))
(defmacro style
@@ -27,9 +27,9 @@
(style :check-box)"
[k & options]
`(~(symbol (str u/main-package ".scenes.scene2d.ui."
(u/key->pascal k) "$"
(u/key->pascal k) "Style."))
`(~(u/gdx-class :scenes :scene2d :ui
(u/key->pascal k)
(str (u/key->pascal k) "Style."))
~@options))
(defmacro skin
@@ -45,7 +45,7 @@ based on the file at `path`
(align :center)"
[k]
`(u/static-camel :scenes :scene2d :utils :Align ~k))
`~(u/gdx-field :scenes :scene2d :utils :Align (u/key->camel k)))
(defn cell!
"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]
(symbol (str "." (key->camel k))))
; static methods/fields
; classes/methods/fields
(defn static-symbol
"Returns a fully-qualified static method or field"
[k-list ^String divider ^String str-name]
(symbol (str main-package "." (join-keys k-list) divider str-name)))
(defn ^:private add-divider
"Internal use only"
[args divider]
(let [[a1 a2] (take-last 2 args)]
(conj (vec (drop-last 2 args)) (str (name a1) divider a2))))
(defmacro static-upper
"Returns a fully-qualified static method or field whose last item is formatted
in upper case"
(defn gdx
"Returns a fully-qualified LibGDX symbol"
[& args]
`~(static-symbol (butlast args) "/" (key->upper (last args))))
(symbol (str main-package "." (join-keys args))))
(defmacro static-pascal
"Returns a fully-qualified static method or field whose last item is formatted
in pascal case"
(defn gdx-field
"Returns a fully-qualified LibGDX static method or field"
[& args]
`~(static-symbol (butlast args) "/" (key->pascal (last args))))
(apply gdx (add-divider args "/")))
(defmacro static-camel
"Returns a fully-qualified static method or field whose last item is formatted
in camel case"
(defn gdx-class
"Returns a fully-qualified LibGDX static class"
[& args]
`~(static-symbol (butlast args) "/" (key->camel (last 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))))
(apply gdx (add-divider args "$")))
(defmacro scaling
"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-y)"
[k]
`(static-camcel :utils :Scaling ~k))
`~(gdx-field :utils :Scaling k))
; java interop