diff --git a/common/src/play_clj/core.clj b/common/src/play_clj/core.clj index 108e881..e3050f4 100644 --- a/common/src/play_clj/core.clj +++ b/common/src/play_clj/core.clj @@ -1,4 +1,5 @@ (ns play-clj.core + (:require [play-clj.utils :as utils]) (:import [com.badlogic.gdx Game Gdx Input$Keys Screen] [com.badlogic.gdx.graphics Camera Color GL20 OrthographicCamera PerspectiveCamera Texture] @@ -11,9 +12,9 @@ IsometricTiledMapRenderer OrthogonalTiledMapRenderer])) -(load "2d") -(load "global") -(load "render") +(load "core_2d") +(load "core_global") +(load "core_render") (defn find-pos [val coll] diff --git a/common/src/play_clj/2d.clj b/common/src/play_clj/core_2d.clj similarity index 64% rename from common/src/play_clj/2d.clj rename to common/src/play_clj/core_2d.clj index 5ced4f9..34e4693 100644 --- a/common/src/play_clj/2d.clj +++ b/common/src/play_clj/core_2d.clj @@ -25,18 +25,27 @@ ; textures (defn image - [^String internal-path] - (-> internal-path Texture. TextureRegion.)) + [val] + (if (string? val) + (-> val Texture. TextureRegion.) + (TextureRegion. val))) (defn split-image - ([^String internal-path size] - (split-image internal-path size size)) - ([^String internal-path width height] - (-> internal-path image (.split width height)))) + ([val size] + (split-image val size size)) + ([val width height] + (-> val image (.split width height)))) + +(defn flip-image + [val x? y?] + (doto (image val) (.flip x? y?))) (defmacro animation - [& args] - `(Animation. ~@args)) + [duration images & args] + `(Animation. ~duration + (utils/into-gdx-array ~images) + (utils/static-field :graphics :g2d :Animation + ~(or (first args) :normal)))) (defn get-animation-frame ([screen ^Animation animation] diff --git a/common/src/play_clj/global.clj b/common/src/play_clj/core_global.clj similarity index 100% rename from common/src/play_clj/global.clj rename to common/src/play_clj/core_global.clj diff --git a/common/src/play_clj/render.clj b/common/src/play_clj/core_render.clj similarity index 100% rename from common/src/play_clj/render.clj rename to common/src/play_clj/core_render.clj diff --git a/common/src/play_clj/utils.clj b/common/src/play_clj/utils.clj new file mode 100644 index 0000000..768985c --- /dev/null +++ b/common/src/play_clj/utils.clj @@ -0,0 +1,28 @@ +(ns play-clj.utils + (:require [clojure.string :as s]) + (:import [com.badlogic.gdx.utils Array])) + +(defn- split-keys + [key] + (-> key name (s/split #"-"))) + +(defn- join-keys + [keys] + (->> keys (map name) (s/join ".") (str "com.badlogic.gdx."))) + +(defn static-field* + [args] + (->> (last args) + split-keys + (map s/upper-case) + (s/join "_") + (str (join-keys (butlast args)) "/") + symbol)) + +(defmacro static-field + [& args] + `~(static-field* args)) + +(defn into-gdx-array + [a] + (-> a into-array Array.))