[lua] 4.0 port fixes.

This commit is contained in:
Nathan Sweet 2021-06-05 21:55:01 -04:00
parent a5be08a62a
commit 6428b82e1e
6 changed files with 26 additions and 24 deletions

View File

@ -66,7 +66,7 @@ package spine.animation {
return; return;
} }
var x : Number = 0, y : Number = 0; var x : Number, y : Number;
var i : int = search(frames, time, ENTRIES); var i : int = search(frames, time, ENTRIES);
var curveType : Number = curves[i / ENTRIES]; var curveType : Number = curves[i / ENTRIES];
switch (curveType) { switch (curveType) {

View File

@ -53,14 +53,14 @@ function loadSkeleton (jsonFile, atlasFile, animation, skin, scale, x, y)
local stateData = spine.AnimationStateData.new(skeletonData) local stateData = spine.AnimationStateData.new(skeletonData)
local state = spine.AnimationState.new(stateData) local state = spine.AnimationState.new(stateData)
state:setAnimationByName(0, animation, true) state:setAnimationByName(0, animation, true)
if (jsonFile == "spineboy-pro") then if jsonFile == "spineboy-pro" then
stateData:setMix("walk", "jump", 0.5) stateData:setMix("walk", "jump", 0.5)
stateData:setMix("jump", "run", 0.5) stateData:setMix("jump", "run", 0.5)
state:addAnimationByName(0, "jump", false, 3) state:addAnimationByName(0, "jump", false, 3)
state:addAnimationByName(0, "run", true, 0) state:addAnimationByName(0, "run", true, 0)
end end
if (jsonFile == "raptor-pro") then if jsonFile == "raptor-pro" then
swirl.centerY = -200 swirl.centerY = -200
skeleton.vertexEffect = swirl skeleton.vertexEffect = swirl
-- skeleton.vertexEffect = spine.JitterEffect.new(10, 10) -- skeleton.vertexEffect = spine.JitterEffect.new(10, 10)
@ -113,12 +113,12 @@ end
function love.load(arg) function love.load(arg)
if arg[#arg] == "-debug" then require("mobdebug").start() end if arg[#arg] == "-debug" then require("mobdebug").start() end
skeletonRenderer = spine.SkeletonRenderer.new(true) skeletonRenderer = spine.SkeletonRenderer.new(true)
table.insert(skeletons, loadSkeleton("spineboy-pro", "spineboy", "walk", nil, 0.5, 400, 500)) table.insert(skeletons, loadSkeleton("goblins-pro", "goblins", "walk", "goblin", 1, 400, 500))
table.insert(skeletons, loadSkeleton("mix-and-match-pro", "mix-and-match", "dance", nil, 0.5, 400, 500)) table.insert(skeletons, loadSkeleton("mix-and-match-pro", "mix-and-match", "dance", nil, 0.5, 400, 500))
table.insert(skeletons, loadSkeleton("spineboy-pro", "spineboy", "walk", nil, 0.5, 400, 500))
table.insert(skeletons, loadSkeleton("stretchyman-pro", "stretchyman", "sneak", nil, 0.5, 200, 500)) table.insert(skeletons, loadSkeleton("stretchyman-pro", "stretchyman", "sneak", nil, 0.5, 200, 500))
table.insert(skeletons, loadSkeleton("coin-pro", "coin", "animation", nil, 0.5, 400, 300)) table.insert(skeletons, loadSkeleton("coin-pro", "coin", "animation", nil, 0.5, 400, 300))
table.insert(skeletons, loadSkeleton("raptor-pro", "raptor", "walk", nil, 0.3, 400, 500)) table.insert(skeletons, loadSkeleton("raptor-pro", "raptor", "walk", nil, 0.3, 400, 500))
table.insert(skeletons, loadSkeleton("goblins-pro", "goblins", "walk", "goblin", 1, 400, 500))
table.insert(skeletons, loadSkeleton("tank-pro", "tank", "drive", nil, 0.2, 600, 500)) table.insert(skeletons, loadSkeleton("tank-pro", "tank", "drive", nil, 0.2, 600, 500))
table.insert(skeletons, loadSkeleton("vine-pro", "vine", "grow", nil, 0.3, 400, 500)) table.insert(skeletons, loadSkeleton("vine-pro", "vine", "grow", nil, 0.3, 400, 500))
end end
@ -131,9 +131,9 @@ function love.update (delta)
state:apply(skeleton) state:apply(skeleton)
skeleton:updateWorldTransform() skeleton:updateWorldTransform()
if (skeleton.vertexEffect) then if skeleton.vertexEffect then
skeletonRenderer.vertexEffect = skeleton.vertexEffect skeletonRenderer.vertexEffect = skeleton.vertexEffect
if (skeleton.vertexEffect == swirl) then if skeleton.vertexEffect == swirl then
swirlTime = swirlTime + delta swirlTime = swirlTime + delta
local percent = swirlTime % 2 local percent = swirlTime % 2
if (percent > 1) then percent = 1 - (percent - 1) end if (percent > 1) then percent = 1 - (percent - 1) end
@ -148,7 +148,6 @@ function love.draw ()
love.graphics.setBackgroundColor(0, 0, 0, 255) love.graphics.setBackgroundColor(0, 0, 0, 255)
love.graphics.setColor(255, 255, 255) love.graphics.setColor(255, 255, 255)
local skeleton = skeletons[activeSkeleton].skeleton local skeleton = skeletons[activeSkeleton].skeleton
skeletonRenderer:draw(skeleton) skeletonRenderer:draw(skeleton)
end end

View File

@ -262,6 +262,7 @@ function Animation.CurveTimeline.new (timelineType, frameEntries, frameCount, be
return y + (time - x) / (curves[i] - x) * (curves[i + 1] - y) return y + (time - x) / (curves[i] - x) * (curves[i + 1] - y)
end end
local n = i + BEZIER_SIZE local n = i + BEZIER_SIZE
i = i + 2
while i < n do while i < n do
if curves[i] >= time then if curves[i] >= time then
local x = curves[i - 2] local x = curves[i - 2]
@ -365,9 +366,10 @@ function Animation.RotateTimeline.new (frameCount, bezierCount, boneIndex)
local r = self:getCurveValue(time) local r = self:getCurveValue(time)
if blend == MixBlend.setup then if blend == MixBlend.setup then
bone.rotation = bone.data.rotation + r * alpha bone.rotation = bone.data.rotation + r * alpha
elseif blend == MixBlend.first or blend == MixBlend.replace then else
r = r + bone.data.rotation - bone.rotation if blend == MixBlend.first or blend == MixBlend.replace then
elseif blend == MixBlend.add then r = r + bone.data.rotation - bone.rotation
end
bone.rotation = bone.rotation + r * alpha bone.rotation = bone.rotation + r * alpha
end end
end end
@ -529,8 +531,8 @@ function Animation.ScaleTimeline.new (frameCount, bezierCount, boneIndex)
return return
end end
local x = 0 local x
local y = 0 local y
local i = search(frames, time, ENTRIES) local i = search(frames, time, ENTRIES)
local curveType = self.curves[math_floor(i / ENTRIES)] local curveType = self.curves[math_floor(i / ENTRIES)]
if curveType == LINEAR then if curveType == LINEAR then

View File

@ -61,20 +61,16 @@ function SkeletonJson.new (attachmentLoader)
linkedMeshes = {} linkedMeshes = {}
} }
function self:readSkeletonDataFile (fileName, base)
return self:readSkeletonData(utils.readFile(fileName, base))
end
local readAttachment local readAttachment
local readAnimation local readAnimation
local readCurve local readCurve
local readTimeline1 local readTimeline1
local readTimeline2 local readTimeline2
local getArray local getArray
local getValue
local getValue = function (map, name, default) function self:readSkeletonDataFile (fileName, base)
local value = map[name] return self:readSkeletonData(utils.readFile(fileName, base))
if value == nil then return default else return value end
end end
function self:readSkeletonData (jsonText) function self:readSkeletonData (jsonText)
@ -981,6 +977,7 @@ function SkeletonJson.new (attachmentLoader)
local time = getValue(keyMap, "time", 0) local time = getValue(keyMap, "time", 0)
local bezier = 0 local bezier = 0
for i,keyMap in ipairs(timelineMap) do for i,keyMap in ipairs(timelineMap) do
local frame = i - 1
local deform = nil local deform = nil
local verticesValue = getValue(keyMap, "vertices", nil) local verticesValue = getValue(keyMap, "vertices", nil)
if verticesValue == nil then if verticesValue == nil then
@ -1007,7 +1004,6 @@ function SkeletonJson.new (attachmentLoader)
end end
end end
end end
local frame = i - 1
timeline:setFrame(frame, time, deform) timeline:setFrame(frame, time, deform)
local nextMap = timelineMap[frame + 1] local nextMap = timelineMap[frame + 1]
if not nextMap then if not nextMap then
@ -1200,6 +1196,11 @@ function SkeletonJson.new (attachmentLoader)
return values return values
end end
getValue = function (map, name, default)
local value = map[name]
if value == nil then return default else return value end
end
return self return self
end end
return SkeletonJson return SkeletonJson

View File

@ -88,7 +88,7 @@ function TextureAtlas:parse (atlasContent, imageLoader)
local colon = line:find(":") local colon = line:find(":")
if not colon then return 0 end if not colon then return 0 end
entry[0] = trim(line:sub(1, colon)) entry[0] = trim(line:sub(1, colon - 1))
local lastMatch = colon + 1 local lastMatch = colon + 1
local i = 1 local i = 1
while true do while true do
@ -97,7 +97,7 @@ function TextureAtlas:parse (atlasContent, imageLoader)
entry[i] = trim(line:sub(lastMatch)) entry[i] = trim(line:sub(lastMatch))
return i return i
end end
entry[i] = trim(line:sub(lastMatch, comma - lastMatch)) entry[i] = trim(line:sub(lastMatch, comma - 1))
lastMatch = comma + 1 lastMatch = comma + 1
if i == 4 then return 4 end if i == 4 then return 4 end
i = i + 1 i = i + 1

View File

@ -566,7 +566,7 @@ module spine {
return; return;
} }
let x = 0, y = 0; let x, y;
let i = Timeline.search(frames, time, 3/*ENTRIES*/); let i = Timeline.search(frames, time, 3/*ENTRIES*/);
let curveType = this.curves[i / 3/*ENTRIES*/]; let curveType = this.curves[i / 3/*ENTRIES*/];
switch (curveType) { switch (curveType) {