diff --git a/src/play_clj/core_global.clj b/src/play_clj/core_global.clj index 64c9e78..399967b 100644 --- a/src/play_clj/core_global.clj +++ b/src/play_clj/core_global.clj @@ -99,7 +99,7 @@ (key-code :a) (key-code :page-down)" [k] - `~(symbol (str u/main-package ".Input$Keys/" (u/key->upper k)))) + `~(u/static-upper "Input$Keys" k)) (defmacro is-pressed? "Returns a boolean indicating if the key cooresponding to `k` is being pressed diff --git a/src/play_clj/g3d.clj b/src/play_clj/g3d.clj index c2b3a0d..13e563c 100644 --- a/src/play_clj/g3d.clj +++ b/src/play_clj/g3d.clj @@ -1,7 +1,10 @@ (ns play-clj.g3d (:require [play-clj.utils :as u]) - (:import [com.badlogic.gdx.graphics.g3d Environment Model ModelBatch + (:import [com.badlogic.gdx.graphics.g3d Environment Material Model ModelBatch ModelInstance] + [com.badlogic.gdx.graphics.g3d.attributes BlendingAttribute + ColorAttribute CubemapAttribute DepthTestAttribute FloatAttribute + IntAttribute TextureAttribute] [com.badlogic.gdx.graphics.g3d.utils ModelBuilder])) ; environment @@ -95,3 +98,44 @@ [object k & options] `(let [^ModelBuilder object# object] (u/call! object# ~k ~@options))) + +; material + +(defmacro material + "Returns a [Material](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/Material.html) + + (material)" + [& args] + `(Material. ~@args)) + +(defmacro material! + "Calls a single method on an `material`" + [object k & options] + `(let [^Material object# object] + (u/call! object# ~k ~@options))) + +; attribute + +(defmacro ^:private attribute-type + "Internal use only" + [k] + `(symbol (str u/main-package ".graphics.g3d." + (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) + + (attribute :color)" + [type & args] + `(~(attribute-type type) ~@args)) + +(defmacro attribute! + "Calls a single method on [Attribute](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/Attribute.html) + + (attribute! :color)" + [type k & options] + `((u/static-camel :graphics + :g2d + (str (u/key->pascal type) "Attribute") + k) + ~@options)) diff --git a/src/play_clj/math.clj b/src/play_clj/math.clj index 8d73202..00ae185 100644 --- a/src/play_clj/math.clj +++ b/src/play_clj/math.clj @@ -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-symbol [:math :GeometryUtils k] u/key->camel) ~@options)) + `(~(u/static-camel :math :GeometryUtils 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] - `~(symbol (str u/main-package ".math.Interpolation$" (u/key->pascal k)))) + `~(static-class :math :Interpolation 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-symbol [:math :Intersector k] u/key->camel) ~@options)) + `(~(u/static-camel :math :Intersector 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-symbol [:math :MathUtils k] u/key->camel) ~@options)) + `(~(u/static-camel :math :MathUtils 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] - `~(symbol (str u/main-package ".math.Plane$PlaneSide/" (u/key->pascal k)))) + `~(u/static-class :math :Plane (str "PlaneSide/" (u/key->pascal k)))) ; bezier diff --git a/src/play_clj/utils.clj b/src/play_clj/utils.clj index 7e91c50..c47ebf3 100644 --- a/src/play_clj/utils.clj +++ b/src/play_clj/utils.clj @@ -33,7 +33,7 @@ (defn ^:private join-keys "Internal use only" [k-list] - (->> k-list (map name) (s/join ".") (str main-package "."))) + (->> k-list (map name) (s/join "."))) (defn key->upper "Returns a string based on keyword `k` with upper case and underscores" @@ -66,24 +66,27 @@ ; static methods/fields (defn static-symbol - "Returns a fully-qualified static method or field based on `args` whose last -item is formatted with `transform-fn`" - [args transform-fn] - (->> (transform-fn (last args)) - (str (join-keys (butlast args)) "/") - 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))) -(defmacro static-field-lower +(defmacro static-camel "Returns a fully-qualified static method or field whose last item is formatted in camel case" [& args] - `~(static-symbol args key->camel)) + `~(static-symbol (butlast args) "/" (key->camel (last args)))) -(defmacro static-field-upper +(defmacro static-upper "Returns a fully-qualified static method or field whose last item is formatted in upper case" [& args] - `~(static-symbol args key->upper)) + `~(static-symbol (butlast args) "/" (key->upper (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)))) (defmacro scaling "Returns a static field from [Scaling](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/utils/Scaling.html)