diff --git a/README.md b/README.md index 1ff15dd..5bcd908 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## 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 diff --git a/TUTORIAL.md b/TUTORIAL.md index 7beb665..d9bbdbe 100644 --- a/TUTORIAL.md +++ b/TUTORIAL.md @@ -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`. -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: ```clojure -(run! main-screen :on-change-color :color :blue) +(screen! main-screen :on-change-color :color :blue) ``` ## Using the REPL diff --git a/doclet/src/clojure/play_clj_doclet/core.clj b/doclet/src/clojure/play_clj_doclet/core.clj index e0afe52..9c6b982 100644 --- a/doclet/src/clojure/play_clj_doclet/core.clj +++ b/doclet/src/clojure/play_clj_doclet/core.clj @@ -142,9 +142,8 @@ (remove nil?))) (defn parse-clj - [java-docs] - (->> (io/file "../src/") - file-seq + [java-docs files] + (->> files (filter #(-> % .getName (.endsWith ".clj"))) (remove #(contains? ignore-files (.getName %))) (sort-by #(.getName %)) @@ -155,18 +154,25 @@ (group-by :ns) (into (sorted-map)))) -(defn save! - [parsed-files] - (html/create-site! "site" parsed-files) - (html/create-embed! "embed" parsed-files) - (println "Created site/ and embed/")) +(defn generate! + [java-docs] + (let [play-clj-files (file-seq (io/file "../src/")) + nightmod-file (io/file "../../nightmod/src/clojure/nightmod/game.clj") + 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] (if (= 0 (count (.classes root))) (println "No Java classes found") (->> (map parse-class (.classes root)) (filter some?) (apply concat) - parse-clj - save!))) + generate!))) diff --git a/doclet/src/clojure/play_clj_doclet/html.clj b/doclet/src/clojure/play_clj_doclet/html.clj index 4923d1c..11fa3bf 100644 --- a/doclet/src/clojure/play_clj_doclet/html.clj +++ b/doclet/src/clojure/play_clj_doclet/html.clj @@ -94,7 +94,8 @@ (spit (io/file dir (str->filename ns name)) (create-site-file name (sidebar parsed-files) (content group))))) (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! [dir parsed-files] @@ -112,4 +113,5 @@ :file (str->filename ns name)}))) (apply concat) vec - pr-str))) + pr-str)) + (println "Created" (str dir "/"))) diff --git a/doclet/src/java/play_clj_doclet/core/Start.java b/doclet/src/java/play_clj_doclet/core/Start.java index 9d6e002..78defa3 100644 --- a/doclet/src/java/play_clj_doclet/core/Start.java +++ b/doclet/src/java/play_clj_doclet/core/Start.java @@ -9,8 +9,8 @@ import com.sun.javadoc.*; public class Start { public static boolean start(RootDoc root) { RT.var("clojure.core", "require").invoke(Symbol.intern("play-clj-doclet.core")); - Var parse = RT.var("play-clj-doclet.core", "parse"); - parse.invoke(root); + Var generate = RT.var("play-clj-doclet.core", "generate-all!"); + generate.invoke(root); return true; } } diff --git a/project.clj b/project.clj index f6e0f42..54a3268 100644 --- a/project.clj +++ b/project.clj @@ -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" :url "https://github.com/oakes/play-clj" :license {:name "Public Domain" diff --git a/src/play_clj/core.clj b/src/play_clj/core.clj index a2cf004..681bd37 100644 --- a/src/play_clj/core.clj +++ b/src/play_clj/core.clj @@ -63,8 +63,7 @@ (defn defscreen* [screen entities - {:keys [on-show on-render on-hide on-pause - on-resize on-resume on-dispose on-timer] + {:keys [on-show on-render on-hide on-pause on-resize on-resume on-timer] :as options}] (let [execute-fn! (fn [func & {:keys [] :as options}] (when func @@ -99,6 +98,7 @@ :update-fn! update-fn! :options options :on-timer on-timer + :layers nil :input-listeners (input-listeners options execute-fn!) :ui-listeners (ui-listeners options execute-fn!)]) ; run :on-show @@ -115,8 +115,7 @@ :resize (fn [w h] (execute-fn! on-resize :width w :height h) (update-screen! @screen)) - :resume #(execute-fn! on-resume) - :dispose #(execute-fn! on-dispose)})) + :resume #(execute-fn! on-resume)})) (defmacro defscreen "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] (doseq [screen screen-objects] (apply (get screen k) args)))] - (some-> game-object .getScreen .dispose) (.setScreen game-object (reify Screen (show [this] @@ -526,7 +524,7 @@ keywords and functions in pairs." (pause [this] (run-fn! :pause)) (resize [this w h] (run-fn! :resize w h)) (resume [this] (run-fn! :resume)) - (dispose [this] (run-fn! :dispose)))))) + (dispose [this]))))) (defn set-screen-wrapper! "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] ((:update-fn! screen) assoc args)) -(defn run! +(defn screen! "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. - (run! my-other-screen :on-show) - (run! my-other-screen :on-change-color :color :blue)" + (screen! my-other-screen :on-show) + (screen! my-other-screen :on-change-color :color :blue)" [screen-object fn-name & options] (let [execute-fn! (:execute-fn! screen-object) screen-fn (-> screen-object :options (get fn-name))] (apply execute-fn! screen-fn options) nil)) + +(defn run! + "Deprecated. Please use `screen!` instead." + [& args] + (apply screen! args)) diff --git a/template/project.clj b/template/project.clj index 173a763..170e499 100644 --- a/template/project.clj +++ b/template/project.clj @@ -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" :url "https://github.com/oakes/play-clj" :license {:name "Public Domain" diff --git a/template/src/leiningen/new/play_clj/android-project.clj b/template/src/leiningen/new/play_clj/android-project.clj index ea14bd6..da05fc4 100644 --- a/template/src/leiningen/new/play_clj/android-project.clj +++ b/template/src/leiningen/new/play_clj/android-project.clj @@ -7,7 +7,7 @@ [com.badlogicgames.gdx/gdx-bullet "1.3.1"] [neko/neko "3.0.2"] [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"] [compliment "0.1.3"]] :android {:aot :all-with-unused}} diff --git a/template/src/leiningen/new/play_clj/desktop-project.clj b/template/src/leiningen/new/play_clj/desktop-project.clj index 97f2f16..8861cac 100644 --- a/template/src/leiningen/new/play_clj/desktop-project.clj +++ b/template/src/leiningen/new/play_clj/desktop-project.clj @@ -12,7 +12,7 @@ [com.badlogicgames.gdx/gdx-platform "1.3.1" :classifier "natives-desktop"] [org.clojure/clojure "1.6.0"] - [play-clj "0.3.10"]] + [play-clj "0.3.11"]] :source-paths ["src" "src-common"] :javac-options ["-target" "1.6" "-source" "1.6" "-Xlint:-options"] diff --git a/template/src/leiningen/new/play_clj/ios-project.clj b/template/src/leiningen/new/play_clj/ios-project.clj index ed18c72..74f03ed 100644 --- a/template/src/leiningen/new/play_clj/ios-project.clj +++ b/template/src/leiningen/new/play_clj/ios-project.clj @@ -5,7 +5,7 @@ [com.badlogicgames.gdx/gdx-box2d "1.3.1"] [com.badlogicgames.gdx/gdx-bullet "1.3.1"] [org.clojure/clojure "1.6.0"] - [play-clj "0.3.10"]] + [play-clj "0.3.11"]] :source-paths ["src/clojure" "../desktop/src-common"] :java-source-paths ["src/java"] :javac-options ["-target" "1.7" "-source" "1.7" "-Xlint:-options"]