Selaa lähdekoodia

Adjusted order objects are read.

NathanSweet 11 vuotta sitten
vanhempi
commit
7570e0a18c

+ 52 - 52
spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java

@@ -265,7 +265,39 @@ public class SkeletonBinary {
 		float duration = 0;
 		float duration = 0;
 
 
 		try {
 		try {
-			// SRT.
+			// Slot timelines.
+			for (int i = 0, n = input.readInt(true); i < n; i++) {
+				int slotIndex = input.readInt(true);
+				for (int ii = 0, nn = input.readInt(true); ii < nn; ii++) {
+					int timelineType = input.readByte();
+					int frameCount = input.readInt(true);
+					switch (timelineType) {
+					case TIMELINE_COLOR: {
+						ColorTimeline timeline = new ColorTimeline(frameCount);
+						timeline.slotIndex = slotIndex;
+						for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) {
+							float time = input.readFloat();
+							Color.rgba8888ToColor(tempColor, input.readInt());
+							timeline.setFrame(frameIndex, time, tempColor.r, tempColor.g, tempColor.b, tempColor.a);
+							if (frameIndex < frameCount - 1) readCurve(input, frameIndex, timeline);
+						}
+						timelines.add(timeline);
+						duration = Math.max(duration, timeline.getFrames()[frameCount * 5 - 5]);
+						break;
+					}
+					case TIMELINE_ATTACHMENT:
+						AttachmentTimeline timeline = new AttachmentTimeline(frameCount);
+						timeline.slotIndex = slotIndex;
+						for (int frameIndex = 0; frameIndex < frameCount; frameIndex++)
+							timeline.setFrame(frameIndex, input.readFloat(), input.readString());
+						timelines.add(timeline);
+						duration = Math.max(duration, timeline.getFrames()[frameCount - 1]);
+						break;
+					}
+				}
+			}
+
+			// Bone timelines.
 			for (int i = 0, n = input.readInt(true); i < n; i++) {
 			for (int i = 0, n = input.readInt(true); i < n; i++) {
 				int boneIndex = input.readInt(true);
 				int boneIndex = input.readInt(true);
 				for (int ii = 0, nn = input.readInt(true); ii < nn; ii++) {
 				for (int ii = 0, nn = input.readInt(true); ii < nn; ii++) {
@@ -306,7 +338,7 @@ public class SkeletonBinary {
 				}
 				}
 			}
 			}
 
 
-			// FFD.
+			// FFD timelines.
 			for (int i = 0, n = input.readInt(true); i < n; i++) {
 			for (int i = 0, n = input.readInt(true); i < n; i++) {
 				Skin skin = skeletonData.getSkins().get(input.readInt(true) + 1);
 				Skin skin = skeletonData.getSkins().get(input.readInt(true) + 1);
 				for (int ii = 0, nn = input.readInt(true); ii < nn; ii++) {
 				for (int ii = 0, nn = input.readInt(true); ii < nn; ii++) {
@@ -337,56 +369,7 @@ public class SkeletonBinary {
 				}
 				}
 			}
 			}
 
 
-			// Color, attachment.
-			for (int i = 0, n = input.readInt(true); i < n; i++) {
-				int slotIndex = input.readInt(true);
-				for (int ii = 0, nn = input.readInt(true); ii < nn; ii++) {
-					int timelineType = input.readByte();
-					int frameCount = input.readInt(true);
-					switch (timelineType) {
-					case TIMELINE_COLOR: {
-						ColorTimeline timeline = new ColorTimeline(frameCount);
-						timeline.slotIndex = slotIndex;
-						for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) {
-							float time = input.readFloat();
-							Color.rgba8888ToColor(tempColor, input.readInt());
-							timeline.setFrame(frameIndex, time, tempColor.r, tempColor.g, tempColor.b, tempColor.a);
-							if (frameIndex < frameCount - 1) readCurve(input, frameIndex, timeline);
-						}
-						timelines.add(timeline);
-						duration = Math.max(duration, timeline.getFrames()[frameCount * 5 - 5]);
-						break;
-					}
-					case TIMELINE_ATTACHMENT:
-						AttachmentTimeline timeline = new AttachmentTimeline(frameCount);
-						timeline.slotIndex = slotIndex;
-						for (int frameIndex = 0; frameIndex < frameCount; frameIndex++)
-							timeline.setFrame(frameIndex, input.readFloat(), input.readString());
-						timelines.add(timeline);
-						duration = Math.max(duration, timeline.getFrames()[frameCount - 1]);
-						break;
-					}
-				}
-			}
-
-			// Events.
-			int eventCount = input.readInt(true);
-			if (eventCount > 0) {
-				EventTimeline timeline = new EventTimeline(eventCount);
-				for (int i = 0; i < eventCount; i++) {
-					float time = input.readFloat();
-					EventData eventData = skeletonData.events.get(input.readInt(true));
-					Event event = new Event(eventData);
-					event.intValue = input.readInt(false);
-					event.floatValue = input.readFloat();
-					event.stringValue = input.readBoolean() ? input.readString() : eventData.stringValue;
-					timeline.setFrame(i, time, event);
-				}
-				timelines.add(timeline);
-				duration = Math.max(duration, timeline.getFrames()[eventCount - 1]);
-			}
-
-			// Draw order.
+			// Draw order timeline.
 			int drawOrderCount = input.readInt(true);
 			int drawOrderCount = input.readInt(true);
 			if (drawOrderCount > 0) {
 			if (drawOrderCount > 0) {
 				DrawOrderTimeline timeline = new DrawOrderTimeline(drawOrderCount);
 				DrawOrderTimeline timeline = new DrawOrderTimeline(drawOrderCount);
@@ -417,6 +400,23 @@ public class SkeletonBinary {
 				timelines.add(timeline);
 				timelines.add(timeline);
 				duration = Math.max(duration, timeline.getFrames()[drawOrderCount - 1]);
 				duration = Math.max(duration, timeline.getFrames()[drawOrderCount - 1]);
 			}
 			}
+
+			// Event timeline.
+			int eventCount = input.readInt(true);
+			if (eventCount > 0) {
+				EventTimeline timeline = new EventTimeline(eventCount);
+				for (int i = 0; i < eventCount; i++) {
+					float time = input.readFloat();
+					EventData eventData = skeletonData.events.get(input.readInt(true));
+					Event event = new Event(eventData);
+					event.intValue = input.readInt(false);
+					event.floatValue = input.readFloat();
+					event.stringValue = input.readBoolean() ? input.readString() : eventData.stringValue;
+					timeline.setFrame(i, time, event);
+				}
+				timelines.add(timeline);
+				duration = Math.max(duration, timeline.getFrames()[eventCount - 1]);
+			}
 		} catch (IOException ex) {
 		} catch (IOException ex) {
 			throw new SerializationException("Error reading skeleton file.", ex);
 			throw new SerializationException("Error reading skeleton file.", ex);
 		}
 		}

+ 56 - 56
spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java

@@ -225,7 +225,42 @@ public class SkeletonJson {
 		Array<Timeline> timelines = new Array();
 		Array<Timeline> timelines = new Array();
 		float duration = 0;
 		float duration = 0;
 
 
-		// SRT.
+		// Slot timelines.
+		for (JsonValue slotMap = map.getChild("slots"); slotMap != null; slotMap = slotMap.next) {
+			int slotIndex = skeletonData.findSlotIndex(slotMap.name);
+			if (slotIndex == -1) throw new SerializationException("Slot not found: " + slotMap.name);
+
+			for (JsonValue timelineMap = slotMap.child; timelineMap != null; timelineMap = timelineMap.next) {
+				String timelineName = timelineMap.name;
+				if (timelineName.equals("color")) {
+					ColorTimeline timeline = new ColorTimeline(timelineMap.size);
+					timeline.slotIndex = slotIndex;
+
+					int frameIndex = 0;
+					for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next) {
+						Color color = Color.valueOf(valueMap.getString("color"));
+						timeline.setFrame(frameIndex, valueMap.getFloat("time"), color.r, color.g, color.b, color.a);
+						readCurve(timeline, frameIndex, valueMap);
+						frameIndex++;
+					}
+					timelines.add(timeline);
+					duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() * 5 - 5]);
+
+				} else if (timelineName.equals("attachment")) {
+					AttachmentTimeline timeline = new AttachmentTimeline(timelineMap.size);
+					timeline.slotIndex = slotIndex;
+
+					int frameIndex = 0;
+					for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next)
+						timeline.setFrame(frameIndex++, valueMap.getFloat("time"), valueMap.getString("name"));
+					timelines.add(timeline);
+					duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() - 1]);
+				} else
+					throw new RuntimeException("Invalid timeline type for a slot: " + timelineName + " (" + slotMap.name + ")");
+			}
+		}
+
+		// Bone timelines.
 		for (JsonValue boneMap = map.getChild("bones"); boneMap != null; boneMap = boneMap.next) {
 		for (JsonValue boneMap = map.getChild("bones"); boneMap != null; boneMap = boneMap.next) {
 			int boneIndex = skeletonData.findBoneIndex(boneMap.name);
 			int boneIndex = skeletonData.findBoneIndex(boneMap.name);
 			if (boneIndex == -1) throw new SerializationException("Bone not found: " + boneMap.name);
 			if (boneIndex == -1) throw new SerializationException("Bone not found: " + boneMap.name);
@@ -271,7 +306,7 @@ public class SkeletonJson {
 			}
 			}
 		}
 		}
 
 
