diff --git a/spine-corona/main.lua b/spine-corona/main.lua index 1696adde5..b31b93258 100644 --- a/spine-corona/main.lua +++ b/spine-corona/main.lua @@ -34,7 +34,7 @@ function loadSkeleton(atlasFile, jsonFile, x, y, scale, animation, skin) -- create an animation state object to apply animations to the skeleton local animationStateData = spine.AnimationStateData.new(skeletonData) - animationStateData.defaultMix = 0.2 + animationStateData.defaultMix = 0.5 local animationState = spine.AnimationState.new(animationStateData) -- set the skeleton invisible diff --git a/spine-corona/spine-corona/spine.lua b/spine-corona/spine-corona/spine.lua index edd118b36..30eace287 100644 --- a/spine-corona/spine-corona/spine.lua +++ b/spine-corona/spine-corona/spine.lua @@ -28,7 +28,7 @@ -- POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------- -spine = {} +local spine = {} spine.utils = require "spine-lua.utils" spine.SkeletonJson = require "spine-lua.SkeletonJson" @@ -88,7 +88,7 @@ local QUAD_TRIANGLES = { 1, 2, 3, 3, 4, 1 } spine.Skeleton.new_super = spine.Skeleton.new spine.Skeleton.updateWorldTransform_super = spine.Skeleton.updateWorldTransform spine.Skeleton.new = function(skeletonData, group) - self = spine.Skeleton.new_super(skeletonData) + local self = spine.Skeleton.new_super(skeletonData) self.group = group or display.newGroup() self.drawingGroup = nil self.premultipliedAlpha = false @@ -156,7 +156,7 @@ function spine.Skeleton:updateWorldTransform() uvs = nil } - for i,slot in ipairs(drawOrder) do + for _,slot in ipairs(drawOrder) do local attachment = slot.attachment local vertices = nil local uvs = nil diff --git a/spine-lua/AnimationState.lua b/spine-lua/AnimationState.lua index a1735d37b..f26a64a11 100644 --- a/spine-lua/AnimationState.lua +++ b/spine-lua/AnimationState.lua @@ -198,6 +198,7 @@ function TrackEntry:setTimelineData(to, mixingToArray, propertyIDs) local timelineDipMix = self.timelineDipMix local i = 1 + local skip while i <= timelinesCount do local id = "" .. timelines[i]:getPropertyId() if not (propertyIDs[id] == nil) then @@ -208,7 +209,7 @@ function TrackEntry:setTimelineData(to, mixingToArray, propertyIDs) local ii = mixingToLast while ii > 0 do local entry = mixingTo[ii] - local skip = false + skip = false if not entry:hasTimeline(id) then if entry.mixDuration > 0 then timelineData[i] = DIP_MIX @@ -343,10 +344,7 @@ function AnimationState:updateMixingFrom (to, delta) local from = to.mixingFrom if from == nil then return true end - local finished = self:updateMixingFrom(from, delta) - - from.animationLast = from.nextAnimationLast - from.trackLast = from.nextTrackLast + local finished = self:updateMixingFrom(from, delta) -- Require mixTime > 0 to ensure the mixing from entry was applied at least once. if (to.mixTime > 0 and (to.mixTime >= to.mixDuration or to.timeScale == 0)) then @@ -359,6 +357,8 @@ function AnimationState:updateMixingFrom (to, delta) return finished end + from.animationLast = from.nextAnimationLast + from.trackLast = from.nextTrackLast from.trackTime = from.trackTime + delta * from.timeScale to.mixTime = to.mixTime + delta * to.timeScale return false; diff --git a/spine-lua/Atlas.lua b/spine-lua/Atlas.lua index 4d183c9e4..f3d13a96e 100644 --- a/spine-lua/Atlas.lua +++ b/spine-lua/Atlas.lua @@ -33,13 +33,13 @@ local Atlas = {} function Atlas.parse(atlasPath, atlasBase) local function parseIntTuple4( l ) local a,b,c,d = string.match( l , " ? ?%a+: ([+-]?%d+), ?([+-]?%d+), ?([+-]?%d+), ?([+-]?%d+)" ) - local a,b,c,d = tonumber( a ), tonumber( b ), tonumber( c ), tonumber( d ) + a,b,c,d = tonumber( a ), tonumber( b ), tonumber( c ), tonumber( d ) return a and b and c and d and {a, b, c ,d} end local function parseIntTuple2( l ) local a,b = string.match( l , " ? ?%a+: ([+-]?%d+), ?([+-]?%d+)" ) - local a,b = tonumber( a ), tonumber( b ) + a,b = tonumber( a ), tonumber( b ) return a and b and {a, b} end diff --git a/spine-lua/AtlasAttachmentLoader.lua b/spine-lua/AtlasAttachmentLoader.lua index a6a7d166f..3533cfddd 100644 --- a/spine-lua/AtlasAttachmentLoader.lua +++ b/spine-lua/AtlasAttachmentLoader.lua @@ -69,10 +69,6 @@ function AtlasAttachmentLoader:newMeshAttachment (skin, name, path) return attachment end -function AtlasAttachmentLoader:newSkinningMeshAttachment (skin, name, path) - return SkinningMeshAttachment.new(name) -end - function AtlasAttachmentLoader:newBoundingBoxAttachment (skin, name) return BoundingBoxAttachment.new(name) end diff --git a/spine-lua/AttachmentLoader.lua b/spine-lua/AttachmentLoader.lua index 405e22e27..dfbcf98b8 100644 --- a/spine-lua/AttachmentLoader.lua +++ b/spine-lua/AttachmentLoader.lua @@ -48,10 +48,6 @@ function AttachmentLoader.new () return MeshAttachment.new(name) end - function self:newSkinningMeshAttachment (skin, name, path) - return SkinningMeshAttachment.new(name) - end - function self:newBoundingBoxAttachment (skin, name) return BoundingBoxAttachment.new(name) end diff --git a/spine-lua/Bone.lua b/spine-lua/Bone.lua index 5f304db16..967fd23c9 100644 --- a/spine-lua/Bone.lua +++ b/spine-lua/Bone.lua @@ -240,7 +240,7 @@ function Bone:getWorldScaleY () return math_sqrt(self.b * self.b + self.d * self.d) end -function updateAppliedTransform () +function Bone:updateAppliedTransform () local parent = self.parent if parent == nil then self.ax = self.worldX diff --git a/spine-lua/IkConstraint.lua b/spine-lua/IkConstraint.lua index 3db55f4d9..c5315ba0e 100644 --- a/spine-lua/IkConstraint.lua +++ b/spine-lua/IkConstraint.lua @@ -57,7 +57,7 @@ function IkConstraint.new (data, skeleton) setmetatable(self, IkConstraint) local self_bones = self.bones - for i,boneData in ipairs(data.bones) do + for _,boneData in ipairs(data.bones) do table_insert(self_bones, skeleton:findBone(boneData.name)) end self.target = skeleton:findBone(data.target.name) diff --git a/spine-lua/PathConstraint.lua b/spine-lua/PathConstraint.lua index b8f4ce168..bd724b5bb 100644 --- a/spine-lua/PathConstraint.lua +++ b/spine-lua/PathConstraint.lua @@ -78,7 +78,7 @@ function PathConstraint.new (data, skeleton) } setmetatable(self, PathConstraint) - for i,boneData in ipairs(data.bones) do + for _,boneData in ipairs(data.bones) do table_insert(self.bones, skeleton:findBone(boneData.name)) end @@ -244,6 +244,7 @@ function PathConstraint:computeWorldPositions (path, spacesCount, tangents, perc local verticesLength = path.worldVerticesLength local curveCount = verticesLength / 6 local prevCurve = PathConstraint.NONE + local i = 0 if not path.constantSpeed then local lengths = path.lengths @@ -251,14 +252,14 @@ function PathConstraint:computeWorldPositions (path, spacesCount, tangents, perc local pathLength = lengths[curveCount + 1]; if percentPosition then position = position * pathLength end if percentSpacing then - local i = 0 + i = 0 while i < spacesCount do spaces[i + 1] = spaces[i + 1] * pathLength i = i + 1 end end world = utils.setArraySize(self.world, 8); - local i = 0 + i = 0 local o = 0 local curve = 0 while i < spacesCount do @@ -354,7 +355,6 @@ function PathConstraint:computeWorldPositions (path, spacesCount, tangents, perc local ddfy = 0 local dfx = 0 local dfy = 0 - i = 0 local w = 2 while i < curveCount do cx1 = world[w + 1] @@ -395,7 +395,7 @@ function PathConstraint:computeWorldPositions (path, spacesCount, tangents, perc position = position * pathLength / path.lengths[curveCount]; end if percentSpacing then - local i = 0 + i = 0 while i < spacesCount do spaces[i + 1] = spaces[i + 1] * pathLength i = i + 1 @@ -404,7 +404,7 @@ function PathConstraint:computeWorldPositions (path, spacesCount, tangents, perc local segments = self.segments local curveLength = 0 - local i = 0 + i = 0 local o = 0 local curve = 0 local segment = 0 diff --git a/spine-lua/RegionAttachment.lua b/spine-lua/RegionAttachment.lua index 66c061658..20d8268f2 100644 --- a/spine-lua/RegionAttachment.lua +++ b/spine-lua/RegionAttachment.lua @@ -85,6 +85,7 @@ function RegionAttachment.new (name) y = y + bone.worldY local m00, m01, m10, m11 = bone.m00, bone.m01, bone.m10, bone.m11 local offset = self.offset + local vertices = self.vertices; vertices[0] = offset[0] * m00 + offset[1] * m01 + x vertices[1] = offset[0] * m10 + offset[1] * m11 + y vertices[2] = offset[2] * m00 + offset[3] * m01 + x diff --git a/spine-lua/Skeleton.lua b/spine-lua/Skeleton.lua index bfdb77525..e93d5bc3e 100644 --- a/spine-lua/Skeleton.lua +++ b/spine-lua/Skeleton.lua @@ -68,7 +68,7 @@ function Skeleton.new (data) } setmetatable(self, Skeleton) - for i,boneData in ipairs(data.bones) do + for _,boneData in ipairs(data.bones) do local bone = nil if boneData.parent == nil then bone = Bone.new(boneData, self, nil) @@ -80,7 +80,7 @@ function Skeleton.new (data) table_insert(self.bones, bone) end - for i,slotData in ipairs(data.slots) do + for _,slotData in ipairs(data.slots) do local bone = self.bones[slotData.boneData.index] local slot = Slot.new(slotData, bone) table_insert(self.slots, slot) @@ -88,15 +88,15 @@ function Skeleton.new (data) table_insert(self.drawOrder, slot) end - for i,ikConstraintData in ipairs(data.ikConstraints) do + for _, ikConstraintData in ipairs(data.ikConstraints) do table_insert(self.ikConstraints, IkConstraint.new(ikConstraintData, self)) end - for i, transformConstraintData in ipairs(data.transformConstraints) do + for _, transformConstraintData in ipairs(data.transformConstraints) do table_insert(self.transformConstraints, TransformConstraint.new(transformConstraintData, self)) end - for i, pathConstraintData in ipairs(data.pathConstraints) do + for _, pathConstraintData in ipairs(data.pathConstraints) do table_insert(self.pathConstraints, PathConstraint.new(pathConstraintData, self)) end @@ -113,7 +113,7 @@ function Skeleton:updateCache () self.updateCacheReset = {} local bones = self.bones - for i, bone in ipairs(bones) do + for _, bone in ipairs(bones) do bone.sorted = false end @@ -167,7 +167,7 @@ function Skeleton:updateCache () i = i + 1 end - for i, bone in ipairs(self.bones) do + for _, bone in ipairs(self.bones) do self:sortBone(bone) end end @@ -183,7 +183,7 @@ function Skeleton:sortIkConstraint (constraint) if #constrained > 1 then local child = constrained[#constrained] local contains = false - for i,updatable in ipairs(self._updateCache) do + for _, updatable in ipairs(self._updateCache) do if updatable == child then contains = true break @@ -202,11 +202,11 @@ function Skeleton:sortPathConstraint(constraint) local slot = constraint.target local slotIndex = slot.data.index local slotBone = slot.bone - if self.skin then self:sortPathConstraintAttachment(skin, slotIndex, slotBone) end - if self.data.defaultSkin and not (self.data.defaultSkin == skin) then + if self.skin then self:sortPathConstraintAttachment(self.skin, slotIndex, slotBone) end + if self.data.defaultSkin and not (self.data.defaultSkin == self.skin) then self:sortPathConstraintAttachment(self.data.defaultSkin, slotIndex, slotBone) end - for i,skin in ipairs(self.data.skins) do + for _,skin in ipairs(self.data.skins) do self:sortPathConstraintAttachment(skin, slotIndex, slotBone) end @@ -214,17 +214,17 @@ function Skeleton:sortPathConstraint(constraint) if attachment and attachment.type == AttachmentType.path then self:sortPathConstraintAttachmentWith(attachment, slotBone) end local constrained = constraint.bones - for i,bone in ipairs(constrained) do + for _,bone in ipairs(constrained) do self:sortBone(bone) end table_insert(self._updateCache, constraint) - for i,bone in ipairs(constrained) do + for _,bone in ipairs(constrained) do self:sortReset(bone.children) end - for i,bone in ipairs(constrained) do + for _,bone in ipairs(constrained) do bone.sorted = true end end @@ -234,11 +234,11 @@ function Skeleton:sortTransformConstraint(constraint) local constrained = constraint.bones if constraint.data.local_ then - for i,bone in ipairs(constrained) do + for _,bone in ipairs(constrained) do local child = constrained[#constrained] local contains = false - sortBone(child.parent) - for i,updatable in ipairs(self._updateCache) do + self:sortBone(child.parent) + for _,updatable in ipairs(self._updateCache) do if updatable == child then contains = true break @@ -247,18 +247,18 @@ function Skeleton:sortTransformConstraint(constraint) if not contains then table_insert(self.updateCacheReset, child) end end else - for i,bone in ipairs(constrained) do + for _,bone in ipairs(constrained) do self:sortBone(bone) end end table_insert(self._updateCache, constraint) - for i,bone in ipairs(constrained) do + for _,bone in ipairs(constrained) do self:sortReset(bone.children) end - for i,bone in ipairs(constrained) do + for _,bone in ipairs(constrained) do bone.sorted = true end end @@ -266,7 +266,7 @@ end function Skeleton:sortPathConstraintAttachment(skin, slotIndex, slotBone) local attachments = skin.attachments[slotIndex] if not attachments then return end - for key,attachment in pairs(attachments) do + for _,attachment in pairs(attachments) do self:sortPathConstraintAttachmentWith(attachment, slotBone) end end @@ -301,7 +301,7 @@ function Skeleton:sortBone(bone) end function Skeleton:sortReset(bones) - for i, bone in ipairs(bones) do + for _, bone in ipairs(bones) do if bone.sorted then self:sortReset(bone.children) end bone.sorted = false end @@ -310,7 +310,7 @@ end -- Updates the world transform for each bone and applies IK constraints. function Skeleton:updateWorldTransform () local updateCacheReset = self.updateCacheReset - for i,bone in ipairs(updateCacheReset) do + for _,bone in ipairs(updateCacheReset) do bone.ax = bone.x bone.ay = bone.y bone.arotation = bone.rotation @@ -322,7 +322,7 @@ function Skeleton:updateWorldTransform () end local updateCache = self._updateCache - for i, updatable in ipairs(updateCache) do + for _, updatable in ipairs(updateCache) do updatable:update() end end @@ -333,17 +333,17 @@ function Skeleton:setToSetupPose () end function Skeleton:setBonesToSetupPose () - for i,bone in ipairs(self.bones) do + for _,bone in ipairs(self.bones) do bone:setToSetupPose() end - for i,ikConstraint in ipairs(self.ikConstraints) do + for _,ikConstraint in ipairs(self.ikConstraints) do ikConstraint.bendDirection = ikConstraint.data.bendDirection ikConstraint.mix = ikConstraint.data.mix end local transformConstraints = self.transformConstraints - for i, constraint in ipairs(transformConstraints) do + for _, constraint in ipairs(transformConstraints) do local data = constraint.data constraint.rotateMix = data.rotateMix constraint.translateMix = data.translateMix @@ -352,7 +352,7 @@ function Skeleton:setBonesToSetupPose () end local pathConstraints = self.pathConstraints - for i, constraint in ipairs(pathConstraints) do + for _, constraint in ipairs(pathConstraints) do local data = constraint.data constraint.position = data.position constraint.spacing = data.spacing @@ -374,7 +374,7 @@ end function Skeleton:findBone (boneName) if not boneName then error("boneName cannot be nil.", 2) end - for i,bone in ipairs(self.bones) do + for _,bone in ipairs(self.bones) do if bone.data.name == boneName then return bone end end return nil @@ -463,8 +463,8 @@ end function Skeleton:findIkConstraint(constraintName) if not constraintName then error("constraintName cannot be null.", 2) end - local ikConstaints = self.ikConstraints - for i, ikConstraint in ipairs(ikConstraints) do + local ikConstraints = self.ikConstraints + for _, ikConstraint in ipairs(ikConstraints) do if ikConstraint.data.name == constraintName then return ikConstraint end end return nil @@ -473,7 +473,7 @@ end function Skeleton:findTransformConstraint(constraintName) if not constraintName then error("constraintName cannot be null.", 2) end local transformConstraints = self.transformConstraints - for i, transformConstraint in ipairs(transformConstraints) do + for _, transformConstraint in ipairs(transformConstraints) do if transformConstraint.data.name == constraintName then return transformConstraint end end return nil @@ -482,7 +482,7 @@ end function Skeleton:findPathConstraint(constraintName) if not constraintName then error("constraintName cannot be null.", 2) end local pathConstraints = self.pathConstraints - for i, pathConstraint in ipairs(pathConstraints) do + for _, pathConstraint in ipairs(pathConstraints) do if pathConstraint.data.name == constraintName then return pathConstraint end end return nil @@ -496,7 +496,7 @@ function Skeleton:getBounds(offset, size) local minY = 99999999 local maxX = -99999999 local maxY = -99999999 - for i, slot in ipairs(drawOrder) do + for _, slot in ipairs(drawOrder) do local vertices = {} local attachment = slot.attachment if attachment then diff --git a/spine-lua/SkeletonBounds.lua b/spine-lua/SkeletonBounds.lua index 27e2b3f31..113cd478e 100644 --- a/spine-lua/SkeletonBounds.lua +++ b/spine-lua/SkeletonBounds.lua @@ -59,7 +59,7 @@ function SkeletonBounds:update (skeleton, updateAabb) self.polygons = polygons local slots = skeleton.slots - for i,slot in ipairs(skeleton.slots) do + for _,slot in ipairs(skeleton.slots) do local attachment = slot.attachment if attachment and attachment.type == AttachmentType.boundingbox then local boundingBox = attachment @@ -85,7 +85,7 @@ end function SkeletonBounds:aabbCompute () local minX, minY, maxX, maxY = 9999999, 9999999, -9999999, -9999999 local polygons = self.polygons - for i,vertices in ipairs(polygons) do + for _,vertices in ipairs(polygons) do local count = #vertices for ii = 1, count, 2 do local x = vertices[ii] @@ -179,7 +179,7 @@ function SkeletonBounds:polygonIntersectsSegment (polygon, x1, y1, x2, y2) end function SkeletonBounds:getPolygon (attachment) - local index = spine.utils.indexOf(self.boundingBoxes, attachment) + local index = utils.indexOf(self.boundingBoxes, attachment) if index == -1 then return nil else diff --git a/spine-lua/SkeletonClipping.lua b/spine-lua/SkeletonClipping.lua index 49d88f181..692a7a534 100644 --- a/spine-lua/SkeletonClipping.lua +++ b/spine-lua/SkeletonClipping.lua @@ -66,7 +66,7 @@ function SkeletonClipping:clipStart(slot, clip) clip:computeWorldVertices(slot, 0, n, vertices, 0, 2) self:makeClockwise(self.clippingPolygon) self.clippingPolygons = self.triangulator:decompose(self.clippingPolygon, self.triangulator:triangulate(self.clippingPolygon)) - for i,polygon in ipairs(self.clippingPolygons) do + for _,polygon in ipairs(self.clippingPolygons) do self:makeClockwise(polygon) table_insert(polygon, polygon[1]) table_insert(polygon, polygon[2]) @@ -274,7 +274,7 @@ function SkeletonClipping:clip(x1, y1, x2, y2, x3, y3, clippingArea, output) end if outputStart == #output then -- All edges outside. - for i, v in ipairs(originalOutput) do + for i, _ in ipairs(originalOutput) do originalOutput[i] = nil end return true @@ -286,7 +286,7 @@ function SkeletonClipping:clip(x1, y1, x2, y2, x3, y3, clippingArea, output) if (i == clippingVerticesLast) then break end local temp = output output = input - for i, v in ipairs(output) do + for i, _ in ipairs(output) do output[i] = nil end input = temp @@ -294,7 +294,7 @@ function SkeletonClipping:clip(x1, y1, x2, y2, x3, y3, clippingArea, output) end if originalOutput ~= output then - for i, v in ipairs(originalOutput) do + for i, _ in ipairs(originalOutput) do originalOutput[i] = nil end i = 1 diff --git a/spine-lua/SkeletonData.lua b/spine-lua/SkeletonData.lua index 0d358cf20..0e6543df0 100644 --- a/spine-lua/SkeletonData.lua +++ b/spine-lua/SkeletonData.lua @@ -56,7 +56,7 @@ end function SkeletonData:findBone (boneName) if not boneName then error("boneName cannot be nil.", 2) end - for i,bone in ipairs(self.bones) do + for _,bone in ipairs(self.bones) do if bone.name == boneName then return bone end end return nil @@ -85,7 +85,7 @@ end function SkeletonData:findSkin (skinName) if not skinName then error("skinName cannot be nil.", 2) end - for i,skin in ipairs(self.skins) do + for _,skin in ipairs(self.skins) do if skin.name == skinName then return skin end end return nil @@ -93,7 +93,7 @@ end function SkeletonData:findEvent (eventName) if not eventName then error("eventName cannot be nil.", 2) end - for i,event in ipairs(self.events) do + for _,event in ipairs(self.events) do if event.name == eventName then return event end end return nil @@ -101,7 +101,7 @@ end function SkeletonData:findAnimation (animationName) if not animationName then error("animationName cannot be nil.", 2) end - for i,animation in ipairs(self.animations) do + for _,animation in ipairs(self.animations) do if animation.name == animationName then return animation end end return nil @@ -109,7 +109,7 @@ end function SkeletonData:findIkConstraint (constraintName) if not constraintName then error("constraintName cannot be nil.", 2) end - for i,constraint in ipairs(self.ikConstraints) do + for _,constraint in ipairs(self.ikConstraints) do if constraint.name == constraintName then return constraint end end return nil @@ -117,7 +117,7 @@ end function SkeletonData:findTransformConstraint (constraintName) if not constraintName then error("constraintName cannot be nil.", 2) end - for i,constraint in ipairs(self.transformConstraints) do + for _,constraint in ipairs(self.transformConstraints) do if constraint.name == constraintName then return constraint end end return nil @@ -125,7 +125,7 @@ end function SkeletonData:findPathConstraint (constraintName) if not constraintName then error("constraintName cannot be nil.", 2) end - for i,constraint in ipairs(self.pathConstraints) do + for _,constraint in ipairs(self.pathConstraints) do if constraint.name == constraintName then return constraint end end return nil diff --git a/spine-lua/SkeletonJson.lua b/spine-lua/SkeletonJson.lua index e170b5f24..57116c61d 100644 --- a/spine-lua/SkeletonJson.lua +++ b/spine-lua/SkeletonJson.lua @@ -60,7 +60,7 @@ function SkeletonJson.new (attachmentLoader) } function self:readSkeletonDataFile (fileName, base) - return self:readSkeletonData(spine.utils.readFile(fileName, base)) + return self:readSkeletonData(utils.readFile(fileName, base)) end local readAttachment @@ -76,7 +76,7 @@ function SkeletonJson.new (attachmentLoader) function self:readSkeletonData (jsonText) local scale = self.scale local skeletonData = SkeletonData.new(self.attachmentLoader) - local root = spine.utils.readJSON(jsonText) + local root = utils.readJSON(jsonText) if not root then error("Invalid JSON: " .. jsonText, 2) end -- Skeleton. @@ -117,7 +117,6 @@ function SkeletonJson.new (attachmentLoader) -- Slots. if root["slots"] then for i,slotMap in ipairs(root["slots"]) do - local index = i local slotName = slotMap["name"] local boneName = slotMap["bone"] local boneData = skeletonData:findBone(boneName) @@ -151,11 +150,11 @@ function SkeletonJson.new (attachmentLoader) -- IK constraints. if root["ik"] then - for i,constraintMap in ipairs(root["ik"]) do + for _,constraintMap in ipairs(root["ik"]) do local data = IkConstraintData.new(constraintMap["name"]) data.order = getValue(constraintMap, "order", 0) - for i,boneName in ipairs(constraintMap["bones"]) do + for _,boneName in ipairs(constraintMap["bones"]) do local bone = skeletonData:findBone(boneName) if not bone then error("IK bone not found: " .. boneName) end table_insert(data.bones, bone) @@ -174,11 +173,11 @@ function SkeletonJson.new (attachmentLoader) -- Transform constraints if root["transform"] then - for i,constraintMap in ipairs(root["transform"]) do - data = TransformConstraintData.new(constraintMap.name) + for _,constraintMap in ipairs(root["transform"]) do + local data = TransformConstraintData.new(constraintMap.name) data.order = getValue(constraintMap, "order", 0) - for i,boneName in ipairs(constraintMap.bones) do + for _,boneName in ipairs(constraintMap.bones) do local bone = skeletonData:findBone(boneName) if not bone then error("Transform constraint bone not found: " .. boneName, 2) end table_insert(data.bones, bone) @@ -186,7 +185,7 @@ function SkeletonJson.new (attachmentLoader) local targetName = constraintMap.target data.target = skeletonData:findBone(targetName) - if not data.target then error("Transform constraint target bone not found: " .. boneName, 2) end + if not data.target then error("Transform constraint target bone not found: " .. (targetName or "none"), 2) end data.offsetRotation = getValue(constraintMap, "rotation", 0); data.offsetX = getValue(constraintMap, "x", 0) * scale; @@ -206,11 +205,11 @@ function SkeletonJson.new (attachmentLoader) -- Path constraints if root["path"] then - for i,constraintMap in ipairs(root.path) do + for _,constraintMap in ipairs(root.path) do local data = PathConstraintData.new(constraintMap.name); data.order = getValue(constraintMap, "order", 0) - for i,boneName in ipairs(constraintMap.bones) do + for _,boneName in ipairs(constraintMap.bones) do local bone = skeletonData:findBone(boneName) if not bone then error("Path constraint bone not found: " .. boneName, 2) end table_insert(data.bones, bone) @@ -254,7 +253,7 @@ function SkeletonJson.new (attachmentLoader) end -- Linked meshes - for i, linkedMesh in ipairs(self.linkedMeshes) do + for _, linkedMesh in ipairs(self.linkedMeshes) do local skin = skeletonData.defaultSkin if linkedMesh.skin then skin = skeletonData:findSkin(linkedMesh.skin) end if not skin then error("Skin not found: " .. linkedMesh.skin) end @@ -331,7 +330,7 @@ function SkeletonJson.new (attachmentLoader) elseif type == AttachmentType.mesh or type == AttachmentType.linkedmesh then local mesh = attachmentLoader:newMeshAttachment(skin, name, path) - if not mesh then return null end + if not mesh then return nil end mesh.path = path local color = map.color @@ -487,7 +486,7 @@ function SkeletonJson.new (attachmentLoader) timeline.slotIndex = slotIndex local frameIndex = 0 - for i,valueMap in ipairs(values) do + for _,valueMap in ipairs(values) do local color = valueMap["color"] timeline:setFrame( frameIndex, valueMap["time"], @@ -506,7 +505,7 @@ function SkeletonJson.new (attachmentLoader) timeline.slotIndex = slotIndex local frameIndex = 0 - for i,valueMap in ipairs(values) do + for _,valueMap in ipairs(values) do local light = valueMap["light"] local dark = valueMap["dark"] timeline:setFrame( @@ -529,7 +528,7 @@ function SkeletonJson.new (attachmentLoader) timeline.slotIndex = slotIndex local frameIndex = 0 - for i,valueMap in ipairs(values) do + for _,valueMap in ipairs(values) do local attachmentName = valueMap["name"] timeline:setFrame(frameIndex, valueMap["time"], attachmentName) frameIndex = frameIndex + 1 @@ -557,7 +556,7 @@ function SkeletonJson.new (attachmentLoader) timeline.boneIndex = boneIndex local frameIndex = 0 - for i,valueMap in ipairs(values) do + for _,valueMap in ipairs(values) do timeline:setFrame(frameIndex, valueMap["time"], valueMap["angle"]) readCurve(valueMap, timeline, frameIndex) frameIndex = frameIndex + 1 @@ -579,7 +578,7 @@ function SkeletonJson.new (attachmentLoader) timeline.boneIndex = boneIndex local frameIndex = 0 - for i,valueMap in ipairs(values) do + for _,valueMap in ipairs(values) do local x = (valueMap["x"] or 0) * timelineScale local y = (valueMap["y"] or 0) * timelineScale timeline:setFrame(frameIndex, valueMap["time"], x, y) @@ -608,7 +607,7 @@ function SkeletonJson.new (attachmentLoader) end end local frameIndex = 0 - for i,valueMap in ipairs(values) do + for _,valueMap in ipairs(values) do local mix = 1 if valueMap["mix"] ~= nil then mix = valueMap["mix"] end local bendPositive = 1 @@ -635,7 +634,7 @@ function SkeletonJson.new (attachmentLoader) end end local frameIndex = 0 - for i,valueMap in ipairs(values) do + for _,valueMap in ipairs(values) do timeline:setFrame(frameIndex, valueMap.time, getValue(valueMap, "rotateMix", 1), getValue(valueMap, "translateMix", 1), getValue(valueMap, "scaleMix", 1), getValue(valueMap, "shearMix", 1)) readCurve(valueMap, timeline, frameIndex) frameIndex = frameIndex + 1 @@ -664,7 +663,7 @@ function SkeletonJson.new (attachmentLoader) end timeline.pathConstraintIndex = index local frameIndex = 0 - for i,valueMap in ipairs(timelineMap) do + for _,valueMap in ipairs(timelineMap) do timeline:setFrame(frameIndex, valueMap.time, getValue(valueMap, timelineName, 0) * timelineScale) readCurve(valueMap, timeline, frameIndex) frameIndex = frameIndex + 1 @@ -675,7 +674,7 @@ function SkeletonJson.new (attachmentLoader) local timeline = Animation.PathConstraintMixTimeline.new(#timelineMap) timeline.pathConstraintIndex = index local frameIndex = 0 - for i,valueMap in ipairs(timelineMap) do + for _,valueMap in ipairs(timelineMap) do timeline:setFrame(frameIndex, valueMap.time, getValue(valueMap, "rotateMix", 1), getValue(valueMap, "translateMix", 1)) readCurve(valueMap, timeline, frameIndex) frameIndex = frameIndex + 1 @@ -708,7 +707,7 @@ function SkeletonJson.new (attachmentLoader) timeline.attachment = attachment local frameIndex = 0 - for i,valueMap in ipairs(timelineMap) do + for _,valueMap in ipairs(timelineMap) do local deform = nil local verticesValue = getValue(valueMap, "vertices", nil) if verticesValue == nil then @@ -754,7 +753,7 @@ function SkeletonJson.new (attachmentLoader) local timeline = Animation.DrawOrderTimeline.new(#drawOrderValues) local slotCount = #skeletonData.slots local frameIndex = 0 - for i,drawOrderMap in ipairs(drawOrderValues) do + for _,drawOrderMap in ipairs(drawOrderValues) do local drawOrder = nil local offsets = drawOrderMap["offsets"] if offsets then @@ -762,7 +761,7 @@ function SkeletonJson.new (attachmentLoader) local unchanged = {} local originalIndex = 1 local unchangedIndex = 1 - for ii,offsetMap in ipairs(offsets) do + for _,offsetMap in ipairs(offsets) do local slotIndex = skeletonData:findSlotIndex(offsetMap["slot"]) if slotIndex == -1 then error("Slot not found: " .. offsetMap["slot"]) end -- Collect unchanged items. @@ -801,7 +800,7 @@ function SkeletonJson.new (attachmentLoader) if events then local timeline = Animation.EventTimeline.new(#events) local frameIndex = 0 - for i,eventMap in ipairs(events) do + for _,eventMap in ipairs(events) do local eventData = skeletonData:findEvent(eventMap["name"]) if not eventData then error("Event not found: " .. eventMap["name"]) end local event = Event.new(eventMap["time"], eventData) diff --git a/spine-lua/Skin.lua b/spine-lua/Skin.lua index f0c1c5fda..a403ab9a6 100644 --- a/spine-lua/Skin.lua +++ b/spine-lua/Skin.lua @@ -86,14 +86,14 @@ end function Skin:findNamesForSlot (slotIndex) local names = {} - for k,v in self.attachments do + for _,v in self.attachments do if v[1] == slotIndex then table_insert(names, v[2]) end end end function Skin:findAttachmentsForSlot (slotIndex) local attachments = {} - for k,v in self.attachments do + for _,v in self.attachments do if v[1] == slotIndex then table_insert(attachments, v[3]) end end end diff --git a/spine-lua/TextureAtlas.lua b/spine-lua/TextureAtlas.lua index 96cf5f847..d586002b2 100644 --- a/spine-lua/TextureAtlas.lua +++ b/spine-lua/TextureAtlas.lua @@ -235,14 +235,14 @@ function TextureAtlas:parse (atlasContent, imageLoader) end function TextureAtlas:findRegion(name) - for i, region in ipairs(self.regions) do + for _, region in ipairs(self.regions) do if region.name == name then return region end end return nil end function TextureAtlas:dispose() - for i, page in ipairs(self.pairs) do + for _, page in ipairs(self.pairs) do -- FIXME implement disposing of pages -- love2d doesn't support manual disposing end diff --git a/spine-lua/TransformConstraint.lua b/spine-lua/TransformConstraint.lua index 5f97b8936..436366ba1 100644 --- a/spine-lua/TransformConstraint.lua +++ b/spine-lua/TransformConstraint.lua @@ -41,6 +41,7 @@ local table_insert = table.insert local math_deg = math.deg local math_rad = math.rad local math_abs = math.abs +local math_floor = math.floor local TransformConstraint = {} TransformConstraint.__index = TransformConstraint @@ -58,7 +59,7 @@ function TransformConstraint.new (data, skeleton) } setmetatable(self, TransformConstraint) - for i,bone in ipairs(data.bones) do + for _,bone in ipairs(data.bones) do table_insert(self.bones, skeleton:findBone(bone.name)) end self.target = skeleton:findBone(data.target.name) @@ -101,7 +102,7 @@ function TransformConstraint:applyAbsoluteWorld () local offsetRotation = self.data.offsetRotation * degRadReflect local offsetShearY = self.data.offsetShearY * degRadReflect local bones = self.bones - for i, bone in ipairs(bones) do + for _, bone in ipairs(bones) do local modified = false if rotateMix ~= 0 then local a = bone.a @@ -188,7 +189,7 @@ function TransformConstraint:applyRelativeWorld () local offsetRotation = self.data.offsetRotation * degRadReflect local offsetShearY = self.data.offsetShearY * degRadReflect local bones = self.bones - for i, bone in ipairs(bones) do + for _, bone in ipairs(bones) do local modified = false if rotateMix ~= 0 then @@ -226,7 +227,7 @@ function TransformConstraint:applyRelativeWorld () local s = (math_sqrt(ta * ta + tc * tc) - 1 + self.data.offsetScaleX) * scaleMix + 1 bone.a = bone.a * s bone.c = bone.c * s - local s = (math_sqrt(tb * tb + td * td) - 1 + self.data.offsetScaleY) * scaleMix + 1 + s = (math_sqrt(tb * tb + td * td) - 1 + self.data.offsetScaleY) * scaleMix + 1 bone.b = bone.b * s bone.d = bone.d * s modified = true @@ -260,7 +261,7 @@ function TransformConstraint:applyAbsoluteLocal () local target = self.target if not target.appliedValid then target:updatedAppliedTransform() end local bones = self.bones - for i, bone in ipairs(bones) do + for _, bone in ipairs(bones) do local modified = false if not bone.appliedValid then bone:updateAppliedTransform() end @@ -308,7 +309,7 @@ function TransformConstraint:applyRelativeLocal () local target = self.target if not target.appliedValid then target:updateAppliedTransform() end local bones = self.bones - for i, bone in ipairs(bones) do + for _, bone in ipairs(bones) do if not bone.appliedValid then bone:updateAppliedTransform() end local rotation = bone.arotation @@ -328,7 +329,7 @@ function TransformConstraint:applyRelativeLocal () scaleX = scaleX * (((target.ascaleX - 1 + self.data.offsetScaleX) * scaleMix) + 1) end if scaleY > 0.00001 then - scaleY = scaleY * (((target.ascaleY - 1 + this.data.offsetScaleY) * scaleMix) + 1) + scaleY = scaleY * (((target.ascaleY - 1 + self.data.offsetScaleY) * scaleMix) + 1) end end