mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-05 23:05:01 +08:00
Removed findXxxIndex.
These are just noise now that bones and slots have an index field.
This commit is contained in:
parent
2287256c72
commit
e14a783c38
@ -388,15 +388,6 @@ public class Skeleton {
|
||||
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 () {
|
||||
return slots;
|
||||
}
|
||||
@ -412,15 +403,6 @@ public class Skeleton {
|
||||
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. */
|
||||
public Array<Slot> getDrawOrder () {
|
||||
return drawOrder;
|
||||
@ -470,7 +452,9 @@ public class Skeleton {
|
||||
|
||||
/** @return May be null. */
|
||||
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. */
|
||||
@ -484,24 +468,20 @@ public class Skeleton {
|
||||
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) {
|
||||
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++) {
|
||||
Slot slot = slots.get(i);
|
||||
if (slot.data.name.equals(slotName)) {
|
||||
Attachment attachment = null;
|
||||
if (attachmentName != null) {
|
||||
attachment = getAttachment(i, attachmentName);
|
||||
if (attachment == null)
|
||||
throw new IllegalArgumentException("Attachment not found: " + attachmentName + ", for slot: " + slotName);
|
||||
}
|
||||
slot.setAttachment(attachment);
|
||||
return;
|
||||
}
|
||||
Slot slot = findSlot(slotName);
|
||||
if (slot == null) throw new IllegalArgumentException("Slot not found: " + slotName);
|
||||
Attachment attachment = null;
|
||||
if (attachmentName != null) {
|
||||
attachment = getAttachment(slot.data.index, attachmentName);
|
||||
if (attachment == null)
|
||||
throw new IllegalArgumentException("Attachment not found: " + attachmentName + ", for slot: " + slotName);
|
||||
}
|
||||
throw new IllegalArgumentException("Slot not found: " + slotName);
|
||||
slot.setAttachment(attachment);
|
||||
}
|
||||
|
||||
public Array<IkConstraint> getIkConstraints () {
|
||||
|
||||
@ -617,7 +617,7 @@ public class SkeletonBinary {
|
||||
// Path constraint timelines.
|
||||
for (int i = 0, n = input.readInt(true); i < n; i++) {
|
||||
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++) {
|
||||
int timelineType = input.readByte();
|
||||
int frameCount = input.readInt(true);
|
||||
|
||||
@ -67,15 +67,6 @@ public class SkeletonData {
|
||||
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.
|
||||
|
||||
public Array<SlotData> getSlots () {
|
||||
@ -93,15 +84,6 @@ public class SkeletonData {
|
||||
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.
|
||||
|
||||
/** @return May be null. */
|
||||
@ -209,15 +191,6 @@ public class SkeletonData {
|
||||
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. */
|
||||
|
||||
@ -241,12 +241,12 @@ public class SkeletonJson {
|
||||
for (JsonValue skinMap = root.getChild("skins"); skinMap != null; skinMap = skinMap.next) {
|
||||
Skin skin = new Skin(skinMap.name);
|
||||
for (JsonValue slotEntry = skinMap.child; slotEntry != null; slotEntry = slotEntry.next) {
|
||||
int slotIndex = skeletonData.findSlotIndex(slotEntry.name);
|
||||
if (slotIndex == -1) throw new SerializationException("Slot not found: " + slotEntry.name);
|
||||
SlotData slot = skeletonData.findSlot(slotEntry.name);
|
||||
if (slot == null) throw new SerializationException("Slot not found: " + slotEntry.name);
|
||||
for (JsonValue entry = slotEntry.child; entry != null; entry = entry.next) {
|
||||
try {
|
||||
Attachment attachment = readAttachment(entry, skin, slotIndex, entry.name);
|
||||
if (attachment != null) skin.addAttachment(slotIndex, entry.name, attachment);
|
||||
Attachment attachment = readAttachment(entry, skin, slot.index, entry.name);
|
||||
if (attachment != null) skin.addAttachment(slot.index, entry.name, attachment);
|
||||
} catch (Exception ex) {
|
||||
throw new SerializationException("Error reading attachment: " + entry.name + ", skin: " + skin, ex);
|
||||
}
|
||||
@ -417,13 +417,13 @@ public class SkeletonJson {
|
||||
|
||||
// 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);
|
||||
SlotData slot = skeletonData.findSlot(slotMap.name);
|
||||
if (slot == null) 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;
|
||||
timeline.slotIndex = slot.index;
|
||||
|
||||
int frameIndex = 0;
|
||||
for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next) {
|
||||
@ -437,7 +437,7 @@ public class SkeletonJson {
|
||||
|
||||
} else if (timelineName.equals("attachment")) {
|
||||
AttachmentTimeline timeline = new AttachmentTimeline(timelineMap.size);
|
||||
timeline.slotIndex = slotIndex;
|
||||
timeline.slotIndex = slot.index;
|
||||
|
||||
int frameIndex = 0;
|
||||
for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next)
|
||||
@ -451,13 +451,13 @@ public class SkeletonJson {
|
||||
|
||||
// Bone timelines.
|
||||
for (JsonValue boneMap = map.getChild("bones"); boneMap != null; boneMap = boneMap.next) {
|
||||
int boneIndex = skeletonData.findBoneIndex(boneMap.name);
|
||||
if (boneIndex == -1) throw new SerializationException("Bone not found: " + boneMap.name);
|
||||
BoneData bone = skeletonData.findBone(boneMap.name);
|
||||
if (bone == null) throw new SerializationException("Bone not found: " + boneMap.name);
|
||||
for (JsonValue timelineMap = boneMap.child; timelineMap != null; timelineMap = timelineMap.next) {
|
||||
String timelineName = timelineMap.name;
|
||||
if (timelineName.equals("rotate")) {
|
||||
RotateTimeline timeline = new RotateTimeline(timelineMap.size);
|
||||
timeline.boneIndex = boneIndex;
|
||||
timeline.boneIndex = bone.index;
|
||||
|
||||
int frameIndex = 0;
|
||||
for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next) {
|
||||
@ -479,7 +479,7 @@ public class SkeletonJson {
|
||||
timeline = new TranslateTimeline(timelineMap.size);
|
||||
timelineScale = scale;
|
||||
}
|
||||
timeline.boneIndex = boneIndex;
|
||||
timeline.boneIndex = bone.index;
|
||||
|
||||
int frameIndex = 0;
|
||||
for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next) {
|
||||
@ -531,9 +531,9 @@ public class SkeletonJson {
|
||||
|
||||
// Path constraint timelines.
|
||||
for (JsonValue constraintMap = map.getChild("paths"); constraintMap != null; constraintMap = constraintMap.next) {
|
||||
int index = skeletonData.findPathConstraintIndex(constraintMap.name);
|
||||
if (index == -1) throw new SerializationException("Path constraint not found: " + constraintMap.name);
|
||||
PathConstraintData data = skeletonData.getPathConstraints().get(index);
|
||||
PathConstraintData data = skeletonData.findPathConstraint(constraintMap.name);
|
||||
if (data == null) throw new SerializationException("Path constraint not found: " + constraintMap.name);
|
||||
int index = skeletonData.pathConstraints.indexOf(data, true);
|
||||
for (JsonValue timelineMap = constraintMap.child; timelineMap != null; timelineMap = timelineMap.next) {
|
||||
String timelineName = timelineMap.name;
|
||||
if (timelineName.equals("position") || timelineName.equals("spacing")) {
|
||||
@ -578,17 +578,17 @@ public class SkeletonJson {
|
||||
Skin skin = skeletonData.findSkin(deformMap.name);
|
||||
if (skin == null) throw new SerializationException("Skin not found: " + deformMap.name);
|
||||
for (JsonValue slotMap = deformMap.child; slotMap != null; slotMap = slotMap.next) {
|
||||
int slotIndex = skeletonData.findSlotIndex(slotMap.name);
|
||||
if (slotIndex == -1) throw new SerializationException("Slot not found: " + slotMap.name);
|
||||
SlotData slot = skeletonData.findSlot(slotMap.name);
|
||||
if (slot == null) throw new SerializationException("Slot not found: " + slotMap.name);
|
||||
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);
|
||||
boolean weighted = attachment.getBones() != null;
|
||||
float[] vertices = attachment.getVertices();
|
||||
int deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
|
||||
|
||||
DeformTimeline timeline = new DeformTimeline(timelineMap.size);
|
||||
timeline.slotIndex = slotIndex;
|
||||
timeline.slotIndex = slot.index;
|
||||
timeline.attachment = attachment;
|
||||
|
||||
int frameIndex = 0;
|
||||
@ -638,10 +638,10 @@ public class SkeletonJson {
|
||||
int[] unchanged = new int[slotCount - offsets.size];
|
||||
int originalIndex = 0, unchangedIndex = 0;
|
||||
for (JsonValue offsetMap = offsets.child; offsetMap != null; offsetMap = offsetMap.next) {
|
||||
int slotIndex = skeletonData.findSlotIndex(offsetMap.getString("slot"));
|
||||
if (slotIndex == -1) throw new SerializationException("Slot not found: " + offsetMap.getString("slot"));
|
||||
SlotData slot = skeletonData.findSlot(offsetMap.getString("slot"));
|
||||
if (slot == null) throw new SerializationException("Slot not found: " + offsetMap.getString("slot"));
|
||||
// Collect unchanged items.
|
||||
while (originalIndex != slotIndex)
|
||||
while (originalIndex != slot.index)
|
||||
unchanged[unchangedIndex++] = originalIndex++;
|
||||
// Set changed items.
|
||||
drawOrder[originalIndex + offsetMap.getInt("offset")] = originalIndex++;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user