Allow access to the skin in attachment loader.

This commit is contained in:
NathanSweet 2013-04-11 06:14:53 +02:00
parent 7453edd1e5
commit d5d5839a15
4 changed files with 9 additions and 8 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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;

View File

@ -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: