From aab718fe95279b71005d79d128ddd0ceb9670499 Mon Sep 17 00:00:00 2001 From: oakes Date: Wed, 15 Jan 2014 15:31:02 -0500 Subject: [PATCH] Add gdx-array-map --- src/play_clj/core_2d.clj | 2 +- src/play_clj/utils.clj | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/play_clj/core_2d.clj b/src/play_clj/core_2d.clj index 54a574c..d583b38 100644 --- a/src/play_clj/core_2d.clj +++ b/src/play_clj/core_2d.clj @@ -77,7 +77,7 @@ (defmacro animation [duration textures & args] `(Animation. ~duration - (u/convert-array (map :object ~textures)) + (u/gdx-array (map :object ~textures)) (u/static-field-upper :graphics :g2d :Animation ~(or (first args) :normal)))) diff --git a/src/play_clj/utils.clj b/src/play_clj/utils.clj index 3df8394..05c3f4b 100644 --- a/src/play_clj/utils.clj +++ b/src/play_clj/utils.clj @@ -1,8 +1,10 @@ (ns play-clj.utils (:require [clojure.string :as s]) (:import [com.badlogic.gdx.graphics.g2d TextureRegion] - [com.badlogic.gdx.utils Array] - [com.badlogic.gdx.scenes.scene2d Actor])) + [com.badlogic.gdx.scenes.scene2d Actor] + [com.badlogic.gdx.utils Array ArrayMap])) + +; converting keys (def ^:const main-package "com.badlogic.gdx") @@ -52,9 +54,20 @@ [& args] `~(static-field args key->upper)) -(defn convert-array - [a] - (Array. true (into-array a) 1 (count a))) +; data structures + +(defn gdx-array + [arr] + (Array. true (into-array arr) 1 (count arr))) + +(defn gdx-array-map + [hmap] + (let [amap (ArrayMap.)] + (doseq [[k v] hmap] + (.put amap k v)) + amap)) + +; java interop (defmacro call! [obj k & args] @@ -73,6 +86,8 @@ [obj & args] `(doto ~obj ~@(create-method-calls [] args))) +; entities + (defmulti create-entity class) (defmethod create-entity TextureRegion