From 705195c34855e795acd3dde6f022065eafa314e3 Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Tue, 30 Apr 2019 17:26:54 +0200 Subject: [PATCH] Clean up. --- .../com/esotericsoftware/spine/Animation.java | 2 +- .../com/esotericsoftware/spine/BoneData.java | 2 +- .../com/esotericsoftware/spine/EventData.java | 2 +- .../src/com/esotericsoftware/spine/Skin.java | 49 +++++++++---------- .../com/esotericsoftware/spine/SlotData.java | 2 +- .../spine/attachments/Attachment.java | 2 +- .../spine/attachments/PointAttachment.java | 1 - .../spine/attachments/RegionAttachment.java | 4 +- .../spine/attachments/VertexAttachment.java | 5 +- 9 files changed, 33 insertions(+), 36 deletions(-) diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Animation.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Animation.java index 14f4b0ad6..f3f3e2962 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Animation.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Animation.java @@ -86,7 +86,7 @@ public class Animation { timelines.get(i).apply(skeleton, lastTime, time, events, alpha, blend, direction); } - /** The animation's name, which is unique within the skeleton. */ + /** The animation's name, which is unique across all animations in the skeleton. */ public String getName () { return name; } diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/BoneData.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/BoneData.java index b9d74fa39..c37ca4101 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/BoneData.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/BoneData.java @@ -76,7 +76,7 @@ public class BoneData { return index; } - /** The name of the bone, which is unique within the skeleton. */ + /** The name of the bone, which is unique across all bones in the skeleton. */ public String getName () { return name; } diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/EventData.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/EventData.java index df85cca7d..78effad31 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/EventData.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/EventData.java @@ -93,7 +93,7 @@ public class EventData { this.balance = balance; } - /** The name of the event, which is unique within the skeleton. */ + /** The name of the event, which is unique across all events in the skeleton. */ public String getName () { return name; } diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skin.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skin.java index fedae4138..c6227c0de 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skin.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skin.java @@ -32,6 +32,7 @@ package com.esotericsoftware.spine; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.OrderedMap; + import com.esotericsoftware.spine.attachments.Attachment; import com.esotericsoftware.spine.attachments.MeshAttachment; @@ -68,7 +69,7 @@ public class Skin { if (!constraints.contains(data, true)) constraints.add(data); for (SkinEntry entry : skin.attachments.keys()) - setAttachment(entry.getSlotIndex(), entry.getName(), entry.getAttachment()); + setAttachment(entry.slotIndex, entry.name, entry.attachment); } /** Adds all attachments, bones, and constraints from the specified skin to this skin. Attachments are deep copied. */ @@ -80,16 +81,16 @@ public class Skin { if (!constraints.contains(data, true)) constraints.add(data); for (SkinEntry entry : skin.attachments.keys()) { - Attachment attachment = entry.getAttachment().copy(); - setAttachment(entry.getSlotIndex(), entry.getName(), attachment); + Attachment attachment = entry.attachment.copy(); + setAttachment(entry.slotIndex, entry.name, attachment); } for (SkinEntry entry : attachments.keys()) { - Attachment attachment = entry.getAttachment(); + Attachment attachment = entry.attachment; if (attachment instanceof MeshAttachment) { MeshAttachment mesh = (MeshAttachment)attachment; if (mesh.getParentMesh() != null) { - mesh.setParentMesh((MeshAttachment)getAttachment(entry.getSlotIndex(), mesh.getParentMesh().getName())); + mesh.setParentMesh((MeshAttachment)getAttachment(entry.slotIndex, mesh.getParentMesh().getName())); mesh.updateUVs(); } } @@ -99,14 +100,14 @@ public class Skin { /** Returns the attachment for the specified slot index and name, or null. */ public Attachment getAttachment (int slotIndex, String name) { if (slotIndex < 0) throw new IllegalArgumentException("slotIndex must be >= 0."); - lookup.set(slotIndex, name, null); + lookup.set(slotIndex, name); return attachments.get(lookup); } /** Removes the attachment in the skin for the specified slot index and name, if any. */ public void removeAttachment (int slotIndex, String name) { if (slotIndex < 0) throw new IllegalArgumentException("slotIndex must be >= 0."); - lookup.set(slotIndex, name, null); + lookup.set(slotIndex, name); attachments.remove(lookup); } @@ -115,12 +116,13 @@ public class Skin { return attachments.orderedKeys(); } - /** Returns all attachments for the given slot in this skin. */ + /** Returns all attachments in this skin for the specified slot index. */ public void getAttachments (int slotIndex, Array attachments) { for (SkinEntry entry : this.attachments.keys()) - if (entry.getSlotIndex() == slotIndex) attachments.add(entry); + if (entry.slotIndex == slotIndex) attachments.add(entry); } + /** Clears all attachments, bones, and constraints. */ public void clear () { attachments.clear(1024); bones.clear(); @@ -135,11 +137,7 @@ public class Skin { return constraints; } - public int size () { - return attachments.size; - } - - /** The skin's name, which is unique within the skeleton. */ + /** The skin's name, which is unique across all skins in the skeleton. */ public String getName () { return name; } @@ -151,35 +149,35 @@ public class Skin { /** Attach each attachment in this skin if the corresponding attachment in the old skin is currently attached. */ void attachAll (Skeleton skeleton, Skin oldSkin) { for (SkinEntry entry : oldSkin.attachments.keys()) { - int slotIndex = entry.getSlotIndex(); + int slotIndex = entry.slotIndex; Slot slot = skeleton.slots.get(slotIndex); - if (slot.attachment == entry.getAttachment()) { - Attachment attachment = getAttachment(slotIndex, entry.getName()); + if (slot.attachment == entry.attachment) { + Attachment attachment = getAttachment(slotIndex, entry.name); if (attachment != null) slot.setAttachment(attachment); } } } /** Stores an entry in the skin consisting of the slot index, name, and attachment **/ - public static class SkinEntry { - private int slotIndex; - private String name; - private Attachment attachment; + static public class SkinEntry { + int slotIndex; + String name; + Attachment attachment; private int hashCode; SkinEntry () { - set(0, "", null); + set(0, ""); } SkinEntry (int slotIndex, String name, Attachment attachment) { - set(slotIndex, name, attachment); + set(slotIndex, name); + this.attachment = attachment; } - void set (int slotIndex, String name, Attachment attachment) { + void set (int slotIndex, String name) { if (name == null) throw new IllegalArgumentException("name cannot be null."); this.slotIndex = slotIndex; this.name = name; - this.attachment = attachment; this.hashCode = name.hashCode() + slotIndex * 37; } @@ -187,6 +185,7 @@ public class Skin { return slotIndex; } + /** The name the attachment is associated with, equivalent to the skin placeholder name in the Spine editor. */ public String getName () { return name; } diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SlotData.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SlotData.java index 3d5bc5fca..08b4ee913 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SlotData.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SlotData.java @@ -56,7 +56,7 @@ public class SlotData { return index; } - /** The name of the slot, which is unique within the skeleton. */ + /** The name of the slot, which is unique across all slots in the skeleton. */ public String getName () { return name; } diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/Attachment.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/Attachment.java index f26511877..9509d782b 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/Attachment.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/Attachment.java @@ -45,7 +45,7 @@ abstract public class Attachment { } public String toString () { - return getName(); + return name; } /** Returns a copy of the attachment. **/ diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/PointAttachment.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/PointAttachment.java index 931969b27..d23853fd1 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/PointAttachment.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/PointAttachment.java @@ -98,7 +98,6 @@ public class PointAttachment extends Attachment { public Attachment copy () { PointAttachment copy = new PointAttachment(name); - copy.name = name; copy.x = x; copy.y = y; copy.rotation = rotation; diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionAttachment.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionAttachment.java index 3405757a7..8d39e25d1 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionAttachment.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionAttachment.java @@ -276,8 +276,8 @@ public class RegionAttachment extends Attachment { copy.rotation = rotation; copy.width = width; copy.height = height; - System.arraycopy(uvs, 0, copy.uvs, 0, uvs.length); - System.arraycopy(offset, 0, copy.offset, 0, offset.length); + System.arraycopy(uvs, 0, copy.uvs, 0, 8); + System.arraycopy(offset, 0, copy.offset, 0, 8); copy.color.set(color); return copy; } diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/VertexAttachment.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/VertexAttachment.java index 606df4375..88f90c8a8 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/VertexAttachment.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/VertexAttachment.java @@ -37,7 +37,7 @@ import com.esotericsoftware.spine.Slot; /** Base class for an attachment with vertices that are transformed by one or more bones and can be deformed by a slot's * {@link Slot#getDeform()}. */ -public abstract class VertexAttachment extends Attachment { +abstract public class VertexAttachment extends Attachment { static private int nextID; private final int id = (nextID() & 65535) << 11; @@ -161,8 +161,7 @@ public abstract class VertexAttachment extends Attachment { return id; } - /** Internal method used by VertexAttachment subclasses to copy basic data. Does not copy id (generated) and name (set on - * construction). **/ + /** Does not copy id (generated) or name (set on construction). **/ void copyTo (VertexAttachment attachment) { if (bones != null) { attachment.bones = new int[bones.length];