try {
int boneCount = input.readInt(true);
for (int i = 0; i < boneCount; i++) {
String boneName = input.readString();
int boneIndex = skeletonData.findBoneIndex(boneName);
if (boneIndex == -1) throw new SerializationException("Bone not found: " + boneName);
int itemCount = input.readInt(true);
for (int ii = 0; ii < itemCount; ii++) {
int timelineType = input.readByte();
int keyCount = input.readInt(true);
switch (timelineType) {
case TIMELINE_ROTATE: {
RotateTimeline timeline = new RotateTimeline(keyCount);
timeline.setBoneIndex(boneIndex);
for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) {
timeline.setFrame(keyframeIndex, input.readFloat(), input.readFloat());
if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline);
}
timelines.add(timeline);
duration = Math.max(duration, timeline.getFrames()[keyCount * 2 - 2]);
break;
}
case TIMELINE_TRANSLATE:
case TIMELINE_SCALE:
TranslateTimeline timeline;
float timelineScale = 1;
if (timelineType == TIMELINE_SCALE)
timeline = new ScaleTimeline(keyCount);
else {
timeline = new TranslateTimeline(keyCount);
timelineScale = scale;
}
timeline.setBoneIndex(boneIndex);
for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) {
timeline.setFrame(keyframeIndex, input.readFloat(), input.readFloat() * timelineScale, input.readFloat()
* timelineScale);
if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline);
}
timelines.add(timeline);
duration = Math.max(duration, timeline.getFrames()[keyCount * 3 - 3]);
break;
default:
throw new RuntimeException("Invalid timeline type for a bone: " + timelineType + " (" + boneName + ")");
}
}
}
int slotCount = input.readInt(true);
for (int i = 0; i < slotCount; i++) {
String slotName = input.readString();
int slotIndex = skeletonData.findSlotIndex(slotName);
int itemCount = input.readInt(true);
for (int ii = 0; ii < itemCount; ii++) {
int timelineType = input.readByte();
int keyCount = input.readInt(true);
switch (timelineType) {
case TIMELINE_COLOR: {
ColorTimeline timeline = new ColorTimeline(keyCount);
timeline.setSlotIndex(slotIndex);
for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) {
float time = input.readFloat();
Color.rgba8888ToColor(tempColor, input.readInt());
timeline.setFrame(keyframeIndex, time, tempColor.r, tempColor.g, tempColor.b, tempColor.a);
if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline);
}
timelines.add(timeline);
duration = Math.max(duration, timeline.getFrames()[keyCount * 5 - 5]);
break;
}
case TIMELINE_ATTACHMENT:
AttachmentTimeline timeline = new AttachmentTimeline(keyCount);
timeline.setSlotIndex(slotIndex);
for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++)
timeline.setFrame(keyframeIndex, input.readFloat(), input.readString());
timelines.add(timeline);
duration = Math.max(duration, timeline.getFrames()[keyCount - 1]);
break;
default:
throw new RuntimeException("Invalid timeline type for a slot: " + timelineType + " (" + slotName + ")");
}
}
}
} catch (IOException ex) {
throw new SerializationException("Error reading skeleton file.", ex);
}
timelines.shrink();
skeletonData.addAnimation(new Animation(name, timelines, duration));
}