Minor skin clean up.

This commit is contained in:
NathanSweet 2019-11-29 21:07:30 +01:00
parent d99fd64e2d
commit 26aaed331f
3 changed files with 17 additions and 18 deletions

View File

@ -294,7 +294,7 @@ public class Skeleton {
} }
private void sortPathConstraintAttachment (Skin skin, int slotIndex, Bone slotBone) { private void sortPathConstraintAttachment (Skin skin, int slotIndex, Bone slotBone) {
for (SkinEntry entry : skin.attachments.keys()) for (SkinEntry entry : skin.attachments.orderedItems())
if (entry.getSlotIndex() == slotIndex) sortPathConstraintAttachment(entry.getAttachment(), slotBone); if (entry.getSlotIndex() == slotIndex) sortPathConstraintAttachment(entry.getAttachment(), slotBone);
} }

View File

@ -280,6 +280,7 @@ public class SkeletonJson {
if (bone == null) throw new SerializationException("Skin bone not found: " + entry); if (bone == null) throw new SerializationException("Skin bone not found: " + entry);
skin.bones.add(bone); skin.bones.add(bone);
} }
skin.bones.shrink();
for (JsonValue entry = skinMap.getChild("ik"); entry != null; entry = entry.next) { for (JsonValue entry = skinMap.getChild("ik"); entry != null; entry = entry.next) {
IkConstraintData constraint = skeletonData.findIkConstraint(entry.asString()); IkConstraintData constraint = skeletonData.findIkConstraint(entry.asString());
if (constraint == null) throw new SerializationException("Skin IK constraint not found: " + entry); if (constraint == null) throw new SerializationException("Skin IK constraint not found: " + entry);
@ -295,6 +296,7 @@ public class SkeletonJson {
if (constraint == null) throw new SerializationException("Skin path constraint not found: " + entry); if (constraint == null) throw new SerializationException("Skin path constraint not found: " + entry);
skin.constraints.add(constraint); skin.constraints.add(constraint);
} }
skin.constraints.shrink();
for (JsonValue slotEntry = skinMap.getChild("attachments"); slotEntry != null; slotEntry = slotEntry.next) { for (JsonValue slotEntry = skinMap.getChild("attachments"); slotEntry != null; slotEntry = slotEntry.next) {
SlotData slot = skeletonData.findSlot(slotEntry.name); SlotData slot = skeletonData.findSlot(slotEntry.name);
if (slot == null) throw new SerializationException("Slot not found: " + slotEntry.name); if (slot == null) throw new SerializationException("Slot not found: " + slotEntry.name);

View File

@ -30,7 +30,8 @@
package com.esotericsoftware.spine; package com.esotericsoftware.spine;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.OrderedMap; import com.badlogic.gdx.utils.OrderedSet;
import com.esotericsoftware.spine.attachments.Attachment; import com.esotericsoftware.spine.attachments.Attachment;
import com.esotericsoftware.spine.attachments.MeshAttachment; import com.esotericsoftware.spine.attachments.MeshAttachment;
@ -40,15 +41,15 @@ import com.esotericsoftware.spine.attachments.MeshAttachment;
* <a href="http://esotericsoftware.com/spine-runtime-skins">Runtime skins</a> in the Spine Runtimes Guide. */ * <a href="http://esotericsoftware.com/spine-runtime-skins">Runtime skins</a> in the Spine Runtimes Guide. */
public class Skin { public class Skin {
final String name; final String name;
final OrderedMap<SkinEntry, SkinEntry> attachments = new OrderedMap(); final OrderedSet<SkinEntry> attachments = new OrderedSet();
final Array<BoneData> bones = new Array(); final Array<BoneData> bones = new Array(0);
final Array<ConstraintData> constraints = new Array(); final Array<ConstraintData> constraints = new Array(0);
private final SkinEntry lookup = new SkinEntry(); private final SkinEntry lookup = new SkinEntry();
public Skin (String name) { public Skin (String name) {
if (name == null) throw new IllegalArgumentException("name cannot be null."); if (name == null) throw new IllegalArgumentException("name cannot be null.");
this.name = name; this.name = name;
this.attachments.orderedKeys().ordered = false; attachments.orderedItems().ordered = false;
} }
/** Adds an attachment to the skin for the specified slot index and name. */ /** Adds an attachment to the skin for the specified slot index and name. */
@ -56,10 +57,7 @@ public class Skin {
if (slotIndex < 0) throw new IllegalArgumentException("slotIndex must be >= 0."); if (slotIndex < 0) throw new IllegalArgumentException("slotIndex must be >= 0.");
if (attachment == null) throw new IllegalArgumentException("attachment cannot be null."); if (attachment == null) throw new IllegalArgumentException("attachment cannot be null.");
SkinEntry newEntry = new SkinEntry(slotIndex, name, attachment); SkinEntry newEntry = new SkinEntry(slotIndex, name, attachment);
SkinEntry oldEntry = attachments.put(newEntry, newEntry); if (!attachments.add(newEntry)) attachments.get(newEntry).attachment = attachment;
if (oldEntry != null) {
oldEntry.attachment = attachment;
}
} }
/** Adds all attachments, bones, and constraints from the specified skin to this skin. */ /** Adds all attachments, bones, and constraints from the specified skin to this skin. */
@ -72,7 +70,7 @@ public class Skin {
for (ConstraintData data : skin.constraints) for (ConstraintData data : skin.constraints)
if (!constraints.contains(data, true)) constraints.add(data); if (!constraints.contains(data, true)) constraints.add(data);
for (SkinEntry entry : skin.attachments.keys()) for (SkinEntry entry : skin.attachments.orderedItems())
setAttachment(entry.slotIndex, entry.name, entry.attachment); setAttachment(entry.slotIndex, entry.name, entry.attachment);
} }
@ -87,7 +85,7 @@ public class Skin {
for (ConstraintData data : skin.constraints) for (ConstraintData data : skin.constraints)
if (!constraints.contains(data, true)) constraints.add(data); if (!constraints.contains(data, true)) constraints.add(data);
for (SkinEntry entry : skin.attachments.keys()) { for (SkinEntry entry : skin.attachments.orderedItems()) {
if (entry.attachment instanceof MeshAttachment) if (entry.attachment instanceof MeshAttachment)
setAttachment(entry.slotIndex, entry.name, ((MeshAttachment)entry.attachment).newLinkedMesh()); setAttachment(entry.slotIndex, entry.name, ((MeshAttachment)entry.attachment).newLinkedMesh());
else else
@ -112,14 +110,14 @@ public class Skin {
/** Returns all attachments in this skin. */ /** Returns all attachments in this skin. */
public Array<SkinEntry> getAttachments () { public Array<SkinEntry> getAttachments () {
return attachments.orderedKeys(); return attachments.orderedItems();
} }
/** Returns all attachments in this skin for the specified slot index. */ /** Returns all attachments in this skin for the specified slot index. */
public void getAttachments (int slotIndex, Array<SkinEntry> attachments) { public void getAttachments (int slotIndex, Array<SkinEntry> attachments) {
if (slotIndex < 0) throw new IllegalArgumentException("slotIndex must be >= 0."); if (slotIndex < 0) throw new IllegalArgumentException("slotIndex must be >= 0.");
if (attachments == null) throw new IllegalArgumentException("attachments cannot be null."); if (attachments == null) throw new IllegalArgumentException("attachments cannot be null.");
for (SkinEntry entry : this.attachments.keys()) for (SkinEntry entry : this.attachments.orderedItems())
if (entry.slotIndex == slotIndex) attachments.add(entry); if (entry.slotIndex == slotIndex) attachments.add(entry);
} }
@ -149,7 +147,7 @@ public class Skin {
/** Attach each attachment in this skin if the corresponding attachment in the old skin is currently attached. */ /** Attach each attachment in this skin if the corresponding attachment in the old skin is currently attached. */
void attachAll (Skeleton skeleton, Skin oldSkin) { void attachAll (Skeleton skeleton, Skin oldSkin) {
for (SkinEntry entry : oldSkin.attachments.keys()) { for (SkinEntry entry : oldSkin.attachments.orderedItems()) {
int slotIndex = entry.slotIndex; int slotIndex = entry.slotIndex;
Slot slot = skeleton.slots.get(slotIndex); Slot slot = skeleton.slots.get(slotIndex);
if (slot.attachment == entry.attachment) { if (slot.attachment == entry.attachment) {
@ -179,7 +177,7 @@ public class Skin {
if (name == null) throw new IllegalArgumentException("name cannot be null."); if (name == null) throw new IllegalArgumentException("name cannot be null.");
this.slotIndex = slotIndex; this.slotIndex = slotIndex;
this.name = name; this.name = name;
this.hashCode = name.hashCode() + slotIndex * 37; hashCode = name.hashCode() + slotIndex * 37;
} }
public int getSlotIndex () { public int getSlotIndex () {
@ -203,8 +201,7 @@ public class Skin {
if (object == null) return false; if (object == null) return false;
SkinEntry other = (SkinEntry)object; SkinEntry other = (SkinEntry)object;
if (slotIndex != other.slotIndex) return false; if (slotIndex != other.slotIndex) return false;
if (!name.equals(other.name)) return false; return name.equals(other.name);
return true;
} }
public String toString () { public String toString () {