diff --git a/template/project.clj b/template/project.clj new file mode 100644 index 0000000..568b336 --- /dev/null +++ b/template/project.clj @@ -0,0 +1,8 @@ +(defproject play-clj/lein-template "0.1.0-SNAPSHOT" + :description "A template for making play-clj projects" + :url "https://github.com/oakes/play-clj" + :license {:name "Public Domain" + :url "http://unlicense.org/UNLICENSE"} + :dependencies [[lein-droid "0.2.0"]] + :resource-paths ["resources"] + :eval-in-leiningen true) diff --git a/template/resources/armeabi-libgdx.so b/template/resources/armeabi-libgdx.so new file mode 100644 index 0000000..9476a88 Binary files /dev/null and b/template/resources/armeabi-libgdx.so differ diff --git a/template/resources/armeabi-v7a-libgdx.so b/template/resources/armeabi-v7a-libgdx.so new file mode 100644 index 0000000..bd49369 Binary files /dev/null and b/template/resources/armeabi-v7a-libgdx.so differ diff --git a/template/resources/libObjectAL.a b/template/resources/libObjectAL.a new file mode 100644 index 0000000..c6d7e08 Binary files /dev/null and b/template/resources/libObjectAL.a differ diff --git a/template/resources/libgdx.a b/template/resources/libgdx.a new file mode 100644 index 0000000..2838f52 Binary files /dev/null and b/template/resources/libgdx.a differ diff --git a/template/resources/x86-libgdx.so b/template/resources/x86-libgdx.so new file mode 100644 index 0000000..1abc12a Binary files /dev/null and b/template/resources/x86-libgdx.so differ diff --git a/template/src/leiningen/new/play_clj.clj b/template/src/leiningen/new/play_clj.clj new file mode 100644 index 0000000..4dea47a --- /dev/null +++ b/template/src/leiningen/new/play_clj.clj @@ -0,0 +1,96 @@ +(ns leiningen.new.play-clj + (:require [clojure.java.io :as io] + [leiningen.droid.new :as droid-new] + [leiningen.new.templates :as t])) + +(defn play-clj + [name & [package-name]] + (let [render (t/renderer "play-clj") + lein-droid-render (droid-new/renderer "templates") + desktop-class-name "desktop-launcher" + android-class-name "AndroidLauncher" + ios-class-name "IOSLauncher" + package-name (t/sanitize (t/multi-segment (or package-name name))) + package-prefix (->> (.lastIndexOf package-name ".") + (subs package-name 0)) + main-ns (t/sanitize-ns package-name) + desktop-ns (str main-ns "." desktop-class-name) + android-ns (str package-name "." android-class-name) + ios-ns (str package-name "." ios-class-name) + data {:app-name name + :name (t/project-name name) + :package package-name + :package-sanitized package-name + :package-prefix package-prefix + :desktop-class-name desktop-class-name + :android-class-name android-class-name + :ios-class-name ios-class-name + :activity android-class-name + :namespace main-ns + :desktop-namespace desktop-ns + :android-namespace android-ns + :ios-namespace ios-ns + :path (t/name-to-path main-ns) + :desktop-path (t/name-to-path desktop-ns) + :android-path (t/name-to-path android-ns) + :ios-path (t/name-to-path ios-ns) + :year (t/year) + :target-sdk "15"}] + (t/->files data + ; main + ["README.md" (render "README.md" data)] + [".gitignore" (render "gitignore" data)] + ; desktop + ["desktop/project.clj" (render "desktop-project.clj" data)] + ["desktop/src-common/{{path}}.clj" (render "core.clj" data)] + ["desktop/src/{{desktop-path}}.clj" + (render "desktop-launcher.clj" data)] + "desktop/src-common" + "desktop/src" + "desktop/resources" + ; android + ["android/project.clj" + (render "android-project.clj" data)] + ["android/src/java/{{android-path}}.java" + (render "AndroidLauncher.java" data)] + "android/src/clojure" + ["android/AndroidManifest.xml" + (lein-droid-render "AndroidManifest.xml" data)] + ["android/res/drawable-hdpi/ic_launcher.png" + (lein-droid-render "ic_launcher_hdpi.png")] + ["android/res/drawable-mdpi/ic_launcher.png" + (lein-droid-render "ic_launcher_mdpi.png")] + ["android/res/drawable-ldpi/ic_launcher.png" + (lein-droid-render "ic_launcher_ldpi.png")] + ["android/res/values/strings.xml" + (lein-droid-render "strings.xml" data)] + ["android/res/drawable-hdpi/splash_circle.png" + (lein-droid-render "splash_circle.png")] + ["android/res/drawable-hdpi/splash_droid.png" + (lein-droid-render "splash_droid.png")] + ["android/res/drawable-hdpi/splash_hands.png" + (lein-droid-render "splash_hands.png")] + ["android/res/drawable/splash_background.xml" + (lein-droid-render "splash_background.xml")] + ["android/res/anim/splash_rotation.xml" + (lein-droid-render "splash_rotation.xml")] + ["android/res/layout/splashscreen.xml" + (lein-droid-render "splashscreen.xml")] + ["android/src/java/{{path}}/SplashActivity.java" + (lein-droid-render "SplashActivity.java" data)] + ["android/libs/armeabi/libgdx.so" + (-> (io/resource "armeabi-libgdx.so") io/input-stream)] + ["android/libs/armeabi-v7a/libgdx.so" + (-> (io/resource "armeabi-v7a-libgdx.so") io/input-stream)] + ["android/libs/x86/libgdx.so" + (-> (io/resource "x86-libgdx.so") io/input-stream)] + ; ios + ["ios/project.clj" (render "ios-project.clj" data)] + ["ios/Info.plist.xml" (render "Info.plist.xml" data)] + "ios/src/clojure" + ["ios/src/java/{{ios-path}}.java" + (render "IOSLauncher.java" data)] + ["ios/libs/libObjectAL.a" + (-> (io/resource "libObjectAL.a") io/input-stream)] + ["ios/libs/libgdx.a" + (-> (io/resource "libgdx.a") io/input-stream)]))) diff --git a/template/src/leiningen/new/play_clj/AndroidLauncher.java b/template/src/leiningen/new/play_clj/AndroidLauncher.java new file mode 100644 index 0000000..9ca501e --- /dev/null +++ b/template/src/leiningen/new/play_clj/AndroidLauncher.java @@ -0,0 +1,20 @@ +package {{package}}; + +import clojure.lang.RT; +import clojure.lang.Symbol; + +import com.badlogic.gdx.backends.android.AndroidApplication; +import com.badlogic.gdx.Game; + +public class {{android-class-name}} extends AndroidApplication { + public void onCreate (android.os.Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + RT.var("clojure.core", "require").invoke(Symbol.intern("{{namespace}}")); + try { + Game game = (Game) RT.var("{{namespace}}", "{{app-name}}").deref(); + initialize(game, true); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/template/src/leiningen/new/play_clj/IOSLauncher.java b/template/src/leiningen/new/play_clj/IOSLauncher.java new file mode 100644 index 0000000..19d4d69 --- /dev/null +++ b/template/src/leiningen/new/play_clj/IOSLauncher.java @@ -0,0 +1,31 @@ +package {{package}}; + +import clojure.lang.RT; +import clojure.lang.Symbol; + +import com.badlogic.gdx.backends.iosrobovm.IOSApplication; +import com.badlogic.gdx.backends.iosrobovm.IOSApplicationConfiguration; +import com.badlogic.gdx.Game; + +import org.robovm.cocoatouch.foundation.NSAutoreleasePool; +import org.robovm.cocoatouch.uikit.UIApplication; + +public class {{ios-class-name}} extends IOSApplication.Delegate { + protected IOSApplication createApplication() { + IOSApplicationConfiguration config = new IOSApplicationConfiguration(); + RT.var("clojure.core", "require").invoke(Symbol.intern("{{namespace}}")); + try { + Game game = (Game) RT.var("{{namespace}}", "{{app-name}}").deref(); + return new IOSApplication(game, config); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public static void main(String[] argv) { + NSAutoreleasePool pool = new NSAutoreleasePool(); + UIApplication.main(argv, null, {{ios-class-name}}.class); + pool.drain(); + } +} diff --git a/template/src/leiningen/new/play_clj/Info.plist.xml b/template/src/leiningen/new/play_clj/Info.plist.xml new file mode 100644 index 0000000..a5465ac --- /dev/null +++ b/template/src/leiningen/new/play_clj/Info.plist.xml @@ -0,0 +1,61 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + {{app-name}} + CFBundleExecutable + {{app-name}} + CFBundleIdentifier + {{package}} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + {{app-name}} + CFBundlePackageType + APPL + CFBundleShortVersionString + ${app.version} + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UIDeviceFamily + + 1 + 2 + + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + CFBundleIcons + + CFBundlePrimaryIcon + + CFBundleIconFiles + + Icon + Icon-72 + + + + + diff --git a/template/src/leiningen/new/play_clj/README.md b/template/src/leiningen/new/play_clj/README.md new file mode 100644 index 0000000..618c480 --- /dev/null +++ b/template/src/leiningen/new/play_clj/README.md @@ -0,0 +1,11 @@ +# {{name}} + +A LibGDX game in which ... well, that part is up to you. + +## Contents + +* `android/src` Android-specific code +* `desktop/resources` Images, audio, and other files +* `desktop/src` Desktop-specific code +* `desktop/src-common` Cross-platform game code +* `ios/src` iOS-specific code diff --git a/template/src/leiningen/new/play_clj/android-project.clj b/template/src/leiningen/new/play_clj/android-project.clj new file mode 100644 index 0000000..5939c47 --- /dev/null +++ b/template/src/leiningen/new/play_clj/android-project.clj @@ -0,0 +1,37 @@ +(defproject {{app-name}} "0.0.1-SNAPSHOT" + :description "FIXME: write description" + + :dependencies [[com.badlogicgames.gdx/gdx "0.9.9" :use-resources true] + [com.badlogicgames.gdx/gdx-backend-android "0.9.9"] + [neko/neko "3.0.0"] + [org.clojure-android/clojure "1.5.1-jb" :use-resources true] + [play-clj "0.1.0-SNAPSHOT"]] + :repositories [["sonatype" + "https://oss.sonatype.org/content/repositories/snapshots/"]] + :profiles {:dev {:dependencies [[android/tools.nrepl "0.2.0-bigstack"] + [compliment "0.0.3"]] + :android {:aot :all-with-unused}} + :release {:android + {;; Specify the path to your private + ;; keystore and the the alias of the + ;; key you want to sign APKs with. + ;; :keystore-path "/home/user/.android/private.keystore" + ;; :key-alias "mykeyalias" + :aot :all}}} + + :android {;; Specify the path to the Android SDK directory either + ;; here or in your ~/.lein/profiles.clj file. + ;; :sdk-path "/home/user/path/to/android-sdk/" + + ;; Uncomment this if dexer fails with OutOfMemoryException + ;; :force-dex-optimize true + + :assets-path "../desktop/resources" + :native-libraries-paths ["libs"] + :target-version "{{target-sdk}}" + :aot-exclude-ns ["clojure.parallel" "clojure.core.reducers"] + :dex-opts ["-JXmx2048M"]} + + :source-paths ["src/clojure" "../desktop/src-common"] + :java-source-paths ["src/java" "gen"] + :javac-options ["-target" "1.7" "-source" "1.7" "-Xlint:-options"]) diff --git a/template/src/leiningen/new/play_clj/core.clj b/template/src/leiningen/new/play_clj/core.clj new file mode 100644 index 0000000..4b71f0b --- /dev/null +++ b/template/src/leiningen/new/play_clj/core.clj @@ -0,0 +1,18 @@ +(ns {{namespace}} + (:require [play-clj.core :refer :all] + [play-clj.ui :refer :all])) + +(defscreen main-screen + :on-show + (fn [screen entities] + (update! screen :renderer (stage)) + (conj entities (label "Hello world!" (color :white)))) + :on-render + (fn [screen entities] + (clear!) + (render! screen entities))) + +(defgame {{app-name}} + :on-create + (fn [this] + (set-screen! this main-screen))) diff --git a/template/src/leiningen/new/play_clj/desktop-launcher.clj b/template/src/leiningen/new/play_clj/desktop-launcher.clj new file mode 100644 index 0000000..37c0570 --- /dev/null +++ b/template/src/leiningen/new/play_clj/desktop-launcher.clj @@ -0,0 +1,10 @@ +(ns {{desktop-namespace}} + (:require [{{namespace}} :refer :all]) + (:import [com.badlogic.gdx.backends.lwjgl LwjglApplication] + [org.lwjgl.input Keyboard]) + (:gen-class)) + +(defn -main + [] + (LwjglApplication. {{app-name}} "{{app-name}}" 800 600 true) + (Keyboard/enableRepeatEvents true)) diff --git a/template/src/leiningen/new/play_clj/desktop-project.clj b/template/src/leiningen/new/play_clj/desktop-project.clj new file mode 100644 index 0000000..fa4bbef --- /dev/null +++ b/template/src/leiningen/new/play_clj/desktop-project.clj @@ -0,0 +1,16 @@ +(defproject {{app-name}} "0.0.1-SNAPSHOT" + :description "FIXME: write description" + + :dependencies [[com.badlogicgames.gdx/gdx "0.9.9"] + [com.badlogicgames.gdx/gdx-backend-lwjgl "0.9.9"] + [com.badlogicgames.gdx/gdx-platform "0.9.9" + :classifier "natives-desktop"] + [org.clojure/clojure "1.5.1"] + [play-clj "0.1.0-SNAPSHOT"]] + :repositories [["sonatype" + "https://oss.sonatype.org/content/repositories/snapshots/"]] + + :source-paths ["src" "src-common"] + :javac-options ["-target" "1.6" "-source" "1.6" "-Xlint:-options"] + :aot [{{desktop-namespace}}] + :main {{desktop-namespace}}) diff --git a/template/src/leiningen/new/play_clj/gitignore b/template/src/leiningen/new/play_clj/gitignore new file mode 100644 index 0000000..cc2ff39 --- /dev/null +++ b/template/src/leiningen/new/play_clj/gitignore @@ -0,0 +1,12 @@ +/target +/lib +/classes +/checkouts +pom.xml +pom.xml.asc +*.jar +*.class +.lein-deps-sum +.lein-failures +.lein-plugins +.lein-repl-history diff --git a/template/src/leiningen/new/play_clj/ios-project.clj b/template/src/leiningen/new/play_clj/ios-project.clj new file mode 100644 index 0000000..739fd96 --- /dev/null +++ b/template/src/leiningen/new/play_clj/ios-project.clj @@ -0,0 +1,17 @@ +(defproject {{app-name}} "0.0.1-SNAPSHOT" + :description "FIXME: write description" + :dependencies [[com.badlogicgames.gdx/gdx "0.9.9"] + [com.badlogicgames.gdx/gdx-backend-robovm "0.9.9"] + [org.clojure/clojure "1.5.1"] + [play-clj "0.1.0-SNAPSHOT"]] + :repositories [["sonatype" + "https://oss.sonatype.org/content/repositories/snapshots/"]] + :source-paths ["src/clojure" "../desktop/src-common"] + :java-source-paths ["src/java"] + :javac-options ["-target" "1.7" "-source" "1.7" "-Xlint:-options"] + :ios {:robovm-opts ["-forcelinkclasses" "{{package-prefix}}.**:clojure.**:com.badlogic.**:play_clj.**" + "-libs" "libs/libObjectAL.a:libs/libgdx.a" + "-frameworks" "UIKit:OpenGLES:QuartzCore:CoreGraphics:OpenAL:AudioToolbox:AVFoundation" + "-resources" "../desktop/resources/**"]} + :aot :all + :main {{ios-namespace}})