Browse Source

Names for animation and skeleton.

NathanSweet 12 năm trước cách đây
mục cha
commit
159d076f79

+ 15 - 0
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<Timeline> 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;

+ 4 - 0
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();
+	}
 }

+ 4 - 0
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();
+	}
 }

+ 5 - 1
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 {

+ 17 - 0
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<BoneData> bones = new Array(); // Ordered parents first.
 	final Array<SlotData> slots = new Array(); // Bind pose draw order.
 	final Array<Skin> skins = new Array();
@@ -131,4 +132,20 @@ public class SkeletonData {
 	public Array<Skin> 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();
+	}
 }

+ 4 - 1
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<String, ?> 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) {

+ 1 - 0
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);