Clean up static macros and add more to g3d
This commit is contained in:
@@ -99,7 +99,7 @@
|
|||||||
(key-code :a)
|
(key-code :a)
|
||||||
(key-code :page-down)"
|
(key-code :page-down)"
|
||||||
[k]
|
[k]
|
||||||
`~(symbol (str u/main-package ".Input$Keys/" (u/key->upper k))))
|
`~(u/static-upper "Input$Keys" 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
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
(ns play-clj.g3d
|
(ns play-clj.g3d
|
||||||
(:require [play-clj.utils :as u])
|
(: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]
|
ModelInstance]
|
||||||
|
[com.badlogic.gdx.graphics.g3d.attributes BlendingAttribute
|
||||||
|
ColorAttribute CubemapAttribute DepthTestAttribute FloatAttribute
|
||||||
|
IntAttribute TextureAttribute]
|
||||||
[com.badlogic.gdx.graphics.g3d.utils ModelBuilder]))
|
[com.badlogic.gdx.graphics.g3d.utils ModelBuilder]))
|
||||||
|
|
||||||
; environment
|
; environment
|
||||||
@@ -95,3 +98,44 @@
|
|||||||
[object k & options]
|
[object k & options]
|
||||||
`(let [^ModelBuilder object# object]
|
`(let [^ModelBuilder object# object]
|
||||||
(u/call! object# ~k ~@options)))
|
(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))
|
||||||
|
|||||||
@@ -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-symbol [:math :GeometryUtils k] u/key->camel) ~@options))
|
`(~(u/static-camel :math :GeometryUtils 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]
|
||||||
`~(symbol (str u/main-package ".math.Interpolation$" (u/key->pascal k))))
|
`~(static-class :math :Interpolation 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-symbol [:math :Intersector k] u/key->camel) ~@options))
|
`(~(u/static-camel :math :Intersector 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-symbol [:math :MathUtils k] u/key->camel) ~@options))
|
`(~(u/static-camel :math :MathUtils 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]
|
||||||
`~(symbol (str u/main-package ".math.Plane$PlaneSide/" (u/key->pascal k))))
|
`~(u/static-class :math :Plane (str "PlaneSide/" (u/key->pascal k))))
|
||||||
|
|
||||||
; bezier
|
; bezier
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
(defn ^:private join-keys
|
(defn ^:private join-keys
|
||||||
"Internal use only"
|
"Internal use only"
|
||||||
[k-list]
|
[k-list]
|
||||||
(->> k-list (map name) (s/join ".") (str main-package ".")))
|
(->> k-list (map name) (s/join ".")))
|
||||||
|
|
||||||
(defn key->upper
|
(defn key->upper
|
||||||
"Returns a string based on keyword `k` with upper case and underscores"
|
"Returns a string based on keyword `k` with upper case and underscores"
|
||||||
@@ -66,24 +66,27 @@
|
|||||||
; static methods/fields
|
; static methods/fields
|
||||||
|
|
||||||
(defn static-symbol
|
(defn static-symbol
|
||||||
"Returns a fully-qualified static method or field based on `args` whose last
|
"Returns a fully-qualified static method or field"
|
||||||
item is formatted with `transform-fn`"
|
[k-list ^String divider ^String str-name]
|
||||||
[args transform-fn]
|
(symbol (str main-package "." (join-keys k-list) divider str-name)))
|
||||||
(->> (transform-fn (last args))
|
|
||||||
(str (join-keys (butlast args)) "/")
|
|
||||||
symbol))
|
|
||||||
|
|
||||||
(defmacro static-field-lower
|
(defmacro static-camel
|
||||||
"Returns a fully-qualified static method or field whose last item is formatted
|
"Returns a fully-qualified static method or field whose last item is formatted
|
||||||
in camel case"
|
in camel case"
|
||||||
[& args]
|
[& 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
|
"Returns a fully-qualified static method or field whose last item is formatted
|
||||||
in upper case"
|
in upper case"
|
||||||
[& args]
|
[& 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
|
(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)
|
||||||
|
|||||||
Reference in New Issue
Block a user