From 6565f9b31c050950dcb682302a891b8200ae9d32 Mon Sep 17 00:00:00 2001 From: oakes Date: Sat, 15 Mar 2014 20:59:19 -0400 Subject: [PATCH] Remove unnecessary multi-method --- src/play_clj/g2d.clj | 9 +++++---- src/play_clj/g3d.clj | 5 +++-- src/play_clj/ui.clj | 27 ++++++++++++++------------- src/play_clj/utils.clj | 28 +--------------------------- 4 files changed, 23 insertions(+), 46 deletions(-) diff --git a/src/play_clj/g2d.clj b/src/play_clj/g2d.clj index 880dd31..001493b 100644 --- a/src/play_clj/g2d.clj +++ b/src/play_clj/g2d.clj @@ -2,7 +2,8 @@ (:require [play-clj.utils :as u]) (:import [com.badlogic.gdx.graphics Texture] [com.badlogic.gdx.graphics.g2d Animation BitmapFont NinePatch - ParticleEffect TextureAtlas TextureRegion])) + ParticleEffect TextureAtlas TextureRegion] + [play_clj.utils TextureEntity NinePatchEntity ParticleEntity])) (defmacro bitmap-font "Returns a [BitmapFont](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/BitmapFont.html) @@ -17,7 +18,7 @@ (defn texture* "The function version of `texture`" [arg] - (u/create-entity + (TextureEntity. (cond (string? arg) (-> ^String arg Texture. TextureRegion.) @@ -52,7 +53,7 @@ (defn nine-patch* "The function version of `nine-patch`" [arg] - (u/create-entity + (NinePatchEntity. (cond (string? arg) (-> ^String arg Texture. TextureRegion. NinePatch.) @@ -89,7 +90,7 @@ (defn particle-effect* "The function version of `particle-effect`" [] - (u/create-entity (ParticleEffect.))) + (ParticleEntity. (ParticleEffect.))) (defmacro particle-effect "Returns an entity based on [ParticleEffect](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/ParticleEffect.html) diff --git a/src/play_clj/g3d.clj b/src/play_clj/g3d.clj index a28e3ed..43f2ee7 100644 --- a/src/play_clj/g3d.clj +++ b/src/play_clj/g3d.clj @@ -7,7 +7,8 @@ IntAttribute TextureAttribute] [com.badlogic.gdx.graphics.g3d.model.data ModelData] [com.badlogic.gdx.graphics.g3d.utils AnimationController - ModelBuilder])) + ModelBuilder] + [play_clj.utils ModelEntity])) ; animation-controller @@ -77,7 +78,7 @@ (defmacro model "Returns an entity based on [ModelInstance](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/ModelInstance.html)" [& args] - `(u/create-entity + `(ModelEntity. (let [arg1# ~(first args)] (cond (:object arg1#) diff --git a/src/play_clj/ui.clj b/src/play_clj/ui.clj index ed01ed5..c156e01 100644 --- a/src/play_clj/ui.clj +++ b/src/play_clj/ui.clj @@ -11,7 +11,8 @@ Tree$Node VerticalGroup WidgetGroup Window] [com.badlogic.gdx.scenes.scene2d.utils NinePatchDrawable SpriteDrawable TextureRegionDrawable TiledDrawable] - [com.esotericsoftware.tablelayout Cell])) + [com.esotericsoftware.tablelayout Cell] + [play_clj.utils ActorEntity])) (defmacro drawable "Returns a subclass of [BaseDrawable](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/utils/BaseDrawable.html) @@ -159,14 +160,14 @@ based on the file at `path` (defn ^:private create-group "Internal use only" [^WidgetGroup group children] - (apply add! (u/create-entity group) children)) + (apply add! (ActorEntity. group) children)) ; check-box (defn check-box* "The function version of `check-box`" [^String text arg] - (u/create-entity (CheckBox. text arg))) + (ActorEntity. (CheckBox. text arg))) (defmacro check-box "Returns an entity based on [CheckBox](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/CheckBox.html) @@ -188,7 +189,7 @@ based on the file at `path` (defn dialog* "The function version of `dialog`" [text arg] - (u/create-entity (Dialog. text arg))) + (ActorEntity. (Dialog. text arg))) (defmacro dialog "Returns an entity based on [Dialog](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/Dialog.html) @@ -231,7 +232,7 @@ based on the file at `path` (defn image* "The function version of `image`" [arg] - (u/create-entity + (ActorEntity. (cond (map? arg) (Image. ^TextureRegion (:object arg)) @@ -259,7 +260,7 @@ based on the file at `path` (defn image-button* "The function version of `image-button`" [arg] - (u/create-entity (ImageButton. arg))) + (ActorEntity. (ImageButton. arg))) (defmacro image-button "Returns an entity based on [ImageButton](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/ImageButton.html) @@ -281,7 +282,7 @@ based on the file at `path` (defn image-text-button* "The function version of `image-text-button`" [^String text arg] - (u/create-entity (ImageTextButton. text arg))) + (ActorEntity. (ImageTextButton. text arg))) (defmacro image-text-button "Returns an entity based on [ImageTextButton](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/ImageTextButton.html) @@ -304,7 +305,7 @@ based on the file at `path` (defn label* "The function version of `label`" [^String text arg] - (u/create-entity + (ActorEntity. (if (isa? (type arg) Color) (Label. text (style :label (g2d/bitmap-font) arg)) (Label. text arg)))) @@ -330,7 +331,7 @@ based on the file at `path` (defn scroll-pane* "The function version of `scroll-pane`" [child arg] - (u/create-entity (ScrollPane. (u/get-obj child :object) arg))) + (ActorEntity. (ScrollPane. (u/get-obj child :object) arg))) (defmacro scroll-pane "Returns an entity based on [ScrollPane](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/ScrollPane.html) @@ -352,7 +353,7 @@ based on the file at `path` (defn select-box* "The function version of `select-box`" [items arg] - (u/create-entity (SelectBox. (into-array items) arg))) + (ActorEntity. (SelectBox. (into-array items) arg))) (defmacro select-box "Returns an entity based on [SelectBox](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/SelectBox.html) @@ -377,7 +378,7 @@ based on the file at `path` [{:keys [min max step vertical?] :or {min 0 max 10 step 1 vertical? false}} arg] - (u/create-entity + (ActorEntity. (Slider. (float min) (float max) (float step) vertical? arg))) (defmacro slider @@ -442,7 +443,7 @@ based on the file at `path` (defn text-button* "The function version of `text-button`" [^String text arg] - (u/create-entity (TextButton. text arg))) + (ActorEntity. (TextButton. text arg))) (defmacro text-button "Returns an entity based on [TextButton](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/TextButton.html) @@ -464,7 +465,7 @@ based on the file at `path` (defn text-field* "The function version of `text-field`" [^String text arg] - (u/create-entity (TextField. text arg))) + (ActorEntity. (TextField. text arg))) (defmacro text-field "Returns an entity based on [TextField](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/TextField.html) diff --git a/src/play_clj/utils.clj b/src/play_clj/utils.clj index 2cc5f24..df7c6af 100644 --- a/src/play_clj/utils.clj +++ b/src/play_clj/utils.clj @@ -194,7 +194,7 @@ new object to be created each time a field is set) height (float (or height (.getTotalHeight object)))] (.draw object ^SpriteBatch batch x y width height)))) -(defrecord ParticleEffectEntity [object] Entity +(defrecord ParticleEntity [object] Entity (draw-entity! [{:keys [^ParticleEffect object x y delta-time]} batch] (let [x (float (or x 0)) y (float (or y 0)) @@ -217,29 +217,3 @@ new object to be created each time a field is set) (draw-entity! [{:keys [^ModelInstance object]} {:keys [^ModelBatch renderer ^Environment attributes]}] (.render renderer object attributes))) - -; create-entity - -(defmulti create-entity - "Internal use only" - class) - -(defmethod create-entity TextureRegion - [obj] - (TextureEntity. obj)) - -(defmethod create-entity NinePatch - [obj] - (NinePatchEntity. obj)) - -(defmethod create-entity ParticleEffect - [obj] - (ParticleEffectEntity. obj)) - -(defmethod create-entity Actor - [obj] - (ActorEntity. obj)) - -(defmethod create-entity ModelInstance - [obj] - (ModelEntity. obj))