diff --git a/spine-libgdx/src/com/esotericsoftware/spine/Animation.java b/spine-libgdx/src/com/esotericsoftware/spine/Animation.java index e3ecf654c..0586f51e2 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/Animation.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/Animation.java @@ -30,6 +30,7 @@ import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.utils.Array; public class Animation { + private String name; private final Array timelines; private float duration; @@ -76,6 +77,20 @@ public class Animation { timelines.get(i).apply(skeleton, time, alpha); } + /** @return May be null. */ + public String getName () { + return name; + } + + /** @param name May be null. */ + public void setName (String name) { + this.name = name; + } + + public String toString () { + return name != null ? name : super.toString(); + } + /** @param target After the first and before the last entry. */ static int binarySearch (float[] values, float target, int step) { int low = 0; diff --git a/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java b/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java index b776a1c18..b6adc14a8 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java @@ -95,4 +95,8 @@ public class AnimationState { public AnimationStateData getData () { return data; } + + public String toString () { + return (current != null && current.getName() != null) ? current.getName() : super.toString(); + } } diff --git a/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java b/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java index db97154ce..e75886be0 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java @@ -298,4 +298,8 @@ public class Skeleton { public void update (float delta) { time += delta; } + + public String toString () { + return data.name != null ? data.name : super.toString(); + } } diff --git a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java index 5cfc08852..e70e54726 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java @@ -81,6 +81,8 @@ public class SkeletonBinary { if (file == null) throw new IllegalArgumentException("file cannot be null."); SkeletonData skeletonData = new SkeletonData(); + skeletonData.setName(file.nameWithoutExtension()); + DataInput input = new DataInput(file.read(512)); try { // Bones. @@ -274,7 +276,9 @@ public class SkeletonBinary { } timelines.shrink(); - return new Animation(timelines, duration); + Animation animation = new Animation(timelines, duration); + animation.setName(file.nameWithoutExtension()); + return animation; } private void readCurve (DataInput input, int keyframeIndex, CurveTimeline timeline) throws IOException { diff --git a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonData.java b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonData.java index 023afe4b0..3b85eb019 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonData.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonData.java @@ -28,6 +28,7 @@ package com.esotericsoftware.spine; import com.badlogic.gdx.utils.Array; public class SkeletonData { + String name; final Array bones = new Array(); // Ordered parents first. final Array slots = new Array(); // Bind pose draw order. final Array skins = new Array(); @@ -131,4 +132,20 @@ public class SkeletonData { public Array getSkins () { return skins; } + + // --- + + /** @return May be null. */ + public String getName () { + return name; + } + + /** @param name May be null. */ + public void setName (String name) { + this.name = name; + } + + public String toString () { + return name != null ? name : super.toString(); + } } diff --git a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java index b4a607350..39af3e585 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java @@ -78,6 +78,7 @@ public class SkeletonJson { if (file == null) throw new IllegalArgumentException("file cannot be null."); SkeletonData skeletonData = new SkeletonData(); + skeletonData.setName(file.nameWithoutExtension()); OrderedMap root = json.fromJson(OrderedMap.class, file); @@ -284,7 +285,9 @@ public class SkeletonJson { } timelines.shrink(); - return new Animation(timelines, duration); + Animation animation = new Animation(timelines, duration); + animation.setName(file.nameWithoutExtension()); + return animation; } private void readCurve (CurveTimeline timeline, int keyframeIndex, OrderedMap valueMap) { diff --git a/spine-libgdx/test/com/esotericsoftware/spine/AnimationStateTest.java b/spine-libgdx/test/com/esotericsoftware/spine/AnimationStateTest.java index 0b2129792..775c33c06 100644 --- a/spine-libgdx/test/com/esotericsoftware/spine/AnimationStateTest.java +++ b/spine-libgdx/test/com/esotericsoftware/spine/AnimationStateTest.java @@ -76,6 +76,7 @@ public class AnimationStateTest extends ApplicationAdapter { Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); batch.begin(); + System.out.println(skeleton); state.apply(skeleton); // After one second, change the current animation. Mixing is done by AnimationState for you. if (state.getTime() > 1 && state.getAnimation() == walkAnimation) state.setAnimation(jumpAnimation, false);