Clean up.

This commit is contained in:
NathanSweet 2019-04-30 17:26:54 +02:00
parent f0533b6093
commit 705195c348
9 changed files with 33 additions and 36 deletions

View File

@ -86,7 +86,7 @@ public class Animation {
timelines.get(i).apply(skeleton, lastTime, time, events, alpha, blend, direction); 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 () { public String getName () {
return name; return name;
} }

View File

@ -76,7 +76,7 @@ public class BoneData {
return index; 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 () { public String getName () {
return name; return name;
} }

View File

@ -93,7 +93,7 @@ public class EventData {
this.balance = balance; 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 () { public String getName () {
return name; return name;
} }

View File

@ -32,6 +32,7 @@ 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.OrderedMap;
import com.esotericsoftware.spine.attachments.Attachment; import com.esotericsoftware.spine.attachments.Attachment;
import com.esotericsoftware.spine.attachments.MeshAttachment; import com.esotericsoftware.spine.attachments.MeshAttachment;
@ -68,7 +69,7 @@ public class Skin {
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.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. */ /** 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); if (!constraints.contains(data, true)) constraints.add(data);
for (SkinEntry entry : skin.attachments.keys()) { for (SkinEntry entry : skin.attachments.keys()) {
Attachment attachment = entry.getAttachment().copy(); Attachment attachment = entry.attachment.copy();
setAttachment(entry.getSlotIndex(), entry.getName(), attachment); setAttachment(entry.slotIndex, entry.name, attachment);
} }
for (SkinEntry entry : attachments.keys()) { for (SkinEntry entry : attachments.keys()) {
Attachment attachment = entry.getAttachment(); Attachment attachment = entry.attachment;
if (attachment instanceof MeshAttachment) { if (attachment instanceof MeshAttachment) {
MeshAttachment mesh = (MeshAttachment)attachment; MeshAttachment mesh = (MeshAttachment)attachment;
if (mesh.getParentMesh() != null) { if (mesh.getParentMesh() != null) {
mesh.setParentMesh((MeshAttachment)getAttachment(entry.getSlotIndex(), mesh.getParentMesh().getName())); mesh.setParentMesh((MeshAttachment)getAttachment(entry.slotIndex, mesh.getParentMesh().getName()));
mesh.updateUVs(); mesh.updateUVs();
} }
} }
@ -99,14 +100,14 @@ public class Skin {
/** Returns the attachment for the specified slot index and name, or null. */ /** Returns the attachment for the specified slot index and name, or null. */
public Attachment getAttachment (int slotIndex, String name) { public Attachment getAttachment (int slotIndex, String name) {
if (slotIndex < 0) throw new IllegalArgumentException("slotIndex must be >= 0."); if (slotIndex < 0) throw new IllegalArgumentException("slotIndex must be >= 0.");
lookup.set(slotIndex, name, null); lookup.set(slotIndex, name);
return attachments.get(lookup); return attachments.get(lookup);
} }
/** Removes the attachment in the skin for the specified slot index and name, if any. */ /** Removes the attachment in the skin for the specified slot index and name, if any. */
public void removeAttachment (int slotIndex, String name) { public void removeAttachment (int slotIndex, String name) {
if (slotIndex < 0) throw new IllegalArgumentException("slotIndex must be >= 0."); if (slotIndex < 0) throw new IllegalArgumentException("slotIndex must be >= 0.");
lookup.set(slotIndex, name, null); lookup.set(slotIndex, name);
attachments.remove(lookup); attachments.remove(lookup);
} }
@ -115,12 +116,13 @@ public class Skin {
return attachments.orderedKeys(); 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<SkinEntry> attachments) { public void getAttachments (int slotIndex, Array<SkinEntry> attachments) {
for (SkinEntry entry : this.attachments.keys()) 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 () { public void clear () {
attachments.clear(1024); attachments.clear(1024);
bones.clear(); bones.clear();
@ -135,11 +137,7 @@ public class Skin {
return constraints; return constraints;
} }
public int size () { /** The skin's name, which is unique across all skins in the skeleton. */
return attachments.size;
}
/** The skin's name, which is unique within the skeleton. */
public String getName () { public String getName () {
return name; 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. */ /** 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.keys()) {
int slotIndex = entry.getSlotIndex(); int slotIndex = entry.slotIndex;
Slot slot = skeleton.slots.get(slotIndex); Slot slot = skeleton.slots.get(slotIndex);
if (slot.attachment == entry.getAttachment()) { if (slot.attachment == entry.attachment) {
Attachment attachment = getAttachment(slotIndex, entry.getName()); Attachment attachment = getAttachment(slotIndex, entry.name);
if (attachment != null) slot.setAttachment(attachment); if (attachment != null) slot.setAttachment(attachment);
} }
} }
} }
/** Stores an entry in the skin consisting of the slot index, name, and attachment **/ /** Stores an entry in the skin consisting of the slot index, name, and attachment **/
public static class SkinEntry { static public class SkinEntry {
private int slotIndex; int slotIndex;
private String name; String name;
private Attachment attachment; Attachment attachment;
private int hashCode; private int hashCode;
SkinEntry () { SkinEntry () {
set(0, "", null); set(0, "");
} }
SkinEntry (int slotIndex, String name, Attachment attachment) { 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."); if (name == null) throw new IllegalArgumentException("name cannot be null.");
this.slotIndex = slotIndex; this.slotIndex = slotIndex;
this.name = name; this.name = name;
this.attachment = attachment;
this.hashCode = name.hashCode() + slotIndex * 37; this.hashCode = name.hashCode() + slotIndex * 37;
} }
@ -187,6 +185,7 @@ public class Skin {
return slotIndex; return slotIndex;
} }
/** The name the attachment is associated with, equivalent to the skin placeholder name in the Spine editor. */
public String getName () { public String getName () {
return name; return name;
} }

View File

@ -56,7 +56,7 @@ public class SlotData {
return index; 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 () { public String getName () {
return name; return name;
} }

View File

@ -45,7 +45,7 @@ abstract public class Attachment {
} }
public String toString () { public String toString () {
return getName(); return name;
} }
/** Returns a copy of the attachment. **/ /** Returns a copy of the attachment. **/

View File

@ -98,7 +98,6 @@ public class PointAttachment extends Attachment {
public Attachment copy () { public Attachment copy () {
PointAttachment copy = new PointAttachment(name); PointAttachment copy = new PointAttachment(name);
copy.name = name;
copy.x = x; copy.x = x;
copy.y = y; copy.y = y;
copy.rotation = rotation; copy.rotation = rotation;

View File

@ -276,8 +276,8 @@ public class RegionAttachment extends Attachment {
copy.rotation = rotation; copy.rotation = rotation;
copy.width = width; copy.width = width;
copy.height = height; copy.height = height;
System.arraycopy(uvs, 0, copy.uvs, 0, uvs.length); System.arraycopy(uvs, 0, copy.uvs, 0, 8);
System.arraycopy(offset, 0, copy.offset, 0, offset.length); System.arraycopy(offset, 0, copy.offset, 0, 8);
copy.color.set(color); copy.color.set(color);
return copy; return copy;
} }

View File

@ -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 /** 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()}. */ * {@link Slot#getDeform()}. */
public abstract class VertexAttachment extends Attachment { abstract public class VertexAttachment extends Attachment {
static private int nextID; static private int nextID;
private final int id = (nextID() & 65535) << 11; private final int id = (nextID() & 65535) << 11;
@ -161,8 +161,7 @@ public abstract class VertexAttachment extends Attachment {
return id; return id;
} }
/** Internal method used by VertexAttachment subclasses to copy basic data. Does not copy id (generated) and name (set on /** Does not copy id (generated) or name (set on construction). **/
* construction). **/
void copyTo (VertexAttachment attachment) { void copyTo (VertexAttachment attachment) {
if (bones != null) { if (bones != null) {
attachment.bones = new int[bones.length]; attachment.bones = new int[bones.length];