From 65752c6d39208016a9ac8d78a42a1719aca8895b Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Thu, 5 Dec 2019 13:27:09 +0100 Subject: [PATCH] A little more minor skin clean up. --- .../src/com/esotericsoftware/spine/Skin.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) 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 2a9096c4a..0a68fd7d4 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skin.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skin.java @@ -44,7 +44,7 @@ public class Skin { final OrderedSet attachments = new OrderedSet(); final Array bones = new Array(0); final Array constraints = new Array(0); - private final SkinEntry lookup = new SkinEntry(); + private final SkinEntry lookup = new SkinEntry(0, "", null); public Skin (String name) { if (name == null) throw new IllegalArgumentException("name cannot be null."); @@ -54,10 +54,9 @@ public class Skin { /** Adds an attachment to the skin for the specified slot index and name. */ public void setAttachment (int slotIndex, String name, Attachment attachment) { - if (slotIndex < 0) throw new IllegalArgumentException("slotIndex must be >= 0."); if (attachment == null) throw new IllegalArgumentException("attachment cannot be null."); - SkinEntry newEntry = new SkinEntry(slotIndex, name, attachment); - if (!attachments.add(newEntry)) attachments.get(newEntry).attachment = attachment; + SkinEntry entry = new SkinEntry(slotIndex, name, attachment); + if (!attachments.add(entry)) attachments.get(entry).attachment = attachment; } /** Adds all attachments, bones, and constraints from the specified skin to this skin. */ @@ -95,7 +94,6 @@ 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); SkinEntry entry = attachments.get(lookup); return entry != null ? entry.attachment : null; @@ -103,7 +101,6 @@ public class Skin { /** 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); attachments.remove(lookup); } @@ -164,16 +161,14 @@ public class Skin { Attachment attachment; private int hashCode; - SkinEntry () { - set(0, ""); - } - + /** @param attachment May be null. */ SkinEntry (int slotIndex, String name, Attachment attachment) { set(slotIndex, name); this.attachment = attachment; } void set (int slotIndex, String name) { + if (slotIndex < 0) throw new IllegalArgumentException("slotIndex must be >= 0."); if (name == null) throw new IllegalArgumentException("name cannot be null."); this.slotIndex = slotIndex; this.name = name;