From 5ecdf787b758441d28f0aebbfdc6739b01e57d10 Mon Sep 17 00:00:00 2001 From: oakes Date: Wed, 29 Jan 2014 04:21:49 -0500 Subject: [PATCH] Add attribute-type and other changes --- src/play_clj/g3d.clj | 66 +++++++++++++++++++----------------------- src/play_clj/ui.clj | 2 +- src/play_clj/utils.clj | 20 ++++++++----- 3 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/play_clj/g3d.clj b/src/play_clj/g3d.clj index 13e563c..d9d355a 100644 --- a/src/play_clj/g3d.clj +++ b/src/play_clj/g3d.clj @@ -44,36 +44,20 @@ (u/calls! object# ~@options))) (defmacro model-batch! - "Calls a single method on an `model-batch`" + "Calls a single method on a `model-batch`" [screen k & options] `(let [^ModelBatch object# (u/get-obj ~screen :renderer)] (u/call! object# ~k ~@options))) ; model -(defn model* - "The function version of `model`" - ([a1] - (u/create-entity (ModelInstance. (if (map? a1) (:object a1) a1)))) - ([a1 a2] - (u/create-entity (ModelInstance. a1 a2))) - ([a1 a2 a3] - (u/create-entity (ModelInstance. a1 a2 a3))) - ([a1 a2 a3 a4] - (u/create-entity (ModelInstance. a1 a2 a3 a4))) - ([a1 a2 a3 a4 a5] - (u/create-entity (ModelInstance. a1 a2 a3 a4 a5))) - ([a1 a2 a3 a4 a5 a6] - (u/create-entity (ModelInstance. a1 a2 a3 a4 a5 a6)))) - (defmacro model "Returns an entity based on [ModelInstance](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/ModelInstance.html)" - [& options] - `(let [^ModelInstance object# (model*)] - (u/calls! object# ~@options))) + [& args] + `(ModelInstance. ~@args)) (defmacro model! - "Calls a single method on an `model`" + "Calls a single method on a `model`" [entity k & options] `(let [^ModelInstance object# (u/get-obj ~entity :object)] (u/call! object# ~k ~@options))) @@ -94,10 +78,9 @@ (u/calls! object# ~@options))) (defmacro model-builder! - "Calls a single method on an `model-builder`" + "Calls a single method on a `model-builder`" [object k & options] - `(let [^ModelBuilder object# object] - (u/call! object# ~k ~@options))) + `(u/call! ^ModelBuilder ~object ~k ~@options)) ; material @@ -109,33 +92,44 @@ `(Material. ~@args)) (defmacro material! - "Calls a single method on an `material`" + "Calls a single method on a `material`" [object k & options] - `(let [^Material object# object] - (u/call! object# ~k ~@options))) + `(u/call! ^Material ~object ~k ~@options)) ; attribute -(defmacro ^:private attribute-type +(defmacro ^:private attribute-init "Internal use only" [k] - `(symbol (str u/main-package ".graphics.g3d." - (u/key->pascal ~k) "Attribute"))) + `(symbol (str u/main-package ".graphics.g3d.attributes." + (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)" + (attribute :color (attribute-type :color :diffuse) (color :blue))" [type & args] - `(~(attribute-type type) ~@args)) + `(~(attribute-init type) ~@args)) + +(defmacro attribute-type + "Returns a static field in a subclass of [Attribute](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/Attribute.html) + + (attribute-type :color :diffuse)" + [type k] + `(u/static-pascal :graphics + :g3d + :attributes + ~(str (u/key->pascal type) "Attribute") + ~k)) (defmacro attribute! - "Calls a single method on [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)" + (attribute! :color :create-diffuse (color :blue)" [type k & options] `((u/static-camel :graphics - :g2d - (str (u/key->pascal type) "Attribute") - k) + :g3d + :attributes + ~(str (u/key->pascal type) "Attribute") + ~k) ~@options)) diff --git a/src/play_clj/ui.clj b/src/play_clj/ui.clj index b96a300..08eb4a1 100644 --- a/src/play_clj/ui.clj +++ b/src/play_clj/ui.clj @@ -45,7 +45,7 @@ based on the file at `path` (align :center)" [k] - `(u/static-lower :scenes :scene2d :utils :Align ~k)) + `(u/static-camel :scenes :scene2d :utils :Align ~k)) (defn cell! "Calls a single method on a [Cell](https://github.com/libgdx/libgdx/blob/master/gdx/src/com/esotericsoftware/tablelayout/Cell.java) diff --git a/src/play_clj/utils.clj b/src/play_clj/utils.clj index 9f5941b..f10f8cd 100644 --- a/src/play_clj/utils.clj +++ b/src/play_clj/utils.clj @@ -70,18 +70,24 @@ [k-list ^String divider ^String str-name] (symbol (str main-package "." (join-keys k-list) divider str-name))) -(defmacro static-camel - "Returns a fully-qualified static method or field whose last item is formatted -in camel case" - [& args] - `~(static-symbol (butlast args) "/" (key->camel (last args)))) - (defmacro static-upper "Returns a fully-qualified static method or field whose last item is formatted in upper case" [& args] `~(static-symbol (butlast args) "/" (key->upper (last args)))) +(defmacro static-pascal + "Returns a fully-qualified static method or field whose last item is formatted +in pascal case" + [& args] + `~(static-symbol (butlast args) "/" (key->pascal (last args)))) + +(defmacro static-camel + "Returns a fully-qualified static method or field whose last item is formatted +in camel case" + [& 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" @@ -100,7 +106,7 @@ pascal case" (scaling :stretch-x) (scaling :stretch-y)" [k] - `(static-lower :utils :Scaling ~k)) + `(static-camcel :utils :Scaling ~k)) ; java interop