Merge branch 'master' of github.com:brycecovert/play-clj

This commit is contained in:
=
2014-09-10 14:31:25 -07:00
11 changed files with 43 additions and 32 deletions

View File

@@ -1,6 +1,6 @@
## Introduction ## Introduction
A Clojure library that provides a wrapper for [libGDX](http://libgdx.badlogicgames.com/), allowing you to write 2D and 3D games that run on desktop OSes (Windows, OS X, and Linux) and mobile OSes (Android and iOS) with the same Clojure codebase. A Clojure library that provides a wrapper for [libGDX](http://libgdx.badlogicgames.com/), allowing you to write 2D and 3D games that run on desktop OSes (Windows, OS X, and Linux) and mobile OSes (Android and iOS) with the same Clojure codebase. The mobile support is currently experimental, and may have poor performance or even fail to run on some devices.
## Getting Started ## Getting Started

View File

@@ -345,12 +345,12 @@ Then, in `defgame`, set the screens in the order in which you'd like them to app
Make sure you add `play-clj.ui` back to your `ns` declaration, so you can use the label again. Also, note that only the first screen, which in this case is `main-screen`, calls `(clear!)` in its `:on-render` function. If `text-screen` called it as well, it would clear whatever was drawn by `main-screen`. Make sure you add `play-clj.ui` back to your `ns` declaration, so you can use the label again. Also, note that only the first screen, which in this case is `main-screen`, calls `(clear!)` in its `:on-render` function. If `text-screen` called it as well, it would clear whatever was drawn by `main-screen`.
With multiple screens being displayed, it will often be important to make them interact. For example, you may want to place a button on `text-screen` that causes a character on `main-screen` to change color. You can do this with the [run!](http://oakes.github.io/play-clj/core.run!.html) function. With multiple screens being displayed, it will often be important to make them interact. For example, you may want to place a button on `text-screen` that causes a character on `main-screen` to change color. You can do this with the [screen!](http://oakes.github.io/play-clj/core.screen!.html) function.
First, define a custom screen function in `main-screen` with a name such as `:on-change-color`, where you can write the code that changes the character's color. Then, in `text-screen`, listen for the button click (using the `:on-ui-changed` screen function) and manually run the custom function. You may optionally provide key-value pairs that will be passed into its screen map: First, define a custom screen function in `main-screen` with a name such as `:on-change-color`, where you can write the code that changes the character's color. Then, in `text-screen`, listen for the button click (using the `:on-ui-changed` screen function) and manually run the custom function. You may optionally provide key-value pairs that will be passed into its screen map:
```clojure ```clojure
(run! main-screen :on-change-color :color :blue) (screen! main-screen :on-change-color :color :blue)
``` ```
## Using the REPL ## Using the REPL

View File

@@ -142,9 +142,8 @@
(remove nil?))) (remove nil?)))
(defn parse-clj (defn parse-clj
[java-docs] [java-docs files]
(->> (io/file "../src/") (->> files
file-seq
(filter #(-> % .getName (.endsWith ".clj"))) (filter #(-> % .getName (.endsWith ".clj")))
(remove #(contains? ignore-files (.getName %))) (remove #(contains? ignore-files (.getName %)))
(sort-by #(.getName %)) (sort-by #(.getName %))
@@ -155,18 +154,25 @@
(group-by :ns) (group-by :ns)
(into (sorted-map)))) (into (sorted-map))))
(defn save! (defn generate!
[parsed-files] [java-docs]
(html/create-site! "site" parsed-files) (let [play-clj-files (file-seq (io/file "../src/"))
(html/create-embed! "embed" parsed-files) nightmod-file (io/file "../../nightmod/src/clojure/nightmod/game.clj")
(println "Created site/ and embed/")) net-file (io/file "../../play-clj.net/src/play_clj/net.clj")]
(->> play-clj-files
(parse-clj java-docs)
(html/create-site! "site"))
(when (and (.exists nightmod-file) (.exists net-file))
(->> play-clj-files
(concat [nightmod-file net-file])
(parse-clj java-docs)
(html/create-embed! "embed")))))
(defn parse (defn generate-all!
[^RootDoc root] [^RootDoc root]
(if (= 0 (count (.classes root))) (if (= 0 (count (.classes root)))
(println "No Java classes found") (println "No Java classes found")
(->> (map parse-class (.classes root)) (->> (map parse-class (.classes root))
(filter some?) (filter some?)
(apply concat) (apply concat)
parse-clj generate!)))
save!)))

View File

@@ -94,7 +94,8 @@
(spit (io/file dir (str->filename ns name)) (spit (io/file dir (str->filename ns name))
(create-site-file name (sidebar parsed-files) (content group))))) (create-site-file name (sidebar parsed-files) (content group)))))
(spit (io/file dir "index.html") (spit (io/file dir "index.html")
(create-site-file "play-clj docs" (sidebar parsed-files) nil))) (create-site-file "play-clj docs" (sidebar parsed-files) nil))
(println "Created" (str dir "/")))
(defn create-embed! (defn create-embed!
[dir parsed-files] [dir parsed-files]
@@ -112,4 +113,5 @@
:file (str->filename ns name)}))) :file (str->filename ns name)})))
(apply concat) (apply concat)
vec vec
pr-str))) pr-str))
(println "Created" (str dir "/")))

