From 318b9939e6d6cd84d292b5ebe11d0eac41c6f058 Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Fri, 15 Jan 2016 07:02:09 +0100 Subject: [PATCH] Made consistent when slot vertices and attachment time are reset. setAttachment resets vertices and attachment time only if the attachment actually changed. setToSetupPose always resets vertices and attachment time. http://esotericsoftware.com/forum/Spine-API-SetToSetupPose-FFD-Questions-2102?p=26119#p26119 --- spine-as3/spine-as3/src/spine/Slot.as | 8 +++++++- spine-c/src/spine/Slot.c | 8 ++++++-- spine-csharp/src/Slot.cs | 8 +++++++- spine-js/spine.js | 16 +++++++++++----- .../src/com/esotericsoftware/spine/Slot.java | 11 ++++++++--- spine-lua/Slot.lua | 10 ++++++---- 6 files changed, 45 insertions(+), 16 deletions(-) diff --git a/spine-as3/spine-as3/src/spine/Slot.as b/spine-as3/spine-as3/src/spine/Slot.as index e621f0d66..5daf06b27 100644 --- a/spine-as3/spine-as3/src/spine/Slot.as +++ b/spine-as3/spine-as3/src/spine/Slot.as @@ -71,6 +71,7 @@ public class Slot { /** Sets the attachment and resets {@link #getAttachmentTime()}. * @param attachment May be null. */ public function set attachment (attachment:Attachment) : void { + if (_attachment == attachment) return; _attachment = attachment; _attachmentTime = _bone._skeleton.time; attachmentVertices.length = 0; @@ -91,7 +92,12 @@ public class Slot { g = _data.g; b = _data.b; a = _data.a; - attachment = _data.attachmentName == null ? null : _bone._skeleton.getAttachmentForSlotIndex(slotIndex, data.attachmentName); + if (_data.attachmentName == null) + attachment = null; + else { + _attachment = null; + attachment = _bone._skeleton.getAttachmentForSlotIndex(slotIndex, data.attachmentName); + } } public function toString () : String { diff --git a/spine-c/src/spine/Slot.c b/spine-c/src/spine/Slot.c index 7a7da3ba8..709ae9f98 100644 --- a/spine-c/src/spine/Slot.c +++ b/spine-c/src/spine/Slot.c @@ -51,6 +51,7 @@ void spSlot_dispose (spSlot* self) { } void spSlot_setAttachment (spSlot* self, spAttachment* attachment) { + if (attachment == self->attachment) return; CONST_CAST(spAttachment*, self->attachment) = attachment; SUB_CAST(_spSlot, self)->attachmentTime = self->bone->skeleton->time; self->attachmentVerticesCount = 0; @@ -72,7 +73,9 @@ void spSlot_setToSetupPose (spSlot* self) { self->b = self->data->b; self->a = self->data->a; - if (self->data->attachmentName) { + if (!self->data->attachmentName) + spSlot_setAttachment(self, 0); + else { /* Find slot index. */ int i; for (i = 0; i < self->bone->skeleton->data->slotsCount; ++i) { @@ -81,6 +84,7 @@ void spSlot_setToSetupPose (spSlot* self) { break; } } + CONST_CAST(spAttachment*, self->attachment) = 0; + spSlot_setAttachment(self, attachment); } - spSlot_setAttachment(self, attachment); } diff --git a/spine-csharp/src/Slot.cs b/spine-csharp/src/Slot.cs index e8d393baf..cce0fd869 100644 --- a/spine-csharp/src/Slot.cs +++ b/spine-csharp/src/Slot.cs @@ -55,6 +55,7 @@ namespace Spine { return attachment; } set { + if (attachment == value) return; attachment = value; attachmentTime = bone.skeleton.time; attachmentVerticesCount = 0; @@ -86,7 +87,12 @@ namespace Spine { g = data.g; b = data.b; a = data.a; - Attachment = data.attachmentName == null ? null : bone.skeleton.GetAttachment(slotIndex, data.attachmentName); + if (data.attachmentName == null) + Attachment = null; + else { + attachment = null; + Attachment = bone.skeleton.GetAttachment(slotIndex, data.attachmentName); + } } public void SetToSetupPose () { diff --git a/spine-js/spine.js b/spine-js/spine.js index bee97ed2d..86edad85f 100644 --- a/spine-js/spine.js +++ b/spine-js/spine.js @@ -178,6 +178,7 @@ spine.Slot.prototype = { attachment: null, attachmentVertices: [], setAttachment: function (attachment) { + if (this.attachment == attachment) return; this.attachment = attachment; this._attachmentTime = this.bone.skeleton.time; this.attachmentVertices.length = 0; @@ -195,11 +196,16 @@ spine.Slot.prototype = { this.b = data.b; this.a = data.a; - var slotDatas = this.bone.skeleton.data.slots; - for (var i = 0, n = slotDatas.length; i < n; i++) { - if (slotDatas[i] == data) { - this.setAttachment(!data.attachmentName ? null : this.bone.skeleton.getAttachmentBySlotIndex(i, data.attachmentName)); - break; + if (!data.attachmentName) + this.setAttachment(null); + else { + var slotDatas = this.bone.skeleton.data.slots; + for (var i = 0, n = slotDatas.length; i < n; i++) { + if (slotDatas[i] == data) { + this.attachment = null; + this.setAttachment(this.bone.skeleton.getAttachmentBySlotIndex(i, data.attachmentName)); + break; + } } } } diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Slot.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Slot.java index a78b34412..48db6d475 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Slot.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Slot.java @@ -91,10 +91,10 @@ public class Slot { return attachment; } - /** Sets the attachment, resets {@link #getAttachmentTime()}, and clears {@link #getAttachmentVertices()}. + /** Sets the attachment and if it changed, resets {@link #getAttachmentTime()} and clears {@link #getAttachmentVertices()}. * @param attachment May be null. */ public void setAttachment (Attachment attachment) { - if (this.attachment == attachment) return; + if (this.attachment != attachment) return; this.attachment = attachment; attachmentTime = bone.skeleton.time; attachmentVertices.clear(); @@ -119,7 +119,12 @@ public class Slot { void setToSetupPose (int slotIndex) { color.set(data.color); - setAttachment(data.attachmentName == null ? null : bone.skeleton.getAttachment(slotIndex, data.attachmentName)); + if (data.attachmentName == null) + setAttachment(null); + else { + attachment = null; + setAttachment(bone.skeleton.getAttachment(slotIndex, data.attachmentName)); + } } public void setToSetupPose () { diff --git a/spine-lua/Slot.lua b/spine-lua/Slot.lua index daa9c2846..56bceb9b5 100644 --- a/spine-lua/Slot.lua +++ b/spine-lua/Slot.lua @@ -52,6 +52,7 @@ function Slot.new (slotData, bone) end function self:setAttachment (attachment) + if self.attachment == attachment then return end self.attachment = attachment self.attachmentTime = self.bone.skeleton.time self.attachmentVerticesCount = 0 @@ -70,11 +71,12 @@ function Slot.new (slotData, bone) self:setColor(data.r, data.g, data.b, data.a) - local attachment - if data.attachmentName then - attachment = self.bone.skeleton:getAttachment(data.name, data.attachmentName) + if not data.attachmentName then + self:setAttachment(nil) + else + self.attachment = nil + self:setAttachment(self.bone.skeleton:getAttachment(data.name, data.attachmentName)) end - self:setAttachment(attachment) end self:setToSetupPose()