Improve key transform functions and add scaling macro

This commit is contained in:
oakes
2014-01-12 00:32:33 -05:00
parent 1509726492
commit 489ffe0c0f
4 changed files with 31 additions and 21 deletions

View File

@@ -86,3 +86,7 @@
(texture* (.getKeyFrame animation total-time true))) (texture* (.getKeyFrame animation total-time true)))
([{:keys [total-time]} ^Animation animation is-looping?] ([{:keys [total-time]} ^Animation animation is-looping?]
(texture* (.getKeyFrame animation total-time is-looping?)))) (texture* (.getKeyFrame animation total-time is-looping?))))
(defmacro scaling
[key]
`(u/static-field-lower :utils :Scaling ~key))

View File

@@ -62,7 +62,7 @@
(defmacro key-code (defmacro key-code
[key] [key]
`~(symbol (str u/main-package ".Input$Keys/" (u/key->static-field key true)))) `~(symbol (str u/main-package ".Input$Keys/" (u/key->upper key))))
(defmacro is-pressed? (defmacro is-pressed?
[key] [key]

View File

@@ -15,7 +15,7 @@
(defmacro drawable (defmacro drawable
[type & options] [type & options]
`(~(symbol (str u/main-package ".scenes.scene2d.u." `(~(symbol (str u/main-package ".scenes.scene2d.u."
(u/key->class type) "Drawable.")) (u/key->pascal type) "Drawable."))
~@options)) ~@options))
(defmacro bitmap-font (defmacro bitmap-font
@@ -25,8 +25,8 @@
(defmacro style (defmacro style
[type & options] [type & options]
`(~(symbol (str u/main-package ".scenes.scene2d.ui." `(~(symbol (str u/main-package ".scenes.scene2d.ui."
(u/key->class type) "$" (u/key->pascal type) "$"
(u/key->class type) "Style.")) (u/key->pascal type) "Style."))
~@options)) ~@options))
(defmacro skin (defmacro skin
@@ -47,7 +47,13 @@
(defmethod add-to-group! Table (defmethod add-to-group! Table
[[{:keys [^Table object]} children]] [[{:keys [^Table object]} children]]
(doseq [child children] (doseq [child children]
(.add object ^Actor (:object child)))) (cond
(map? child)
(.add object ^Actor (:object child))
(keyword? child)
(case child
:row (.row object)
nil))))
(defn add! (defn add!
[group children] [group children]

View File

@@ -14,43 +14,43 @@
[keys] [keys]
(->> keys (map name) (s/join ".") (str main-package "."))) (->> keys (map name) (s/join ".") (str main-package ".")))
(defn key->static-field (defn key->upper
[key upper?] [key]
(->> (split-key key) (->> (split-key key)
(map (if upper? s/upper-case s/lower-case)) (map s/upper-case)
(s/join "_") (s/join "_")))
symbol))
(defn key->class (defn key->pascal
[key] [key]
(->> (split-key key) (->> (split-key key)
(map s/capitalize) (map s/capitalize)
(s/join "") (s/join "")))
symbol))
(defn key->method (defn key->camel
[key] [key]
(let [parts (split-key key)] (let [parts (split-key key)]
(->> (rest parts) (->> (rest parts)
(map s/capitalize) (map s/capitalize)
(cons (first parts)) (cons (first parts))
(s/join "") (s/join ""))))
(str ".")
symbol))) (defn key->method
[key]
(symbol (str "." (key->camel key))))
(defn ^:private static-field (defn ^:private static-field
[args upper?] [args transform-fn]
(->> (key->static-field (last args) upper?) (->> (transform-fn (last args))
(str (join-keys (butlast args)) "/") (str (join-keys (butlast args)) "/")
symbol)) symbol))
(defmacro static-field-lower (defmacro static-field-lower
[& args] [& args]
`~(static-field args false)) `~(static-field args key->camel))
(defmacro static-field-upper (defmacro static-field-upper
[& args] [& args]
`~(static-field args true)) `~(static-field args key->upper))
(defn convert-array (defn convert-array
[a] [a]