View File

@@ -9,8 +9,8 @@ import com.sun.javadoc.*;
public class Start { public class Start {
public static boolean start(RootDoc root) { public static boolean start(RootDoc root) {
RT.var("clojure.core", "require").invoke(Symbol.intern("play-clj-doclet.core")); RT.var("clojure.core", "require").invoke(Symbol.intern("play-clj-doclet.core"));
Var parse = RT.var("play-clj-doclet.core", "parse"); Var generate = RT.var("play-clj-doclet.core", "generate-all!");
parse.invoke(root); generate.invoke(root);
return true; return true;
} }
} }

View File

@@ -1,4 +1,4 @@
(defproject play-clj "0.3.11-SNAPSHOT" (defproject play-clj "0.3.12-SNAPSHOT"
:description "A libGDX wrapper for easy cross-platform game development" :description "A libGDX wrapper for easy cross-platform game development"
:url "https://github.com/oakes/play-clj" :url "https://github.com/oakes/play-clj"
:license {:name "Public Domain" :license {:name "Public Domain"

View File

@@ -63,8 +63,7 @@
(defn defscreen* (defn defscreen*
[screen entities [screen entities
{:keys [on-show on-render on-hide on-pause {:keys [on-show on-render on-hide on-pause on-resize on-resume on-timer]
on-resize on-resume on-dispose on-timer]
:as options}] :as options}]
(let [execute-fn! (fn [func & {:keys [] :as options}] (let [execute-fn! (fn [func & {:keys [] :as options}]
(when func (when func
@@ -99,6 +98,7 @@
:update-fn! update-fn! :update-fn! update-fn!
:options options :options options
:on-timer on-timer :on-timer on-timer
:layers nil
:input-listeners (input-listeners options execute-fn!) :input-listeners (input-listeners options execute-fn!)
:ui-listeners (ui-listeners options execute-fn!)]) :ui-listeners (ui-listeners options execute-fn!)])
; run :on-show ; run :on-show
@@ -115,8 +115,7 @@
:resize (fn [w h] :resize (fn [w h]
(execute-fn! on-resize :width w :height h) (execute-fn! on-resize :width w :height h)
(update-screen! @screen)) (update-screen! @screen))
:resume #(execute-fn! on-resume) :resume #(execute-fn! on-resume)}))
:dispose #(execute-fn! on-dispose)}))
(defmacro defscreen (defmacro defscreen
"Defines a screen, and creates vars for all the functions inside of it. All "Defines a screen, and creates vars for all the functions inside of it. All
@@ -512,7 +511,6 @@ keywords and functions in pairs."
(let [run-fn! (fn [k & args] (let [run-fn! (fn [k & args]
(doseq [screen screen-objects] (doseq [screen screen-objects]
(apply (get screen k) args)))] (apply (get screen k) args)))]
(some-> game-object .getScreen .dispose)
(.setScreen game-object (.setScreen game-object
(reify Screen (reify Screen
(show [this] (show [this]
@@ -526,7 +524,7 @@ keywords and functions in pairs."
(pause [this] (run-fn! :pause)) (pause [this] (run-fn! :pause))
(resize [this w h] (run-fn! :resize w h)) (resize [this w h] (run-fn! :resize w h))
(resume [this] (run-fn! :resume)) (resume [this] (run-fn! :resume))
(dispose [this] (run-fn! :dispose)))))) (dispose [this])))))
(defn set-screen-wrapper! (defn set-screen-wrapper!
"Sets a function that wraps around all screen functions, allowing you to "Sets a function that wraps around all screen functions, allowing you to
@@ -554,14 +552,19 @@ is the atom storing the screen map behind the scenes. Returns the updated
[screen & args] [screen & args]
((:update-fn! screen) assoc args)) ((:update-fn! screen) assoc args))
(defn run! (defn screen!
"Runs a function defined in another screen. You may optionally pass a series "Runs a function defined in another screen. You may optionally pass a series
of key-value pairs, which will be given to the function via its screen map. of key-value pairs, which will be given to the function via its screen map.
(run! my-other-screen :on-show) (screen! my-other-screen :on-show)
(run! my-other-screen :on-change-color :color :blue)" (screen! my-other-screen :on-change-color :color :blue)"
[screen-object fn-name & options] [screen-object fn-name & options]
(let [execute-fn! (:execute-fn! screen-object) (let [execute-fn! (:execute-fn! screen-object)
screen-fn (-> screen-object :options (get fn-name))] screen-fn (-> screen-object :options (get fn-name))]
(apply execute-fn! screen-fn options) (apply execute-fn! screen-fn options)
nil)) nil))
(defn run!
"Deprecated. Please use `screen!` instead."
[& args]
(apply screen! args))

View File

@@ -1,4 +1,4 @@
(defproject play-clj/lein-template "0.3.10" (defproject play-clj/lein-template "0.3.11.1"
:description "A template for making play-clj projects" :description "A template for making play-clj projects"
:url "https://github.com/oakes/play-clj" :url "https://github.com/oakes/play-clj"
:license {:name "Public Domain" :license {:name "Public Domain"

View File

@@ -7,7 +7,7 @@
[com.badlogicgames.gdx/gdx-bullet "1.3.1"] [com.badlogicgames.gdx/gdx-bullet "1.3.1"]
[neko/neko "3.0.2"] [neko/neko "3.0.2"]
[org.clojure-android/clojure "1.6.0-RC1" :use-resources true] [org.clojure-android/clojure "1.6.0-RC1" :use-resources true]
[play-clj "0.3.10"]] [play-clj "0.3.11"]]
:profiles {:dev {:dependencies [[android/tools.nrepl "0.2.0-bigstack"] :profiles {:dev {:dependencies [[android/tools.nrepl "0.2.0-bigstack"]
[compliment "0.1.3"]] [compliment "0.1.3"]]
:android {:aot :all-with-unused}} :android {:aot :all-with-unused}}

View File

@@ -12,7 +12,7 @@
[com.badlogicgames.gdx/gdx-platform "1.3.1" [com.badlogicgames.gdx/gdx-platform "1.3.1"
:classifier "natives-desktop"] :classifier "natives-desktop"]
[org.clojure/clojure "1.6.0"] [org.clojure/clojure "1.6.0"]
[play-clj "0.3.10"]] [play-clj "0.3.11"]]
:source-paths ["src" "src-common"] :source-paths ["src" "src-common"]
:javac-options ["-target" "1.6" "-source" "1.6" "-Xlint:-options"] :javac-options ["-target" "1.6" "-source" "1.6" "-Xlint:-options"]

View File

@@ -5,7 +5,7 @@
[com.badlogicgames.gdx/gdx-box2d "1.3.1"] [com.badlogicgames.gdx/gdx-box2d "1.3.1"]
[com.badlogicgames.gdx/gdx-bullet "1.3.1"] [com.badlogicgames.gdx/gdx-bullet "1.3.1"]
[org.clojure/clojure "1.6.0"] [org.clojure/clojure "1.6.0"]
[play-clj "0.3.10"]] [play-clj "0.3.11"]]
:source-paths ["src/clojure" "../desktop/src-common"] :source-paths ["src/clojure" "../desktop/src-common"]
:java-source-paths ["src/java"] :java-source-paths ["src/java"]
:javac-options ["-target" "1.7" "-source" "1.7" "-Xlint:-options"] :javac-options ["-target" "1.7" "-source" "1.7" "-Xlint:-options"]