Start work on docstrings

This commit is contained in:
oakes
2014-01-19 22:02:30 -05:00
parent 265ee56228
commit f7664fdce7
3 changed files with 83 additions and 1 deletions

View File

@@ -4,4 +4,5 @@
:license {:name "Public Domain" :license {:name "Public Domain"
:url "http://unlicense.org/UNLICENSE"} :url "http://unlicense.org/UNLICENSE"}
:dependencies [[com.badlogicgames.gdx/gdx "0.9.9"] :dependencies [[com.badlogicgames.gdx/gdx "0.9.9"]
[org.clojure/clojure "1.5.1"]]) [org.clojure/clojure "1.5.1"]]
:plugins [[lein-marginalia "0.7.1"]])

View File

@@ -26,11 +26,13 @@
(load "core_listeners") (load "core_listeners")
(defn ^:private reset-changed! (defn ^:private reset-changed!
"Internal use only"
[e-atom e-old e-new] [e-atom e-old e-new]
(when (not= e-old e-new) (when (not= e-old e-new)
(compare-and-set! e-atom e-old e-new))) (compare-and-set! e-atom e-old e-new)))
(defn defscreen* (defn defscreen*
"Internal use only"
[{:keys [on-show on-render on-hide on-pause on-resize on-resume] [{:keys [on-show on-render on-hide on-pause on-resize on-resume]
:as options}] :as options}]
(let [screen (atom {}) (let [screen (atom {})
@@ -68,6 +70,20 @@
:input-listeners (global-listeners options execute-fn!)})) :input-listeners (global-listeners options execute-fn!)}))
(defmacro defscreen (defmacro defscreen
"Creates vars for all the anonymous functions provided to it, so they can be
replaced by simply reloading the namespace, and creates a var for the symbol `n`
bound to a map containing various important values related to the screen
(defscreen text-screen
:on-show
(fn [screen entities]
(update! screen :renderer (stage))
(label \"Hello world!\" (color :white)))
:on-render
(fn [screen entities]
(clear!)
(render! screen entities)))
"
[n & {:keys [] :as options}] [n & {:keys [] :as options}]
`(let [fns# (->> (for [[k# v#] ~options] `(let [fns# (->> (for [[k# v#] ~options]
[k# (intern *ns* (symbol (str '~n "-" (name k#))) v#)]) [k# (intern *ns* (symbol (str '~n "-" (name k#))) v#)])
@@ -76,16 +92,30 @@
(defonce ~n (defscreen* fns#)))) (defonce ~n (defscreen* fns#))))
(defn defgame* (defn defgame*
"Internal use only"
[{:keys [on-create]}] [{:keys [on-create]}]
(proxy [Game] [] (proxy [Game] []
(create [] (create []
(when on-create (on-create this))))) (when on-create (on-create this)))))
(defmacro defgame (defmacro defgame
"Creates a var for the symbol `n` bound to a [Game](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/Game.html)
object
(defgame hello-world
:on-create
(fn [this]
(set-screen! this main-screen)))"
[n & {:keys [] :as options}] [n & {:keys [] :as options}]
`(defonce ~n (defgame* ~options))) `(defonce ~n (defgame* ~options)))
(defn set-screen! (defn set-screen!
"Creates a [Screen](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/Screen.html)
object, sets it as the screen for the `game`, and runs the functions from
`screens` in the order they are provided in
(set-screen! hello-world main-screen)
"
[^Game game & screens] [^Game game & screens]
(let [add-inputs! (fn [] (let [add-inputs! (fn []
(input! :set-input-processor (InputMultiplexer.)) (input! :set-input-processor (InputMultiplexer.))
@@ -105,5 +135,10 @@
(dispose [this]))))) (dispose [this])))))
(defn update! (defn update!
"Runs the equivalent of `(swap! screen-atom assoc ...)`, where `screen-atom`
is the atom storing the screen map behind the scenes
(update! screen :renderer (stage))
"
[{:keys [update-fn!]} & {:keys [] :as args}] [{:keys [update-fn!]} & {:keys [] :as args}]
(update-fn! args)) (update-fn! args))

View File

@@ -4,10 +4,16 @@
[com.badlogic.gdx.graphics.g2d Animation BitmapFont TextureRegion])) [com.badlogic.gdx.graphics.g2d Animation BitmapFont TextureRegion]))
(defmacro bitmap-font (defmacro bitmap-font
"Returns a [BitmapFont](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/BitmapFont.html)
(bitmap-font)
(bitmap-font file-handle region)
"
[& options] [& options]
`(BitmapFont. ~@options)) `(BitmapFont. ~@options))
(defn texture* (defn texture*
"The function version of `texture`"
[arg] [arg]
(u/create-entity (u/create-entity
(cond (cond
@@ -19,34 +25,74 @@
arg))) arg)))
(defmacro texture (defmacro texture
"Returns an entity based on [TextureRegion](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/TextureRegion.html)
(texture \"image.png\")
(texture \"image.png\" :flip true false)
(texture \"image.png\"
:flip true false
:set-region 0 0 100 100)
"
[arg & options] [arg & options]
`(let [entity# (texture* ~arg)] `(let [entity# (texture* ~arg)]
(u/calls! ^TextureRegion (u/get-obj entity# :object) ~@options) (u/calls! ^TextureRegion (u/get-obj entity# :object) ~@options)
entity#)) entity#))
(defmacro texture! (defmacro texture!
"Calls a single method on a `texture` entity, returning whatever the method
itself does
(texture! entity :flip true false)
(texture! entity :get-region-width)
"
[entity k & options] [entity k & options]
`(u/call! ^TextureRegion (u/get-obj ~entity :object) ~k ~@options)) `(u/call! ^TextureRegion (u/get-obj ~entity :object) ~k ~@options))
(defmacro play-mode (defmacro play-mode
"Returns a static field from [Animation](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/Animation.html)
(play-mode :loop)
(play-mode :loop-pingpong)
(play-mode :loop-random)
(play-mode :loop-reversed)
(play-mode :normal)
(play-mode :reversed)
"
[key] [key]
`(u/static-field-upper :graphics :g2d :Animation ~key)) `(u/static-field-upper :graphics :g2d :Animation ~key))
(defn animation* (defn animation*
"The function version of `animation`"
[duration textures] [duration textures]
(Animation. duration (Animation. duration
(u/gdx-array (map #(u/get-obj % :object) textures)) (u/gdx-array (map #(u/get-obj % :object) textures))
(play-mode :normal))) (play-mode :normal)))
(defmacro animation (defmacro animation
"Returns an [Animation](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/Animation.html) object
(animation 0.2
[walk-1 walk-2 walk-3]
:set-play-mode (play-mode :loop-pingpong))
"
[duration textures & options] [duration textures & options]
`(u/calls! ^Animation (animation* ~duration ~textures) ~@options)) `(u/calls! ^Animation (animation* ~duration ~textures) ~@options))
(defmacro animation! (defmacro animation!
"Calls a single method on an `animation` object, returning whatever the method
itself does
(animation! object :set-play-mode (play-mode :loop))
"
[object k & options] [object k & options]
`(u/call! ^Animation ~object ~k ~@options)) `(u/call! ^Animation ~object ~k ~@options))
(defn animation->texture (defn animation->texture
"Returns a `texture` entity with a frame from `animation` based on the total
time the `screen` has been showing
(animation->texture screen anim)
"
([{:keys [total-time]} ^Animation animation] ([{:keys [total-time]} ^Animation animation]
(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?]