-		// FFD.
+		// FFD timelines.
 		for (JsonValue ffdMap = map.getChild("ffd"); ffdMap != null; ffdMap = ffdMap.next) {
 		for (JsonValue ffdMap = map.getChild("ffd"); ffdMap != null; ffdMap = ffdMap.next) {
 			Skin skin = skeletonData.findSkin(ffdMap.name);
 			Skin skin = skeletonData.findSkin(ffdMap.name);
 			if (skin == null) throw new SerializationException("Skin not found: " + ffdMap.name);
 			if (skin == null) throw new SerializationException("Skin not found: " + ffdMap.name);
@@ -308,60 +343,7 @@ public class SkeletonJson {
 			}
 			}
 		}
 		}
 
 
-		// Color, attachment.
-		for (JsonValue slotMap = map.getChild("slots"); slotMap != null; slotMap = slotMap.next) {
-			int slotIndex = skeletonData.findSlotIndex(slotMap.name);
-			if (slotIndex == -1) throw new SerializationException("Slot not found: " + slotMap.name);
-
-			for (JsonValue timelineMap = slotMap.child; timelineMap != null; timelineMap = timelineMap.next) {
-				String timelineName = timelineMap.name;
-				if (timelineName.equals("color")) {
-					ColorTimeline timeline = new ColorTimeline(timelineMap.size);
-					timeline.slotIndex = slotIndex;
-
-					int frameIndex = 0;
-					for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next) {
-						Color color = Color.valueOf(valueMap.getString("color"));
-						timeline.setFrame(frameIndex, valueMap.getFloat("time"), color.r, color.g, color.b, color.a);
-						readCurve(timeline, frameIndex, valueMap);
-						frameIndex++;
-					}
-					timelines.add(timeline);
-					duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() * 5 - 5]);
-
-				} else if (timelineName.equals("attachment")) {
-					AttachmentTimeline timeline = new AttachmentTimeline(timelineMap.size);
-					timeline.slotIndex = slotIndex;
-
-					int frameIndex = 0;
-					for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next)
-						timeline.setFrame(frameIndex++, valueMap.getFloat("time"), valueMap.getString("name"));
-					timelines.add(timeline);
-					duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() - 1]);
-				} else
-					throw new RuntimeException("Invalid timeline type for a slot: " + timelineName + " (" + slotMap.name + ")");
-			}
-		}
-
-		// Events.
-		JsonValue eventsMap = map.get("events");
-		if (eventsMap != null) {
-			EventTimeline timeline = new EventTimeline(eventsMap.size);
-			int frameIndex = 0;
-			for (JsonValue eventMap = eventsMap.child; eventMap != null; eventMap = eventMap.next) {
-				EventData eventData = skeletonData.findEvent(eventMap.getString("name"));
-				if (eventData == null) throw new SerializationException("Event not found: " + eventMap.getString("name"));
-				Event event = new Event(eventData);
-				event.intValue = eventMap.getInt("int", eventData.getInt());
-				event.floatValue = eventMap.getFloat("float", eventData.getFloat());
-				event.stringValue = eventMap.getString("string", eventData.getString());
-				timeline.setFrame(frameIndex++, eventMap.getFloat("time"), event);
-			}
-			timelines.add(timeline);
-			duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() - 1]);
-		}
-
-		// Draw order.
+		// Draw order timeline.
 		JsonValue drawOrdersMap = map.get("draworder");
 		JsonValue drawOrdersMap = map.get("draworder");
 		if (drawOrdersMap != null) {
 		if (drawOrdersMap != null) {
 			DrawOrderTimeline timeline = new DrawOrderTimeline(drawOrdersMap.size);
 			DrawOrderTimeline timeline = new DrawOrderTimeline(drawOrdersMap.size);
@@ -398,6 +380,24 @@ public class SkeletonJson {
 			duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() - 1]);
 			duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() - 1]);
 		}
 		}
 
 
+		// Event timeline.
+		JsonValue eventsMap = map.get("events");
+		if (eventsMap != null) {
+			EventTimeline timeline = new EventTimeline(eventsMap.size);
+			int frameIndex = 0;
+			for (JsonValue eventMap = eventsMap.child; eventMap != null; eventMap = eventMap.next) {
+				EventData eventData = skeletonData.findEvent(eventMap.getString("name"));
+				if (eventData == null) throw new SerializationException("Event not found: " + eventMap.getString("name"));
+				Event event = new Event(eventData);
+				event.intValue = eventMap.getInt("int", eventData.getInt());
+				event.floatValue = eventMap.getFloat("float", eventData.getFloat());
+				event.stringValue = eventMap.getString("string", eventData.getString());
+				timeline.setFrame(frameIndex++, eventMap.getFloat("time"), event);
+			}
+			timelines.add(timeline);
+			duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() - 1]);
+		}
+
 		timelines.shrink();
 		timelines.shrink();
 		skeletonData.addAnimation(new Animation(name, timelines, duration));
 		skeletonData.addAnimation(new Animation(name, timelines, duration));
 	}
 	}