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.
for (int i = 0, n = input.readInt(true); i < n; i++) {
String name = input.readString();
BoneData parent = null;
String parentName = input.readString();
if (parentName != null) {
parent = skeletonData.findBone(parentName);
if (parent == null) throw new SerializationException("Parent bone not found: " + parentName);
}
BoneData boneData = new BoneData(name, parent);
boneData.x = input.readFloat() * scale;
boneData.y = input.readFloat() * scale;
boneData.scaleX = input.readFloat();
boneData.scaleY = input.readFloat();
boneData.rotation = input.readFloat();
boneData.length = input.readFloat() * scale;
boneData.inheritScale = input.readByte() == 1;
boneData.inheritRotation = input.readByte() == 1;
skeletonData.addBone(boneData);
}
// Slots.
for (int i = 0, n = input.readInt(true); i < n; i++) {
String slotName = input.readString();
String boneName = input.readString();
BoneData boneData = skeletonData.findBone(boneName);
if (boneData == null) throw new SerializationException("Bone not found: " + boneName);
SlotData slotData = new SlotData(slotName, boneData);
Color.rgba8888ToColor(slotData.getColor(), input.readInt());
slotData.setAttachmentName(input.readString());
slotData.additiveBlending = input.readByte() == 1;
skeletonData.addSlot(slotData);
}
// Default skin.
Skin defaultSkin = readSkin(input, "default");
if (defaultSkin != null) {
skeletonData.setDefaultSkin(defaultSkin);
skeletonData.addSkin(defaultSkin);
}
// Skins.
for (int i = 0, n = input.readInt(true); i < n; i++)
skeletonData.addSkin(readSkin(input, input.readString()));
// Animations.
for (int i = 0, n = input.readInt(true); i < n; i++)
readAnimation(input.readString(), input, skeletonData);
} catch (IOException ex) {
throw new SerializationException("Error reading skeleton file.", ex);
} finally {
try {
input.close();
} catch (IOException ignored) {
}
}
skeletonData.bones.shrink();