Removed findXxxIndex.

These are just noise now that bones and slots have an index field.
This commit is contained in:
NathanSweet 2016-10-28 23:11:30 +02:00
parent 2287256c72
commit e14a783c38
4 changed files with 37 additions and 84 deletions

View File

@ -388,15 +388,6 @@ public class Skeleton {
return null; return null;
} }
/** @return -1 if the bone was not found. */
public int findBoneIndex (String boneName) {
if (boneName == null) throw new IllegalArgumentException("boneName cannot be null.");
Array<Bone> bones = this.bones;
for (int i = 0, n = bones.size; i < n; i++)
if (bones.get(i).data.name.equals(boneName)) return i;
return -1;
}
public Array<Slot> getSlots () { public Array<Slot> getSlots () {
return slots; return slots;
} }
@ -412,15 +403,6 @@ public class Skeleton {
return null; return null;
} }
/** @return -1 if the bone was not found. */
public int findSlotIndex (String slotName) {
if (slotName == null) throw new IllegalArgumentException("slotName cannot be null.");
Array<Slot> slots = this.slots;
for (int i = 0, n = slots.size; i < n; i++)
if (slots.get(i).data.name.equals(slotName)) return i;
return -1;
}
/** Returns the slots in the order they will be drawn. The returned array may be modified to change the draw order. */ /** Returns the slots in the order they will be drawn. The returned array may be modified to change the draw order. */
public Array<Slot> getDrawOrder () { public Array<Slot> getDrawOrder () {
return drawOrder; return drawOrder;
@ -470,7 +452,9 @@ public class Skeleton {
/** @return May be null. */ /** @return May be null. */
public Attachment getAttachment (String slotName, String attachmentName) { public Attachment getAttachment (String slotName, String attachmentName) {
return getAttachment(data.findSlotIndex(slotName), attachmentName); SlotData slot = data.findSlot(slotName);
if (slot == null) throw new IllegalArgumentException("Slot not found: " + slotName);
return getAttachment(slot.getIndex(), attachmentName);
} }
/** @return May be null. */ /** @return May be null. */
@ -484,24 +468,20 @@ public class Skeleton {
return null; return null;
} }
/** @param attachmentName May be null. */ /** Sets an attachment by finding the slot with {@link #findSlot(String)}, finding the attachment with
* {@link #getAttachment(int, String)}, then sets the slot's {@link Slot#attachment}.
* @param attachmentName May be null to clear the slot. */
public void setAttachment (String slotName, String attachmentName) { public void setAttachment (String slotName, String attachmentName) {
if (slotName == null) throw new IllegalArgumentException("slotName cannot be null."); if (slotName == null) throw new IllegalArgumentException("slotName cannot be null.");
Array<Slot> slots = this.slots; Slot slot = findSlot(slotName);
for (int i = 0, n = slots.size; i < n; i++) { if (slot == null) throw new IllegalArgumentException("Slot not found: " + slotName);
Slot slot = slots.get(i); Attachment attachment = null;
if (slot.data.name.equals(slotName)) { if (attachmentName != null) {
Attachment attachment = null; attachment = getAttachment(slot.data.index, attachmentName);
if (attachmentName != null) { if (attachment == null)
attachment = getAttachment(i, attachmentName); throw new IllegalArgumentException("Attachment not found: " + attachmentName + ", for slot: " + slotName);
if (attachment == null)
throw new IllegalArgumentException("Attachment not found: " + attachmentName + ", for slot: " + slotName);
}
slot.setAttachment(attachment);
return;
}
} }
throw new IllegalArgumentException("Slot not found: " + slotName); slot.setAttachment(attachment);
} }
public Array<IkConstraint> getIkConstraints () { public Array<IkConstraint> getIkConstraints () {

View File

@ -617,7 +617,7 @@ public class SkeletonBinary {
// Path constraint timelines. // Path constraint timelines.
for (int i = 0, n = input.readInt(true); i < n; i++) { for (int i = 0, n = input.readInt(true); i < n; i++) {
int index = input.readInt(true); int index = input.readInt(true);
PathConstraintData data = skeletonData.getPathConstraints().get(index); PathConstraintData data = skeletonData.pathConstraints.get(index);
for (int ii = 0, nn = input.readInt(true); ii < nn; ii++) { for (int ii = 0, nn = input.readInt(true); ii < nn; ii++) {
int timelineType = input.readByte(); int timelineType = input.readByte();
int frameCount = input.readInt(true); int frameCount = input.readInt(true);

View File

@ -67,15 +67,6 @@ public class SkeletonData {
return null; return null;
} }
/** @return -1 if the bone was not found. */
public int findBoneIndex (String boneName) {
if (boneName == null) throw new IllegalArgumentException("boneName cannot be null.");
Array<BoneData> bones = this.bones;
for (int i = 0, n = bones.size; i < n; i++)
if (bones.get(i).name.equals(boneName)) return i;
return -1;
}
// --- Slots. // --- Slots.
public Array<SlotData> getSlots () { public Array<SlotData> getSlots () {
@ -93,15 +84,6 @@ public class SkeletonData {
return null; return null;
} }
/** @return -1 if the slot was not found. */
public int findSlotIndex (String slotName) {
if (slotName == null) throw new IllegalArgumentException("slotName cannot be null.");
Array<SlotData> slots = this.slots;
for (int i = 0, n = slots.size; i < n; i++)
if (slots.get(i).name.equals(slotName)) return i;
return -1;
}
// --- Skins. // --- Skins.
/** @return May be null. */ /** @return May be null. */
@ -209,15 +191,6 @@ public class SkeletonData {
return null; return null;
} }
/** @return -1 if the path constraint was not found. */
public int findPathConstraintIndex (String pathConstraintName) {
if (pathConstraintName == null) throw new IllegalArgumentException("pathConstraintName cannot be null.");
Array<PathConstraintData> pathConstraints = this.pathConstraints;
for (int i = 0, n = pathConstraints.size; i < n; i++)
if (pathConstraints.get(i).name.equals(pathConstraintName)) return i;
return -1;
}
// --- // ---
/** @return May be null. */ /** @return May be null. */

View File

@ -241,12 +241,12 @@ public class SkeletonJson {
for (JsonValue skinMap = root.getChild("skins"); skinMap != null; skinMap = skinMap.next) { for (JsonValue skinMap = root.getChild("skins"); skinMap != null; skinMap = skinMap.next) {
Skin skin = new Skin(skinMap.name); Skin skin = new Skin(skinMap.name);
for (JsonValue slotEntry = skinMap.child; slotEntry != null; slotEntry = slotEntry.next) { for (JsonValue slotEntry = skinMap.child; slotEntry != null; slotEntry = slotEntry.next) {
int slotIndex = skeletonData.findSlotIndex(slotEntry.name); SlotData slot = skeletonData.findSlot(slotEntry.name);
if (slotIndex == -1) throw new SerializationException("Slot not found: " + slotEntry.name); if (slot == null) throw new SerializationException("Slot not found: " + slotEntry.name);
for (JsonValue entry = slotEntry.child; entry != null; entry = entry.next) { for (JsonValue entry = slotEntry.child; entry != null; entry = entry.next) {
try { try {
Attachment attachment = readAttachment(entry, skin, slotIndex, entry.name); Attachment attachment = readAttachment(entry, skin, slot.index, entry.name);
if (attachment != null) skin.addAttachment(slotIndex, entry.name, attachment); if (attachment != null) skin.addAttachment(slot.index, entry.name, attachment);
} catch (Exception ex) { } catch (Exception ex) {
throw new SerializationException("Error reading attachment: " + entry.name + ", skin: " + skin, ex); throw new SerializationException("Error reading attachment: " + entry.name + ", skin: " + skin, ex);
} }
@ -417,13 +417,13 @@ public class SkeletonJson {
// Slot timelines. // Slot timelines.
for (JsonValue slotMap = map.getChild("slots"); slotMap != null; slotMap = slotMap.next) { for (JsonValue slotMap = map.getChild("slots"); slotMap != null; slotMap = slotMap.next) {
int slotIndex = skeletonData.findSlotIndex(slotMap.name); SlotData slot = skeletonData.findSlot(slotMap.name);
if (slotIndex == -1) throw new SerializationException("Slot not found: " + slotMap.name); if (slot == null) throw new SerializationException("Slot not found: " + slotMap.name);
for (JsonValue timelineMap = slotMap.child; timelineMap != null; timelineMap = timelineMap.next) { for (JsonValue timelineMap = slotMap.child; timelineMap != null; timelineMap = timelineMap.next) {
String timelineName = timelineMap.name; String timelineName = timelineMap.name;
if (timelineName.equals("color")) { if (timelineName.equals("color")) {
ColorTimeline timeline = new ColorTimeline(timelineMap.size); ColorTimeline timeline = new ColorTimeline(timelineMap.size);
timeline.slotIndex = slotIndex; timeline.slotIndex = slot.index;
int frameIndex = 0; int frameIndex = 0;
for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next) { for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next) {
@ -437,7 +437,7 @@ public class SkeletonJson {
} else if (timelineName.equals("attachment")) { } else if (timelineName.equals("attachment")) {
AttachmentTimeline timeline = new AttachmentTimeline(timelineMap.size); AttachmentTimeline timeline = new AttachmentTimeline(timelineMap.size);
timeline.slotIndex = slotIndex; timeline.slotIndex = slot.index;
int frameIndex = 0; int frameIndex = 0;
for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next) for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next)
@ -451,13 +451,13 @@ public class SkeletonJson {
// Bone timelines. // 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); BoneData bone = skeletonData.findBone(boneMap.name);
if (boneIndex == -1) throw new SerializationException("Bone not found: " + boneMap.name); if (bone == null) throw new SerializationException("Bone not found: " + boneMap.name);
for (JsonValue timelineMap = boneMap.child; timelineMap != null; timelineMap = timelineMap.next) { for (JsonValue timelineMap = boneMap.child; timelineMap != null; timelineMap = timelineMap.next) {
String timelineName = timelineMap.name; String timelineName = timelineMap.name;
if (timelineName.equals("rotate")) { if (timelineName.equals("rotate")) {
RotateTimeline timeline = new RotateTimeline(timelineMap.size); RotateTimeline timeline = new RotateTimeline(timelineMap.size);
timeline.boneIndex = boneIndex; timeline.boneIndex = bone.index;
int frameIndex = 0; int frameIndex = 0;
for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next) { for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next) {
@ -479,7 +479,7 @@ public class SkeletonJson {
timeline = new TranslateTimeline(timelineMap.size); timeline = new TranslateTimeline(timelineMap.size);
timelineScale = scale; timelineScale = scale;
} }
timeline.boneIndex = boneIndex; timeline.boneIndex = bone.index;
int frameIndex = 0; int frameIndex = 0;
for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next) { for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next) {
@ -531,9 +531,9 @@ public class SkeletonJson {
// Path constraint timelines. // Path constraint timelines.
for (JsonValue constraintMap = map.getChild("paths"); constraintMap != null; constraintMap = constraintMap.next) { for (JsonValue constraintMap = map.getChild("paths"); constraintMap != null; constraintMap = constraintMap.next) {
int index = skeletonData.findPathConstraintIndex(constraintMap.name); PathConstraintData data = skeletonData.findPathConstraint(constraintMap.name);
if (index == -1) throw new SerializationException("Path constraint not found: " + constraintMap.name); if (data == null) throw new SerializationException("Path constraint not found: " + constraintMap.name);
PathConstraintData data = skeletonData.getPathConstraints().get(index); int index = skeletonData.pathConstraints.indexOf(data, true);
for (JsonValue timelineMap = constraintMap.child; timelineMap != null; timelineMap = timelineMap.next) { for (JsonValue timelineMap = constraintMap.child; timelineMap != null; timelineMap = timelineMap.next) {
String timelineName = timelineMap.name; String timelineName = timelineMap.name;
if (timelineName.equals("position") || timelineName.equals("spacing")) { if (timelineName.equals("position") || timelineName.equals("spacing")) {
@ -578,17 +578,17 @@ public class SkeletonJson {
Skin skin = skeletonData.findSkin(deformMap.name); Skin skin = skeletonData.findSkin(deformMap.name);
if (skin == null) throw new SerializationException("Skin not found: " + deformMap.name); if (skin == null) throw new SerializationException("Skin not found: " + deformMap.name);
for (JsonValue slotMap = deformMap.child; slotMap != null; slotMap = slotMap.next) { for (JsonValue slotMap = deformMap.child; slotMap != null; slotMap = slotMap.next) {
int slotIndex = skeletonData.findSlotIndex(slotMap.name); SlotData slot = skeletonData.findSlot(slotMap.name);
if (slotIndex == -1) throw new SerializationException("Slot not found: " + slotMap.name); if (slot == null) throw new SerializationException("Slot not found: " + slotMap.name);
for (JsonValue timelineMap = slotMap.child; timelineMap != null; timelineMap = timelineMap.next) { for (JsonValue timelineMap = slotMap.child; timelineMap != null; timelineMap = timelineMap.next) {
VertexAttachment attachment = (VertexAttachment)skin.getAttachment(slotIndex, timelineMap.name); VertexAttachment attachment = (VertexAttachment)skin.getAttachment(slot.index, timelineMap.name);
if (attachment == null) throw new SerializationException("Deform attachment not found: " + timelineMap.name); if (attachment == null) throw new SerializationException("Deform attachment not found: " + timelineMap.name);
boolean weighted = attachment.getBones() != null; boolean weighted = attachment.getBones() != null;
float[] vertices = attachment.getVertices(); float[] vertices = attachment.getVertices();
int deformLength = weighted ? vertices.length / 3 * 2 : vertices.length; int deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
DeformTimeline timeline = new DeformTimeline(timelineMap.size); DeformTimeline timeline = new DeformTimeline(timelineMap.size);
timeline.slotIndex = slotIndex; timeline.slotIndex = slot.index;
timeline.attachment = attachment; timeline.attachment = attachment;
int frameIndex = 0; int frameIndex = 0;
@ -638,10 +638,10 @@ public class SkeletonJson {
int[] unchanged = new int[slotCount - offsets.size]; int[] unchanged = new int[slotCount - offsets.size];
int originalIndex = 0, unchangedIndex = 0; int originalIndex = 0, unchangedIndex = 0;
for (JsonValue offsetMap = offsets.child; offsetMap != null; offsetMap = offsetMap.next) { for (JsonValue offsetMap = offsets.child; offsetMap != null; offsetMap = offsetMap.next) {
int slotIndex = skeletonData.findSlotIndex(offsetMap.getString("slot")); SlotData slot = skeletonData.findSlot(offsetMap.getString("slot"));
if (slotIndex == -1) throw new SerializationException("Slot not found: " + offsetMap.getString("slot")); if (slot == null) throw new SerializationException("Slot not found: " + offsetMap.getString("slot"));
// Collect unchanged items. // Collect unchanged items.
while (originalIndex != slotIndex) while (originalIndex != slot.index)
unchanged[unchangedIndex++] = originalIndex++; unchanged[unchangedIndex++] = originalIndex++;
// Set changed items. // Set changed items.
drawOrder[originalIndex + offsetMap.getInt("offset")] = originalIndex++; drawOrder[originalIndex + offsetMap.getInt("offset")] = originalIndex++;