Browse Source

Allow access to the skin in attachment loader.

NathanSweet 12 years ago
parent
commit
d5d5839a15

+ 1 - 1
spine-libgdx/src/com/esotericsoftware/spine/AttachmentLoader.java

@@ -27,5 +27,5 @@ package com.esotericsoftware.spine;
 
 public interface AttachmentLoader {
 	/** @return May be null to not load any attachment. */
-	public Attachment newAttachment (AttachmentType type, String name);
+	public Attachment newAttachment (Skin skin, AttachmentType type, String name);
 }

+ 3 - 3
spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java

@@ -154,18 +154,18 @@ public class SkeletonBinary {
 			int attachmentCount = input.readInt(true);
 			for (int ii = 0; ii < attachmentCount; ii++) {
 				String name = input.readString();
-				skin.addAttachment(slotIndex, name, readAttachment(input, name));
+				skin.addAttachment(slotIndex, name, readAttachment(input, skin, name));
 			}
 		}
 		return skin;
 	}
 
-	private Attachment readAttachment (DataInput input, String attachmentName) throws IOException {
+	private Attachment readAttachment (DataInput input, Skin skin, String attachmentName) throws IOException {
 		String name = input.readString();
 		if (name == null) name = attachmentName;
 
 		AttachmentType type = AttachmentType.values()[input.readByte()];
-		Attachment attachment = attachmentLoader.newAttachment(type, name);
+		Attachment attachment = attachmentLoader.newAttachment(skin, type, name);
 
 		if (attachment instanceof RegionSequenceAttachment) {
 			RegionSequenceAttachment regionSequenceAttachment = (RegionSequenceAttachment)attachment;

+ 3 - 3
spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java

@@ -129,7 +129,7 @@ public class SkeletonJson {
 				for (Entry<String, OrderedMap> slotEntry : ((OrderedMap<String, OrderedMap>)entry.value).entries()) {
 					int slotIndex = skeletonData.findSlotIndex(slotEntry.key);
 					for (Entry<String, OrderedMap> attachmentEntry : ((OrderedMap<String, OrderedMap>)slotEntry.value).entries()) {
-						Attachment attachment = readAttachment(attachmentEntry.key, attachmentEntry.value);
+						Attachment attachment = readAttachment(skin, attachmentEntry.key, attachmentEntry.value);
 						if (attachment != null) skin.addAttachment(slotIndex, attachmentEntry.key, attachment);
 					}
 				}
@@ -152,11 +152,11 @@ public class SkeletonJson {
 		return skeletonData;
 	}
 
-	private Attachment readAttachment (String name, OrderedMap map) {
+	private Attachment readAttachment (Skin skin, String name, OrderedMap map) {
 		name = (String)map.get("name", name);
 
 		AttachmentType type = AttachmentType.valueOf((String)map.get("type", AttachmentType.region.name()));
-		Attachment attachment = attachmentLoader.newAttachment(type, name);
+		Attachment attachment = attachmentLoader.newAttachment(skin, type, name);
 
 		if (attachment instanceof RegionSequenceAttachment) {
 			RegionSequenceAttachment regionSequenceAttachment = (RegionSequenceAttachment)attachment;

+ 2 - 1
spine-libgdx/src/com/esotericsoftware/spine/attachments/AtlasAttachmentLoader.java

@@ -28,6 +28,7 @@ package com.esotericsoftware.spine.attachments;
 import com.esotericsoftware.spine.Attachment;
 import com.esotericsoftware.spine.AttachmentLoader;
 import com.esotericsoftware.spine.AttachmentType;
+import com.esotericsoftware.spine.Skin;
 
 import com.badlogic.gdx.graphics.g2d.TextureAtlas;
 import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
@@ -40,7 +41,7 @@ public class AtlasAttachmentLoader implements AttachmentLoader {
 		this.atlas = atlas;
 	}
 
-	public Attachment newAttachment (AttachmentType type, String name) {
+	public Attachment newAttachment (Skin skin, AttachmentType type, String name) {
 		Attachment attachment = null;
 		switch (type) {
 		case region: