From 695db31d714fe155e8625c4c2d82218b2f008dd7 Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Tue, 12 Mar 2013 23:20:21 +0100 Subject: [PATCH] libgdx runtime, attachment loader instead of resolver. Other minor fixes. --- .../spine-sfml/AtlasAttachmentLoader.h | 3 +- spine-cpp/includes/spine/Animation.h | 1 + spine-cpp/includes/spine/BaseAtlas.h | 2 +- spine-cpp/src/spine-sfml/RegionAttachment.cpp | 22 ++++------ spine-cpp/src/spine/Animation.cpp | 9 ++++ spine-cpp/src/spine/BaseSkeleton.cpp | 1 + spine-libgdx/.classpath | 5 +-- .../.settings/org.eclipse.jdt.core.prefs | 6 +-- .../esotericsoftware/spine/Attachment.java | 11 ----- .../spine/AttachmentLoader.java | 6 +++ .../spine/AttachmentResolver.java | 6 --- .../spine/AttachmentType.java | 6 +++ .../com/esotericsoftware/spine/Skeleton.java | 18 ++++---- .../spine/SkeletonBinary.java | 38 +++++++---------- .../esotericsoftware/spine/SkeletonData.java | 10 ----- .../esotericsoftware/spine/SkeletonJson.java | 39 ++++++++---------- .../attachments/RegionSequenceAttachment.java | 18 ++++---- .../TextureAtlasAttachmentLoader.java | 41 +++++++++++++++++++ .../TextureAtlasAttachmentResolver.java | 29 ------------- .../com/esotericsoftware/spine/MixTest.java | 10 ++--- .../esotericsoftware/spine/SkeletonTest.java | 8 ++-- spine-libgdx/test/spineboy-skeleton.json | 3 -- 22 files changed, 138 insertions(+), 154 deletions(-) create mode 100644 spine-libgdx/src/com/esotericsoftware/spine/AttachmentLoader.java delete mode 100644 spine-libgdx/src/com/esotericsoftware/spine/AttachmentResolver.java create mode 100644 spine-libgdx/src/com/esotericsoftware/spine/AttachmentType.java create mode 100644 spine-libgdx/src/com/esotericsoftware/spine/attachments/TextureAtlasAttachmentLoader.java delete mode 100644 spine-libgdx/src/com/esotericsoftware/spine/attachments/TextureAtlasAttachmentResolver.java diff --git a/spine-cpp/includes/spine-sfml/AtlasAttachmentLoader.h b/spine-cpp/includes/spine-sfml/AtlasAttachmentLoader.h index 57bceebcb..180effd0e 100644 --- a/spine-cpp/includes/spine-sfml/AtlasAttachmentLoader.h +++ b/spine-cpp/includes/spine-sfml/AtlasAttachmentLoader.h @@ -14,8 +14,7 @@ public: AtlasAttachmentLoader (Atlas *atlas); virtual Attachment* newAttachment (AttachmentType type, const std::string &name); -} -; +}; } /* namespace spine */ #endif /* SPINE_ATLASATTACHMENTLOADER_H_ */ diff --git a/spine-cpp/includes/spine/Animation.h b/spine-cpp/includes/spine/Animation.h index 12eb2f523..acaa69958 100644 --- a/spine-cpp/includes/spine/Animation.h +++ b/spine-cpp/includes/spine/Animation.h @@ -18,6 +18,7 @@ public: ~Animation(); void apply (BaseSkeleton *skeleton, float time, bool loop); + void mix (BaseSkeleton *skeleton, float time, bool loop, float alpha); }; // diff --git a/spine-cpp/includes/spine/BaseAtlas.h b/spine-cpp/includes/spine/BaseAtlas.h index 0551d3c36..46b677470 100644 --- a/spine-cpp/includes/spine/BaseAtlas.h +++ b/spine-cpp/includes/spine/BaseAtlas.h @@ -27,7 +27,7 @@ public: private: virtual BaseAtlasPage* newAtlasPage (std::string name) = 0; - virtual BaseAtlasRegion* newAtlasRegion (BaseAtlasPage*) = 0; + virtual BaseAtlasRegion* newAtlasRegion (BaseAtlasPage *page) = 0; }; // diff --git a/spine-cpp/src/spine-sfml/RegionAttachment.cpp b/spine-cpp/src/spine-sfml/RegionAttachment.cpp index fe3a7c582..032cc0f43 100644 --- a/spine-cpp/src/spine-sfml/RegionAttachment.cpp +++ b/spine-cpp/src/spine-sfml/RegionAttachment.cpp @@ -70,20 +70,14 @@ void RegionAttachment::draw (Slot *slot) { } void RegionAttachment::updateWorldVertices (spine::Bone *bone) { - float x = bone->worldX; - float y = bone->worldY; - float m00 = bone->m00; - float m01 = bone->m01; - float m10 = bone->m10; - float m11 = bone->m11; - vertices[0].position.x = offset[0] * m00 + offset[1] * m01 + x; - vertices[0].position.y = offset[0] * m10 + offset[1] * m11 + y; - vertices[1].position.x = offset[2] * m00 + offset[3] * m01 + x; - vertices[1].position.y = offset[2] * m10 + offset[3] * m11 + y; - vertices[2].position.x = offset[4] * m00 + offset[5] * m01 + x; - vertices[2].position.y = offset[4] * m10 + offset[5] * m11 + y; - vertices[3].position.x = offset[6] * m00 + offset[7] * m01 + x; - vertices[3].position.y = offset[6] * m10 + offset[7] * m11 + y; + vertices[0].position.x = offset[0] * bone->m00 + offset[1] * bone->m01 + bone->worldX; + vertices[0].position.y = offset[0] * bone->m10 + offset[1] * bone->m11 + bone->worldY; + vertices[1].position.x = offset[2] * bone->m00 + offset[3] * bone->m01 + bone->worldX; + vertices[1].position.y = offset[2] * bone->m10 + offset[3] * bone->m11 + bone->worldY; + vertices[2].position.x = offset[4] * bone->m00 + offset[5] * bone->m01 + bone->worldX; + vertices[2].position.y = offset[4] * bone->m10 + offset[5] * bone->m11 + bone->worldY; + vertices[3].position.x = offset[6] * bone->m00 + offset[7] * bone->m01 + bone->worldX; + vertices[3].position.y = offset[6] * bone->m10 + offset[7] * bone->m11 + bone->worldY; } } /* namespace spine */ diff --git a/spine-cpp/src/spine/Animation.cpp b/spine-cpp/src/spine/Animation.cpp index 20e52205d..f45f4a480 100644 --- a/spine-cpp/src/spine/Animation.cpp +++ b/spine-cpp/src/spine/Animation.cpp @@ -35,6 +35,15 @@ void Animation::apply (BaseSkeleton *skeleton, float time, bool loop) { timelines[i]->apply(skeleton, time, 1); } +void Animation::mix (BaseSkeleton *skeleton, float time, bool loop, float alpha) { + if (!skeleton) throw std::invalid_argument("skeleton cannot be null."); + + if (loop && duration) time = fmodf(time, duration); + + for (int i = 0, n = timelines.size(); i < n; i++) + timelines[i]->apply(skeleton, time, alpha); +} + // static const float LINEAR = 0; diff --git a/spine-cpp/src/spine/BaseSkeleton.cpp b/spine-cpp/src/spine/BaseSkeleton.cpp index be0a6be97..689fc1659 100644 --- a/spine-cpp/src/spine/BaseSkeleton.cpp +++ b/spine-cpp/src/spine/BaseSkeleton.cpp @@ -45,6 +45,7 @@ BaseSkeleton::BaseSkeleton (SkeletonData *data) : drawOrder.reserve(slotCount); for (int i = 0; i < slotCount; i++) { SlotData *slotData = data->slots[i]; + // Find bone for the slotData's boneData. Bone *bone; for (int ii = 0; ii < boneCount; ii++) { if (data->bones[ii] == slotData->boneData) { diff --git a/spine-libgdx/.classpath b/spine-libgdx/.classpath index 70260f375..962e3a64c 100644 --- a/spine-libgdx/.classpath +++ b/spine-libgdx/.classpath @@ -2,8 +2,7 @@ - - - + + diff --git a/spine-libgdx/.settings/org.eclipse.jdt.core.prefs b/spine-libgdx/.settings/org.eclipse.jdt.core.prefs index 089aa9ace..1f51694d7 100644 --- a/spine-libgdx/.settings/org.eclipse.jdt.core.prefs +++ b/spine-libgdx/.settings/org.eclipse.jdt.core.prefs @@ -5,9 +5,9 @@ org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annota org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.compliance=1.6 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate @@ -92,4 +92,4 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enab org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=ignore org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/spine-libgdx/src/com/esotericsoftware/spine/Attachment.java b/spine-libgdx/src/com/esotericsoftware/spine/Attachment.java index be35e97b6..2adc066a6 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/Attachment.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/Attachment.java @@ -5,25 +5,14 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch; abstract public class Attachment { final String name; - boolean resolved; public Attachment (String name) { if (name == null) throw new IllegalArgumentException("name cannot be null."); this.name = name; } - abstract public void updateOffset (); - abstract public void draw (SpriteBatch batch, Slot slot); - public boolean isResolved () { - return resolved; - } - - public void setResolved (boolean resolved) { - this.resolved = resolved; - } - public String getName () { return name; } diff --git a/spine-libgdx/src/com/esotericsoftware/spine/AttachmentLoader.java b/spine-libgdx/src/com/esotericsoftware/spine/AttachmentLoader.java new file mode 100644 index 000000000..674b0092c --- /dev/null +++ b/spine-libgdx/src/com/esotericsoftware/spine/AttachmentLoader.java @@ -0,0 +1,6 @@ + +package com.esotericsoftware.spine; + +public interface AttachmentLoader { + public Attachment newAttachment (AttachmentType type, String name); +} diff --git a/spine-libgdx/src/com/esotericsoftware/spine/AttachmentResolver.java b/spine-libgdx/src/com/esotericsoftware/spine/AttachmentResolver.java deleted file mode 100644 index 4d668b8d9..000000000 --- a/spine-libgdx/src/com/esotericsoftware/spine/AttachmentResolver.java +++ /dev/null @@ -1,6 +0,0 @@ - -package com.esotericsoftware.spine; - -public interface AttachmentResolver { - public void resolve (Attachment attachment); -} diff --git a/spine-libgdx/src/com/esotericsoftware/spine/AttachmentType.java b/spine-libgdx/src/com/esotericsoftware/spine/AttachmentType.java new file mode 100644 index 000000000..2b0d00c58 --- /dev/null +++ b/spine-libgdx/src/com/esotericsoftware/spine/AttachmentType.java @@ -0,0 +1,6 @@ + +package com.esotericsoftware.spine; + +public enum AttachmentType { + region, regionSequence +} diff --git a/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java b/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java index 64cfe3ac9..1d590b904 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java @@ -1,14 +1,11 @@ package com.esotericsoftware.spine; -import com.esotericsoftware.spine.Skin.Key; - import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType; import com.badlogic.gdx.utils.Array; -import com.badlogic.gdx.utils.ObjectMap.Entry; public class Skeleton { final SkeletonData data; @@ -101,11 +98,7 @@ public class Skeleton { for (int i = 0, n = drawOrder.size; i < n; i++) { Slot slot = drawOrder.get(i); Attachment attachment = slot.attachment; - if (attachment != null) { - if (!attachment.resolved) data.attachmentResolver.resolve(attachment); - attachment.updateOffset(); - attachment.draw(batch, slot); - } + if (attachment != null) attachment.draw(batch, slot); } } @@ -234,11 +227,16 @@ public class Skeleton { /** @param attachmentName May be null. */ public void setAttachment (String slotName, String attachmentName) { if (slotName == null) throw new IllegalArgumentException("slotName cannot be null."); - if (attachmentName == null) throw new IllegalArgumentException("attachmentName cannot be null."); for (int i = 0, n = slots.size; i < n; i++) { Slot slot = slots.get(i); if (slot.data.name.equals(slotName)) { - slot.setAttachment(getAttachment(i, attachmentName)); + Attachment attachment = null; + if (attachmentName != null) { + attachment = getAttachment(i, attachmentName); + if (attachment == null) + throw new IllegalArgumentException("Attachment not found: " + attachmentName + ", for slot: " + slotName); + } + slot.setAttachment(attachment); return; } } diff --git a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java index 225c5a346..afd6b70d4 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java @@ -11,7 +11,7 @@ import com.esotericsoftware.spine.Animation.TranslateTimeline; import com.esotericsoftware.spine.attachments.RegionAttachment; import com.esotericsoftware.spine.attachments.RegionSequenceAttachment; import com.esotericsoftware.spine.attachments.RegionSequenceAttachment.Mode; -import com.esotericsoftware.spine.attachments.TextureAtlasAttachmentResolver; +import com.esotericsoftware.spine.attachments.TextureAtlasAttachmentLoader; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.Color; @@ -29,22 +29,19 @@ public class SkeletonBinary { static public final int TIMELINE_ATTACHMENT = 3; static public final int TIMELINE_COLOR = 4; - static public final int ATTACHMENT_REGION = 0; - static public final int ATTACHMENT_REGION_SEQUENCE = 1; - static public final int CURVE_LINEAR = 0; static public final int CURVE_STEPPED = 1; static public final int CURVE_BEZIER = 2; - private final AttachmentResolver attachmentResolver; + private final AttachmentLoader attachmentLoader; private float scale = 1; public SkeletonBinary (TextureAtlas atlas) { - attachmentResolver = new TextureAtlasAttachmentResolver(atlas); + attachmentLoader = new TextureAtlasAttachmentLoader(atlas); } - public SkeletonBinary (AttachmentResolver attachmentResolver) { - this.attachmentResolver = attachmentResolver; + public SkeletonBinary (AttachmentLoader attachmentLoader) { + this.attachmentLoader = attachmentLoader; } public float getScale () { @@ -59,7 +56,7 @@ public class SkeletonBinary { public SkeletonData readSkeletonData (FileHandle file) { if (file == null) throw new IllegalArgumentException("file cannot be null."); - SkeletonData skeletonData = new SkeletonData(attachmentResolver); + SkeletonData skeletonData = new SkeletonData(); DataInput input = new DataInput(file.read(512)); try { // Bones. @@ -134,19 +131,13 @@ public class SkeletonBinary { String name = input.readString(); if (name == null) name = attachmentName; - Attachment attachment; - int type = input.readByte(); - switch (type) { - case ATTACHMENT_REGION: - attachment = new RegionAttachment(name); - break; - case ATTACHMENT_REGION_SEQUENCE: - float fps = input.readFloat(); - Mode mode = Mode.values()[input.readInt(true)]; - attachment = new RegionSequenceAttachment(name, 1 / fps, mode); - break; - default: - throw new SerializationException("Unknown attachment type: " + type + " (" + name + ")"); + AttachmentType type = AttachmentType.values()[input.readByte()]; + Attachment attachment = attachmentLoader.newAttachment(type, name); + + if (attachment instanceof RegionSequenceAttachment) { + RegionSequenceAttachment regionSequenceAttachment = (RegionSequenceAttachment)attachment; + regionSequenceAttachment.setFrameTime(1 / input.readFloat()); + regionSequenceAttachment.setMode(Mode.values()[input.readInt(true)]); } if (attachment instanceof RegionAttachment) { @@ -158,8 +149,9 @@ public class SkeletonBinary { regionAttachment.setRotation(input.readFloat()); regionAttachment.setWidth(input.readFloat() * scale); regionAttachment.setHeight(input.readFloat() * scale); + regionAttachment.updateOffset(); } - + return attachment; } diff --git a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonData.java b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonData.java index a98d17a47..b2880fdd6 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonData.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonData.java @@ -8,12 +8,6 @@ public class SkeletonData { final Array slots = new Array(); // Bind pose draw order. final Array skins = new Array(); Skin defaultSkin; - final AttachmentResolver attachmentResolver; - - public SkeletonData (AttachmentResolver attachmentResolver) { - if (attachmentResolver == null) throw new IllegalArgumentException("attachmentResolver cannot be null."); - this.attachmentResolver = attachmentResolver; - } public void clear () { bones.clear(); @@ -22,10 +16,6 @@ public class SkeletonData { defaultSkin = null; } - public AttachmentResolver getAttachmentResolver () { - return attachmentResolver; - } - // --- Bones. public void addBone (BoneData bone) { diff --git a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java index de9cd5cdb..301452181 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java @@ -8,10 +8,10 @@ import com.esotericsoftware.spine.Animation.RotateTimeline; import com.esotericsoftware.spine.Animation.ScaleTimeline; import com.esotericsoftware.spine.Animation.Timeline; import com.esotericsoftware.spine.Animation.TranslateTimeline; +import com.esotericsoftware.spine.attachments.RegionAttachment; import com.esotericsoftware.spine.attachments.RegionSequenceAttachment; import com.esotericsoftware.spine.attachments.RegionSequenceAttachment.Mode; -import com.esotericsoftware.spine.attachments.RegionAttachment; -import com.esotericsoftware.spine.attachments.TextureAtlasAttachmentResolver; +import com.esotericsoftware.spine.attachments.TextureAtlasAttachmentLoader; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.Color; @@ -29,19 +29,16 @@ public class SkeletonJson { static public final String TIMELINE_ATTACHMENT = "attachment"; static public final String TIMELINE_COLOR = "color"; - static public final String ATTACHMENT_REGION = "region"; - static public final String ATTACHMENT_REGION_SEQUENCE = "regionSequence"; - private final Json json = new Json(); - private final AttachmentResolver attachmentResolver; + private final AttachmentLoader attachmentLoader; private float scale = 1; public SkeletonJson (TextureAtlas atlas) { - attachmentResolver = new TextureAtlasAttachmentResolver(atlas); + attachmentLoader = new TextureAtlasAttachmentLoader(atlas); } - public SkeletonJson (AttachmentResolver attachmentResolver) { - this.attachmentResolver = attachmentResolver; + public SkeletonJson (AttachmentLoader attachmentLoader) { + this.attachmentLoader = attachmentLoader; } public float getScale () { @@ -56,7 +53,7 @@ public class SkeletonJson { public SkeletonData readSkeletonData (FileHandle file) { if (file == null) throw new IllegalArgumentException("file cannot be null."); - SkeletonData skeletonData = new SkeletonData(attachmentResolver); + SkeletonData skeletonData = new SkeletonData(); OrderedMap root = json.fromJson(OrderedMap.class, file); @@ -122,23 +119,20 @@ public class SkeletonJson { private Attachment readAttachment (String name, OrderedMap map) { name = (String)map.get("name", name); - Attachment attachment; - String type = (String)map.get("type"); - if (type == null) type = ATTACHMENT_REGION; - if (type.equals(ATTACHMENT_REGION)) { - attachment = new RegionAttachment(name); - } else if (type.equals(ATTACHMENT_REGION_SEQUENCE)) { + AttachmentType type = AttachmentType.valueOf((String)map.get("type", AttachmentType.region.name())); + Attachment attachment = attachmentLoader.newAttachment(type, name); + + if (attachment instanceof RegionSequenceAttachment) { + RegionSequenceAttachment regionSequenceAttachment = (RegionSequenceAttachment)attachment; + Float fps = (Float)map.get("fps"); if (fps == null) throw new SerializationException("Region sequence attachment missing fps: " + name); + regionSequenceAttachment.setFrameTime(fps); String modeString = (String)map.get("mode"); - Mode mode = modeString == null ? Mode.forward : Mode.valueOf(modeString); - - attachment = new RegionSequenceAttachment(name, 1 / fps, mode); - - } else - throw new SerializationException("Unknown attachment type: " + type + " (" + name + ")"); + regionSequenceAttachment.setMode(modeString == null ? Mode.forward : Mode.valueOf(modeString)); + } if (attachment instanceof RegionAttachment) { RegionAttachment regionAttachment = (RegionAttachment)attachment; @@ -149,6 +143,7 @@ public class SkeletonJson { regionAttachment.setRotation(getFloat(map, "rotation", 0)); regionAttachment.setWidth(getFloat(map, "width", 32) * scale); regionAttachment.setHeight(getFloat(map, "height", 32) * scale); + regionAttachment.updateOffset(); } return attachment; diff --git a/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionSequenceAttachment.java b/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionSequenceAttachment.java index 80acea639..43823958a 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionSequenceAttachment.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionSequenceAttachment.java @@ -9,17 +9,12 @@ import com.badlogic.gdx.math.MathUtils; /** Attachment that displays various texture regions over time. */ public class RegionSequenceAttachment extends RegionAttachment { - private final Mode mode; + private Mode mode; private float frameTime; private TextureRegion[] regions; - /** @param frameTime Time in seconds each frame is shown. */ - public RegionSequenceAttachment (String name, float frameTime, Mode mode) { + public RegionSequenceAttachment (String name) { super(name); - if (mode == null) throw new IllegalArgumentException("mode cannot be null."); - - this.frameTime = frameTime; - this.mode = mode; } public void draw (SpriteBatch batch, Slot slot) { @@ -62,6 +57,15 @@ public class RegionSequenceAttachment extends RegionAttachment { this.regions = regions; } + /** Sets the time in seconds each frame is shown. */ + public void setFrameTime (float frameTime) { + this.frameTime = frameTime; + } + + public void setMode (Mode mode) { + this.mode = mode; + } + static public enum Mode { forward, backward, forwardLoop, backwardLoop, pingPong, random } diff --git a/spine-libgdx/src/com/esotericsoftware/spine/attachments/TextureAtlasAttachmentLoader.java b/spine-libgdx/src/com/esotericsoftware/spine/attachments/TextureAtlasAttachmentLoader.java new file mode 100644 index 000000000..922dbb629 --- /dev/null +++ b/spine-libgdx/src/com/esotericsoftware/spine/attachments/TextureAtlasAttachmentLoader.java @@ -0,0 +1,41 @@ + +package com.esotericsoftware.spine.attachments; + +import com.esotericsoftware.spine.Attachment; +import com.esotericsoftware.spine.AttachmentLoader; +import com.esotericsoftware.spine.AttachmentType; + +import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion; + +public class TextureAtlasAttachmentLoader implements AttachmentLoader { + private TextureAtlas atlas; + + public TextureAtlasAttachmentLoader (TextureAtlas atlas) { + if (atlas == null) throw new IllegalArgumentException("atlas cannot be null."); + this.atlas = atlas; + } + + public Attachment newAttachment (AttachmentType type, String name) { + Attachment attachment = null; + switch (type) { + case region: + attachment = new RegionAttachment(name); + break; + case regionSequence: + attachment = new RegionAttachment(name); + break; + default: + throw new IllegalArgumentException("Unknown attachment type: " + type); + } + + if (attachment instanceof RegionAttachment) { + AtlasRegion region = atlas.findRegion(attachment.getName()); + if (region == null) + throw new RuntimeException("Region not found in atlas: " + attachment + " (" + type + " attachment: " + name + ")"); + ((RegionAttachment)attachment).setRegion(region); + } + + return attachment; + } +} diff --git a/spine-libgdx/src/com/esotericsoftware/spine/attachments/TextureAtlasAttachmentResolver.java b/spine-libgdx/src/com/esotericsoftware/spine/attachments/TextureAtlasAttachmentResolver.java deleted file mode 100644 index ed5b70530..000000000 --- a/spine-libgdx/src/com/esotericsoftware/spine/attachments/TextureAtlasAttachmentResolver.java +++ /dev/null @@ -1,29 +0,0 @@ - -package com.esotericsoftware.spine.attachments; - -import com.esotericsoftware.spine.Attachment; -import com.esotericsoftware.spine.AttachmentResolver; - -import com.badlogic.gdx.graphics.g2d.TextureAtlas; -import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion; - -public class TextureAtlasAttachmentResolver implements AttachmentResolver { - private TextureAtlas atlas; - - public TextureAtlasAttachmentResolver (TextureAtlas atlas) { - if (atlas == null) throw new IllegalArgumentException("atlas cannot be null."); - this.atlas = atlas; - } - - public void resolve (Attachment attachment) { - if (attachment instanceof RegionAttachment) { - AtlasRegion region = atlas.findRegion(attachment.getName()); - if (region == null) throw new RuntimeException("Region not found in atlas: " + attachment); - ((RegionAttachment)attachment).setRegion(region); - attachment.setResolved(true); - return; - } - - throw new IllegalArgumentException("Unable to resolve attachment of type: " + attachment.getClass().getName()); - } -} diff --git a/spine-libgdx/test/com/esotericsoftware/spine/MixTest.java b/spine-libgdx/test/com/esotericsoftware/spine/MixTest.java index cb78495b0..85e987e6f 100644 --- a/spine-libgdx/test/com/esotericsoftware/spine/MixTest.java +++ b/spine-libgdx/test/com/esotericsoftware/spine/MixTest.java @@ -3,10 +3,8 @@ package com.esotericsoftware.spine; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.Input.Keys; -import com.badlogic.gdx.InputAdapter; -import com.badlogic.gdx.backends.lwjgl.LwjglApplication; -import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; +import com.badlogic.gdx.backends.jglfw.JglfwApplication; +import com.badlogic.gdx.backends.jglfw.JglfwApplicationConfiguration; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL10; import com.badlogic.gdx.graphics.g2d.SpriteBatch; @@ -115,10 +113,10 @@ public class MixTest extends ApplicationAdapter { } public static void main (String[] args) throws Exception { - LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); + JglfwApplicationConfiguration config = new JglfwApplicationConfiguration(); config.title = "Mix Test"; config.width = 640; config.height = 480; - new LwjglApplication(new MixTest(), config); + new JglfwApplication(new MixTest(), config); } } diff --git a/spine-libgdx/test/com/esotericsoftware/spine/SkeletonTest.java b/spine-libgdx/test/com/esotericsoftware/spine/SkeletonTest.java index 7367dabba..71cc84453 100644 --- a/spine-libgdx/test/com/esotericsoftware/spine/SkeletonTest.java +++ b/spine-libgdx/test/com/esotericsoftware/spine/SkeletonTest.java @@ -5,8 +5,8 @@ import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.InputAdapter; -import com.badlogic.gdx.backends.lwjgl.LwjglApplication; -import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; +import com.badlogic.gdx.backends.jglfw.JglfwApplication; +import com.badlogic.gdx.backends.jglfw.JglfwApplicationConfiguration; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL10; @@ -114,10 +114,10 @@ public class SkeletonTest extends ApplicationAdapter { } public static void main (String[] args) throws Exception { - LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); + JglfwApplicationConfiguration config = new JglfwApplicationConfiguration(); config.title = "Skeleton Test"; config.width = 640; config.height = 480; - new LwjglApplication(new SkeletonTest(), config); + new JglfwApplication(new SkeletonTest(), config); } } diff --git a/spine-libgdx/test/spineboy-skeleton.json b/spine-libgdx/test/spineboy-skeleton.json index a51a9feeb..e6df6f99a 100644 --- a/spine-libgdx/test/spineboy-skeleton.json +++ b/spine-libgdx/test/spineboy-skeleton.json @@ -41,9 +41,6 @@ ], "skins": { "default": { - "template": { - "spineboy": { "y": 167.82, "width": 145, "height": 341 } - }, "left shoulder": { "left-shoulder": { "x": 23.74, "y": 0.11, "rotation": 62.01, "width": 34, "height": 53 } },