From 05327b8d1150371c4ed1ab8fe8bbd32d43c3114c Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Sun, 30 May 2021 13:01:08 -0400 Subject: [PATCH] [ts] Clean up. --- spine-ts/core/src/Animation.ts | 343 ++++++++--------- spine-ts/core/src/AnimationState.ts | 29 +- spine-ts/core/src/PathConstraint.ts | 90 ++--- spine-ts/core/src/PathConstraintData.ts | 8 +- spine-ts/core/src/SkeletonBinary.ts | 19 +- spine-ts/core/src/SkeletonJson.ts | 457 +++++++++++------------ spine-ts/core/src/TransformConstraint.ts | 4 +- spine-ts/core/src/Utils.ts | 48 ++- 8 files changed, 463 insertions(+), 535 deletions(-) diff --git a/spine-ts/core/src/Animation.ts b/spine-ts/core/src/Animation.ts index 13bd0bdad..d33989263 100644 --- a/spine-ts/core/src/Animation.ts +++ b/spine-ts/core/src/Animation.ts @@ -51,9 +51,8 @@ module spine { } hasTimeline(ids: string[]) { - for (let i = 0; i < ids.length; i++) { + for (let i = 0; i < ids.length; i++) if (this.timelineIds.contains(ids[i])) return true; - } return false; } @@ -74,20 +73,6 @@ module spine { for (let i = 0, n = timelines.length; i < n; i++) timelines[i].apply(skeleton, lastTime, time, events, alpha, blend, direction); } - - static search (frames: ArrayLike, time: number) { - let n = frames.length; - for (let i = 1; i < n; i++) - if (frames[i] > time) return i - 1; - return n - 1; - } - - static search2 (values: ArrayLike, time: number, step: number) { - let n = values.length; - for (let i = step; i < n; i += step) - if (values[i] > time) return i - step; - return n - step; - } } /** Controls how a timeline value is mixed with the setup pose value or current pose value when a timeline's `alpha` @@ -133,7 +118,6 @@ module spine { event, drawOrder, // ikConstraint, transformConstraint, // pathConstraintPosition, pathConstraintSpacing, pathConstraintMix - } /** The interface for all timelines. */ @@ -150,7 +134,9 @@ module spine { return this.propertyIds; } - abstract getFrameEntries (): number; + getFrameEntries (): number { + return 1; + } getFrameCount () { return this.frames.length / this.getFrameEntries(); @@ -161,6 +147,20 @@ module spine { } abstract apply (skeleton: Skeleton, lastTime: number, time: number, events: Array, alpha: number, blend: MixBlend, direction: MixDirection): void; + + static search (frames: ArrayLike, time: number) { + let n = frames.length; + for (let i = 1; i < n; i++) + if (frames[i] > time) return i - 1; + return n - 1; + } + + static search2 (values: ArrayLike, time: number, step: number) { + let n = values.length; + for (let i = step; i < n; i += step) + if (values[i] > time) return i - step; + return n - step; + } } export interface BoneTimeline { @@ -249,7 +249,6 @@ module spine { * @param i The index of the Bezier segments. See {@link #getCurveType(int)}. */ getBezierValue (time: number, frameIndex: number, valueOffset: number, i: number) { let curves = this.curves; - let frames = this.frames; if (curves[i] > time) { let x = frames[frameIndex], y = frames[frameIndex + valueOffset]; return y + (time - x) / (curves[i] - x) * (curves[i + 1] - y); @@ -275,7 +274,7 @@ module spine { super(frameCount, bezierCount, propertyIds); } - getFrameEntries() { + getFrameEntries () { return CurveTimeline1.ENTRIES; } @@ -307,7 +306,7 @@ module spine { case CurveTimeline.STEPPED: return frames[i + CurveTimeline1.VALUE]; } - return this.getBezierValue(time, i, CurveTimeline1.VALUE, curveType - CurveTimeline1.BEZIER); + return this.getBezierValue(time, i, CurveTimeline1.VALUE, curveType - CurveTimeline.BEZIER); } } @@ -332,10 +331,9 @@ module spine { * @param time The frame time in seconds. */ setFrame (frame: number, time: number, value1: number, value2: number) { frame *= CurveTimeline2.ENTRIES; - let frames = this.frames; - frames[frame] = time; - frames[frame + CurveTimeline2.VALUE1] = value1; - frames[frame + CurveTimeline2.VALUE2] = value2; + this.frames[frame] = time; + this.frames[frame + CurveTimeline2.VALUE1] = value1; + this.frames[frame + CurveTimeline2.VALUE2] = value2; } } @@ -351,11 +349,10 @@ module spine { } apply (skeleton: Skeleton, lastTime: number, time: number, events: Array, alpha: number, blend: MixBlend, direction: MixDirection) { - let frames = this.frames; - let bone = skeleton.bones[this.boneIndex]; if (!bone.active) return; + let frames = this.frames; if (time < frames[0]) { switch (blend) { case MixBlend.setup: @@ -394,11 +391,10 @@ module spine { } apply (skeleton: Skeleton, lastTime: number, time: number, events: Array, alpha: number, blend: MixBlend, direction: MixDirection) { - let frames = this.frames; - let bone = skeleton.bones[this.boneIndex]; if (!bone.active) return; + let frames = this.frames; if (time < frames[0]) { switch (blend) { case MixBlend.setup: @@ -413,7 +409,7 @@ module spine { } let x = 0, y = 0; - let i = Animation.search2(frames, time, CurveTimeline2.ENTRIES); + let i = Timeline.search2(frames, time, CurveTimeline2.ENTRIES); let curveType = this.curves[i / CurveTimeline2.ENTRIES]; switch (curveType) { case CurveTimeline.LINEAR: @@ -462,11 +458,10 @@ module spine { } apply (skeleton: Skeleton, lastTime: number, time: number, events: Array, alpha: number, blend: MixBlend, direction: MixDirection) { - let frames = this.frames; - let bone = skeleton.bones[this.boneIndex]; if (!bone.active) return; + let frames = this.frames; if (time < frames[0]) { switch (blend) { case MixBlend.setup: @@ -505,11 +500,10 @@ module spine { } apply (skeleton: Skeleton, lastTime: number, time: number, events: Array, alpha: number, blend: MixBlend, direction: MixDirection) { - let frames = this.frames; - let bone = skeleton.bones[this.boneIndex]; if (!bone.active) return; + let frames = this.frames; if (time < frames[0]) { switch (blend) { case MixBlend.setup: @@ -549,11 +543,10 @@ module spine { } apply (skeleton: Skeleton, lastTime: number, time: number, events: Array, alpha: number, blend: MixBlend, direction: MixDirection) { - let frames = this.frames; - let bone = skeleton.bones[this.boneIndex]; if (!bone.active) return; + let frames = this.frames; if (time < frames[0]) { switch (blend) { case MixBlend.setup: @@ -568,7 +561,7 @@ module spine { } let x = 0, y = 0; - let i = Animation.search2(frames, time, CurveTimeline2.ENTRIES); + let i = Timeline.search2(frames, time, CurveTimeline2.ENTRIES); let curveType = this.curves[i / CurveTimeline2.ENTRIES]; switch (curveType) { case CurveTimeline.LINEAR: @@ -584,8 +577,8 @@ module spine { y = frames[i + CurveTimeline2.VALUE2]; break; default: - x = this.getBezierValue(time, i, CurveTimeline2.VALUE1, curveType - CurveTimeline2.BEZIER); - y = this.getBezierValue(time, i, CurveTimeline2.VALUE2, curveType + CurveTimeline2.BEZIER_SIZE - CurveTimeline2.BEZIER); + x = this.getBezierValue(time, i, CurveTimeline2.VALUE1, curveType - CurveTimeline.BEZIER); + y = this.getBezierValue(time, i, CurveTimeline2.VALUE2, curveType + CurveTimeline.BEZIER_SIZE - CurveTimeline.BEZIER); } x *= bone.data.scaleX; y *= bone.data.scaleY; @@ -659,11 +652,10 @@ module spine { } apply (skeleton: Skeleton, lastTime: number, time: number, events: Array, alpha: number, blend: MixBlend, direction: MixDirection) { - let frames = this.frames; - let bone = skeleton.bones[this.boneIndex]; if (!bone.active) return; + let frames = this.frames; if (time < frames[0]) { switch (blend) { case MixBlend.setup: @@ -731,11 +723,10 @@ module spine { } apply (skeleton: Skeleton, lastTime: number, time: number, events: Array, alpha: number, blend: MixBlend, direction: MixDirection) { - let frames = this.frames; - let bone = skeleton.bones[this.boneIndex]; if (!bone.active) return; + let frames = this.frames; if (time < frames[0]) { switch (blend) { case MixBlend.setup: @@ -804,11 +795,10 @@ module spine { } apply (skeleton: Skeleton, lastTime: number, time: number, events: Array, alpha: number, blend: MixBlend, direction: MixDirection) { - let frames = this.frames; - let bone = skeleton.bones[this.boneIndex]; if (!bone.active) return; + let frames = this.frames; if (time < frames[0]) { switch (blend) { case MixBlend.setup: @@ -823,10 +813,10 @@ module spine { } let x = 0, y = 0; - let i = Animation.search2(frames, time, CurveTimeline2.ENTRIES); + let i = Timeline.search2(frames, time, CurveTimeline2.ENTRIES); let curveType = this.curves[i / CurveTimeline2.ENTRIES]; switch (curveType) { - case CurveTimeline2.LINEAR: + case CurveTimeline.LINEAR: let before = frames[i]; x = frames[i + CurveTimeline2.VALUE1]; y = frames[i + CurveTimeline2.VALUE2]; @@ -834,13 +824,13 @@ module spine { x += (frames[i + CurveTimeline2.ENTRIES + CurveTimeline2.VALUE1] - x) * t; y += (frames[i + CurveTimeline2.ENTRIES + CurveTimeline2.VALUE2] - y) * t; break; - case CurveTimeline2.STEPPED: + case CurveTimeline.STEPPED: x = frames[i + CurveTimeline2.VALUE1]; y = frames[i + CurveTimeline2.VALUE2]; break; default: - x = this.getBezierValue(time, i, CurveTimeline2.VALUE1, curveType - CurveTimeline2.BEZIER); - y = this.getBezierValue(time, i, CurveTimeline2.VALUE2, curveType + CurveTimeline2.BEZIER_SIZE - CurveTimeline2.BEZIER); + x = this.getBezierValue(time, i, CurveTimeline2.VALUE1, curveType - CurveTimeline.BEZIER); + y = this.getBezierValue(time, i, CurveTimeline2.VALUE2, curveType + CurveTimeline.BEZIER_SIZE - CurveTimeline.BEZIER); } switch (blend) { @@ -872,11 +862,10 @@ module spine { } apply (skeleton: Skeleton, lastTime: number, time: number, events: Array, alpha: number, blend: MixBlend, direction: MixDirection) { - let frames = this.frames; - let bone = skeleton.bones[this.boneIndex]; if (!bone.active) return; + let frames = this.frames; if (time < frames[0]) { switch (blend) { case MixBlend.setup: @@ -915,11 +904,10 @@ module spine { } apply (skeleton: Skeleton, lastTime: number, time: number, events: Array, alpha: number, blend: MixBlend, direction: MixDirection) { - let frames = this.frames; - let bone = skeleton.bones[this.boneIndex]; if (!bone.active) return; + let frames = this.frames; if (time < frames[0]) { switch (blend) { case MixBlend.setup: @@ -981,8 +969,9 @@ module spine { if (!slot.bone.active) return; let frames = this.frames; + let color = slot.color; if (time < frames[0]) { - let color = slot.color, setup = slot.data.color; + let setup = slot.data.color; switch (blend) { case MixBlend.setup: color.setFromColor(slot.data.color); @@ -995,10 +984,10 @@ module spine { } let r = 0, g = 0, b = 0, a = 0; - let i = Animation.search2(frames, time, RGBATimeline.ENTRIES); + let i = Timeline.search2(frames, time, RGBATimeline.ENTRIES); let curveType = this.curves[i / RGBATimeline.ENTRIES]; switch (curveType) { - case RGBATimeline.LINEAR: + case CurveTimeline.LINEAR: let before = frames[i]; r = frames[i + RGBATimeline.R]; g = frames[i + RGBATimeline.G]; @@ -1010,19 +999,18 @@ module spine { b += (frames[i + RGBATimeline.ENTRIES + RGBATimeline.B] - b) * t; a += (frames[i + RGBATimeline.ENTRIES + RGBATimeline.A] - a) * t; break; - case RGBATimeline.STEPPED: + case CurveTimeline.STEPPED: r = frames[i + RGBATimeline.R]; g = frames[i + RGBATimeline.G]; b = frames[i + RGBATimeline.B]; a = frames[i + RGBATimeline.A]; break; default: - r = this.getBezierValue(time, i, RGBATimeline.R, curveType - RGBATimeline.BEZIER); - g = this.getBezierValue(time, i, RGBATimeline.G, curveType + RGBATimeline.BEZIER_SIZE - RGBATimeline.BEZIER); - b = this.getBezierValue(time, i, RGBATimeline.B, curveType + RGBATimeline.BEZIER_SIZE * 2 - RGBATimeline.BEZIER); - a = this.getBezierValue(time, i, RGBATimeline.A, curveType + RGBATimeline.BEZIER_SIZE * 3 - RGBATimeline.BEZIER); + r = this.getBezierValue(time, i, RGBATimeline.R, curveType - CurveTimeline.BEZIER); + g = this.getBezierValue(time, i, RGBATimeline.G, curveType + CurveTimeline.BEZIER_SIZE - CurveTimeline.BEZIER); + b = this.getBezierValue(time, i, RGBATimeline.B, curveType + CurveTimeline.BEZIER_SIZE * 2 - CurveTimeline.BEZIER); + a = this.getBezierValue(time, i, RGBATimeline.A, curveType + CurveTimeline.BEZIER_SIZE * 3 - CurveTimeline.BEZIER); } - let color = slot.color; if (alpha == 1) color.set(r, g, b, a); else { @@ -1053,7 +1041,7 @@ module spine { /** Sets the time in seconds, red, green, blue, and alpha for the specified key frame. */ setFrame (frame: number, time: number, r: number, g: number, b: number) { - frame *= RGBTimeline.ENTRIES; + frame <<= 2; this.frames[frame] = time; this.frames[frame + RGBTimeline.R] = r; this.frames[frame + RGBTimeline.G] = g; @@ -1065,8 +1053,9 @@ module spine { if (!slot.bone.active) return; let frames = this.frames; + let color = slot.color; if (time < frames[0]) { - let color = slot.color, setup = slot.data.color; + let setup = slot.data.color; switch (blend) { case MixBlend.setup: color.r = setup.r; @@ -1082,10 +1071,10 @@ module spine { } let r = 0, g = 0, b = 0; - let i = Animation.search2(frames, time, RGBTimeline.ENTRIES); - let curveType = this.curves[i / RGBTimeline.ENTRIES]; + let i = Timeline.search2(frames, time, RGBTimeline.ENTRIES); + let curveType = this.curves[i >> 2]; switch (curveType) { - case RGBTimeline.LINEAR: + case CurveTimeline.LINEAR: let before = frames[i]; r = frames[i + RGBTimeline.R]; g = frames[i + RGBTimeline.G]; @@ -1095,17 +1084,16 @@ module spine { g += (frames[i + RGBTimeline.ENTRIES + RGBTimeline.G] - g) * t; b += (frames[i + RGBTimeline.ENTRIES + RGBTimeline.B] - b) * t; break; - case RGBATimeline.STEPPED: + case CurveTimeline.STEPPED: r = frames[i + RGBTimeline.R]; g = frames[i + RGBTimeline.G]; b = frames[i + RGBTimeline.B]; break; default: - r = this.getBezierValue(time, i, RGBTimeline.R, curveType - RGBTimeline.BEZIER); - g = this.getBezierValue(time, i, RGBTimeline.G, curveType + RGBTimeline.BEZIER_SIZE - RGBTimeline.BEZIER); - b = this.getBezierValue(time, i, RGBTimeline.B, curveType + RGBTimeline.BEZIER_SIZE * 2 - RGBTimeline.BEZIER); + r = this.getBezierValue(time, i, RGBTimeline.R, curveType - CurveTimeline.BEZIER); + g = this.getBezierValue(time, i, RGBTimeline.G, curveType + CurveTimeline.BEZIER_SIZE - CurveTimeline.BEZIER); + b = this.getBezierValue(time, i, RGBTimeline.B, curveType + CurveTimeline.BEZIER_SIZE * 2 - CurveTimeline.BEZIER); } - let color = slot.color; if (alpha == 1) { color.r = r; color.g = g; @@ -1136,13 +1124,12 @@ module spine { } apply (skeleton: Skeleton, lastTime: number, time: number, events: Array, alpha: number, blend: MixBlend, direction: MixDirection) { - let frames = this.frames; - let slot = skeleton.slots[this.slotIndex]; if (!slot.bone.active) return; - if (time < frames[0]) { // Time is before first frame. - let color = slot.color, setup = slot.data.color; + let color = slot.color; + if (time < this.frames[0]) { // Time is before first frame. + let setup = slot.data.color; switch (blend) { case MixBlend.setup: color.a = setup.a; @@ -1155,10 +1142,10 @@ module spine { let a = this.getCurveValue(time); if (alpha == 1) - slot.color.a = a; + color.a = a; else { - if (blend == MixBlend.setup) slot.color.a = slot.data.color.a; - slot.color.a += (a - slot.color.a) * alpha; + if (blend == MixBlend.setup) color.a = slot.data.color.a; + color.a += (a - color.a) * alpha; } } } @@ -1186,7 +1173,7 @@ module spine { /** Sets the time in seconds, light, and dark colors for the specified key frame. */ setFrame (frame: number, time: number, r: number, g: number, b: number, a: number, r2: number, g2: number, b2: number) { - frame *= RGBA2Timeline.ENTRIES; + frame <<= 3; this.frames[frame] = time; this.frames[frame + RGBA2Timeline.R] = r; this.frames[frame + RGBA2Timeline.G] = g; @@ -1202,8 +1189,9 @@ module spine { if (!slot.bone.active) return; let frames = this.frames; + let light = slot.color, dark = slot.darkColor; if (time < frames[0]) { - let light = slot.color, dark = slot.darkColor, setupLight = slot.data.color, setupDark = slot.data.darkColor; + let setupLight = slot.data.color, setupDark = slot.data.darkColor; switch (blend) { case MixBlend.setup: light.setFromColor(setupLight); @@ -1222,10 +1210,10 @@ module spine { } let r = 0, g = 0, b = 0, a = 0, r2 = 0, g2 = 0, b2 = 0; - let i = Animation.search2(frames, time, RGBA2Timeline.ENTRIES); + let i = Timeline.search2(frames, time, RGBA2Timeline.ENTRIES); let curveType = this.curves[i >> 3]; switch (curveType) { - case RGBA2Timeline.LINEAR: + case CurveTimeline.LINEAR: let before = frames[i]; r = frames[i + RGBA2Timeline.R]; g = frames[i + RGBA2Timeline.G]; @@ -1243,7 +1231,7 @@ module spine { g2 += (frames[i + RGBA2Timeline.ENTRIES + RGBA2Timeline.G2] - g2) * t; b2 += (frames[i + RGBA2Timeline.ENTRIES + RGBA2Timeline.B2] - b2) * t; break; - case RGBA2Timeline.STEPPED: + case CurveTimeline.STEPPED: r = frames[i + RGBA2Timeline.R]; g = frames[i + RGBA2Timeline.G]; b = frames[i + RGBA2Timeline.B]; @@ -1253,16 +1241,15 @@ module spine { b2 = frames[i + RGBA2Timeline.B2]; break; default: - r = this.getBezierValue(time, i, RGBA2Timeline.R, curveType - RGBA2Timeline.BEZIER); - g = this.getBezierValue(time, i, RGBA2Timeline.G, curveType + RGBA2Timeline.BEZIER_SIZE - RGBA2Timeline.BEZIER); - b = this.getBezierValue(time, i, RGBA2Timeline.B, curveType + RGBA2Timeline.BEZIER_SIZE * 2 - RGBA2Timeline.BEZIER); - a = this.getBezierValue(time, i, RGBA2Timeline.A, curveType + RGBA2Timeline.BEZIER_SIZE * 3 - RGBA2Timeline.BEZIER); - r2 = this.getBezierValue(time, i, RGBA2Timeline.R2, curveType + RGBA2Timeline.BEZIER_SIZE * 4 - RGBA2Timeline.BEZIER); - g2 = this.getBezierValue(time, i, RGBA2Timeline.G2, curveType + RGBA2Timeline.BEZIER_SIZE * 5 - RGBA2Timeline.BEZIER); - b2 = this.getBezierValue(time, i, RGBA2Timeline.B2, curveType + RGBA2Timeline.BEZIER_SIZE * 6 - RGBA2Timeline.BEZIER); + r = this.getBezierValue(time, i, RGBA2Timeline.R, curveType - CurveTimeline.BEZIER); + g = this.getBezierValue(time, i, RGBA2Timeline.G, curveType + CurveTimeline.BEZIER_SIZE - CurveTimeline.BEZIER); + b = this.getBezierValue(time, i, RGBA2Timeline.B, curveType + CurveTimeline.BEZIER_SIZE * 2 - CurveTimeline.BEZIER); + a = this.getBezierValue(time, i, RGBA2Timeline.A, curveType + CurveTimeline.BEZIER_SIZE * 3 - CurveTimeline.BEZIER); + r2 = this.getBezierValue(time, i, RGBA2Timeline.R2, curveType + CurveTimeline.BEZIER_SIZE * 4 - CurveTimeline.BEZIER); + g2 = this.getBezierValue(time, i, RGBA2Timeline.G2, curveType + CurveTimeline.BEZIER_SIZE * 5 - CurveTimeline.BEZIER); + b2 = this.getBezierValue(time, i, RGBA2Timeline.B2, curveType + CurveTimeline.BEZIER_SIZE * 6 - CurveTimeline.BEZIER); } - let light = slot.color, dark = slot.darkColor; if (alpha == 1) { light.set(r, g, b, a); dark.r = r2; @@ -1318,8 +1305,9 @@ module spine { if (!slot.bone.active) return; let frames = this.frames; + let light = slot.color, dark = slot.darkColor; if (time < frames[0]) { - let light = slot.color, dark = slot.darkColor, setupLight = slot.data.color, setupDark = slot.data.darkColor; + let setupLight = slot.data.color, setupDark = slot.data.darkColor; switch (blend) { case MixBlend.setup: light.r = setupLight.r; @@ -1341,10 +1329,10 @@ module spine { } let r = 0, g = 0, b = 0, a = 0, r2 = 0, g2 = 0, b2 = 0; - let i = Animation.search2(frames, time, RGB2Timeline.ENTRIES); - let curveType = this.curves[i >> 3]; + let i = Timeline.search2(frames, time, RGB2Timeline.ENTRIES); + let curveType = this.curves[i / RGB2Timeline.ENTRIES]; switch (curveType) { - case RGB2Timeline.LINEAR: + case CurveTimeline.LINEAR: let before = frames[i]; r = frames[i + RGB2Timeline.R]; g = frames[i + RGB2Timeline.G]; @@ -1360,7 +1348,7 @@ module spine { g2 += (frames[i + RGB2Timeline.ENTRIES + RGB2Timeline.G2] - g2) * t; b2 += (frames[i + RGB2Timeline.ENTRIES + RGB2Timeline.B2] - b2) * t; break; - case RGB2Timeline.STEPPED: + case CurveTimeline.STEPPED: r = frames[i + RGB2Timeline.R]; g = frames[i + RGB2Timeline.G]; b = frames[i + RGB2Timeline.B]; @@ -1369,15 +1357,14 @@ module spine { b2 = frames[i + RGB2Timeline.B2]; break; default: - r = this.getBezierValue(time, i, RGB2Timeline.R, curveType - RGB2Timeline.BEZIER); - g = this.getBezierValue(time, i, RGB2Timeline.G, curveType + RGB2Timeline.BEZIER_SIZE - RGB2Timeline.BEZIER); - b = this.getBezierValue(time, i, RGB2Timeline.B, curveType + RGB2Timeline.BEZIER_SIZE * 2 - RGB2Timeline.BEZIER); - r2 = this.getBezierValue(time, i, RGB2Timeline.R2, curveType + RGB2Timeline.BEZIER_SIZE * 3 - RGB2Timeline.BEZIER); - g2 = this.getBezierValue(time, i, RGB2Timeline.G2, curveType + RGB2Timeline.BEZIER_SIZE * 4 - RGB2Timeline.BEZIER); - b2 = this.getBezierValue(time, i, RGB2Timeline.B2, curveType + RGB2Timeline.BEZIER_SIZE * 5 - RGB2Timeline.BEZIER); + r = this.getBezierValue(time, i, RGB2Timeline.R, curveType - CurveTimeline.BEZIER); + g = this.getBezierValue(time, i, RGB2Timeline.G, curveType + CurveTimeline.BEZIER_SIZE - CurveTimeline.BEZIER); + b = this.getBezierValue(time, i, RGB2Timeline.B, curveType + CurveTimeline.BEZIER_SIZE * 2 - CurveTimeline.BEZIER); + r2 = this.getBezierValue(time, i, RGB2Timeline.R2, curveType + CurveTimeline.BEZIER_SIZE * 3 - CurveTimeline.BEZIER); + g2 = this.getBezierValue(time, i, RGB2Timeline.G2, curveType + CurveTimeline.BEZIER_SIZE * 4 - CurveTimeline.BEZIER); + b2 = this.getBezierValue(time, i, RGB2Timeline.B2, curveType + CurveTimeline.BEZIER_SIZE * 5 - CurveTimeline.BEZIER); } - let light = slot.color, dark = slot.darkColor; if (alpha == 1) { light.r = r; light.g = g; @@ -1420,11 +1407,6 @@ module spine { this.attachmentNames = new Array(frameCount); } - getFrameEntries () { - return 1; - } - - /** The number of key frames for this timeline. */ getFrameCount () { return this.frames.length; } @@ -1440,18 +1422,16 @@ module spine { if (!slot.bone.active) return; if (direction == MixDirection.mixOut) { - if (blend == MixBlend.setup) - this.setAttachment(skeleton, slot, slot.data.attachmentName); + if (blend == MixBlend.setup) this.setAttachment(skeleton, slot, slot.data.attachmentName); return; } - let frames = this.frames; - if (time < frames[0]) { + if (time < this.frames[0]) { if (blend == MixBlend.setup || blend == MixBlend.first) this.setAttachment(skeleton, slot, slot.data.attachmentName); return; } - this.setAttachment(skeleton, slot, this.attachmentNames[Animation.search(frames, time)]); + this.setAttachment(skeleton, slot, this.attachmentNames[Timeline.search(this.frames, time)]); } setAttachment(skeleton: Skeleton, slot: Slot, attachmentName: string) { @@ -1459,8 +1439,6 @@ module spine { } } - let zeros : ArrayLike = null; - /** Changes a slot's {@link Slot#deform} to deform a {@link VertexAttachment}. */ export class DeformTimeline extends CurveTimeline implements SlotTimeline { slotIndex = 0; @@ -1478,11 +1456,10 @@ module spine { this.slotIndex = slotIndex; this.attachment = attachment; this.vertices = new Array>(frameCount); - if (zeros == null) zeros = Utils.newFloatArray(64); } - getFrameEntries () { - return 1; + getFrameCount () { + return this.frames.length; } /** Sets the time in seconds and the vertices for the specified key frame. @@ -1497,14 +1474,14 @@ module spine { setBezier (bezier: number, frame: number, value: number, time1: number, value1: number, cx1: number, cy1: number, cx2: number, cy2: number, time2: number, value2: number) { let curves = this.curves; - let i = this.getFrameCount() + bezier * DeformTimeline.BEZIER_SIZE; - if (value == 0) curves[frame] = DeformTimeline.BEZIER + i; + let i = this.getFrameCount() + bezier * CurveTimeline.BEZIER_SIZE; + if (value == 0) curves[frame] = CurveTimeline.BEZIER + i; let tmpx = (time1 - cx1 * 2 + cx2) * 0.03, tmpy = cy2 * 0.03 - cy1 * 0.06; let dddx = ((cx1 - cx2) * 3 - time1 + time2) * 0.006, dddy = (cy1 - cy2 + 0.33333333) * 0.018; let ddx = tmpx * 2 + dddx, ddy = tmpy * 2 + dddy; let dx = (cx1 - time1) * 0.3 + tmpx + dddx * 0.16666667, dy = cy1 * 0.3 + tmpy + dddy * 0.16666667; let x = time1 + dx, y = dy; - for (let n = i + DeformTimeline.BEZIER_SIZE; i < n; i += 2) { + for (let n = i + CurveTimeline.BEZIER_SIZE; i < n; i += 2) { curves[i] = x; curves[i + 1] = y; dx += ddx; @@ -1518,21 +1495,20 @@ module spine { getCurvePercent (time: number, frame: number) { let curves = this.curves; - let frames = this.frames; let i = curves[frame]; switch (i) { - case DeformTimeline.LINEAR: + case CurveTimeline.LINEAR: let x = frames[frame]; return (time - x) / (frames[frame + this.getFrameEntries()] - x); - case DeformTimeline.STEPPED: + case CurveTimeline.STEPPED: return 0; } - i -= DeformTimeline.BEZIER; + i -= CurveTimeline.BEZIER; if (curves[i] > time) { let x = frames[frame]; return curves[i + 1] * (time - x) / (curves[i] - x); } - let n = i + DeformTimeline.BEZIER_SIZE; + let n = i + CurveTimeline.BEZIER_SIZE; for (i += 2; i < n; i += 2) { if (curves[i] >= time) { let x = curves[i - 2], y = curves[i - 1]; @@ -1547,10 +1523,10 @@ module spine { let slot: Slot = skeleton.slots[this.slotIndex]; if (!slot.bone.active) return; let slotAttachment: Attachment = slot.getAttachment(); - if (!(slotAttachment instanceof VertexAttachment) || !((slotAttachment).deformAttachment == this.attachment)) return; + if (!(slotAttachment instanceof VertexAttachment) || (slotAttachment).deformAttachment != this.attachment) return; - let deformArray: Array = slot.deform; - if (deformArray.length == 0) blend = MixBlend.setup; + let deform: Array = slot.deform; + if (deform.length == 0) blend = MixBlend.setup; let vertices = this.vertices; let vertexCount = vertices[0].length; @@ -1560,14 +1536,14 @@ module spine { let vertexAttachment = slotAttachment; switch (blend) { case MixBlend.setup: - deformArray.length = 0; + deform.length = 0; return; case MixBlend.first: if (alpha == 1) { - deformArray.length = 0; - break; + deform.length = 0; + return; } - let deform: Array = Utils.setArraySize(deformArray, vertexCount); + deform.length = vertexCount; if (vertexAttachment.bones == null) { // Unweighted vertex positions. let setupVertices = vertexAttachment.vertices; @@ -1583,7 +1559,7 @@ module spine { return; } - let deform: Array = Utils.setArraySize(deformArray, vertexCount); + deform.length = vertexCount; if (time >= frames[frames.length - 1]) { // Time is after last frame. let lastVertices = vertices[frames.length - 1]; if (alpha == 1) { @@ -1592,17 +1568,15 @@ module spine { if (vertexAttachment.bones == null) { // Unweighted vertex positions, with alpha. let setupVertices = vertexAttachment.vertices; - for (let i = 0; i < vertexCount; i++) { + for (let i = 0; i < vertexCount; i++) deform[i] += lastVertices[i] - setupVertices[i]; - } } else { // Weighted deform offsets, with alpha. for (let i = 0; i < vertexCount; i++) deform[i] += lastVertices[i]; } - } else { + } else Utils.arrayCopy(lastVertices, 0, deform, 0, vertexCount); - } } else { switch (blend) { case MixBlend.setup: { @@ -1631,9 +1605,8 @@ module spine { if (vertexAttachment.bones == null) { // Unweighted vertex positions, with alpha. let setupVertices = vertexAttachment.vertices; - for (let i = 0; i < vertexCount; i++) { + for (let i = 0; i < vertexCount; i++) deform[i] += (lastVertices[i] - setupVertices[i]) * alpha; - } } else { // Weighted deform offsets, with alpha. for (let i = 0; i < vertexCount; i++) @@ -1645,7 +1618,7 @@ module spine { } // Interpolate between the previous frame and the current frame. - let frame = Animation.search(frames, time); + let frame = Timeline.search(frames, time); let percent = this.getCurvePercent(time, frame); let prevVertices = vertices[frame]; let nextVertices = vertices[frame + 1]; @@ -1734,8 +1707,8 @@ module spine { this.events = new Array(frameCount); } - getFrameEntries () { - return 1; + getFrameCount () { + return this.frames.length; } /** Sets the time in seconds and the event for the specified key frame. */ @@ -1762,7 +1735,7 @@ module spine { if (lastTime < frames[0]) i = 0; else { - i = Animation.search(frames, lastTime) + 1; + i = Timeline.search(frames, lastTime) + 1; let frameTime = frames[i]; while (i > 0) { // Fire multiple events with the same frame. if (frames[i - 1] != frameTime) break; @@ -1786,8 +1759,8 @@ module spine { this.drawOrders = new Array>(frameCount); } - getFrameEntries () { - return 1; + getFrameCount () { + return this.frames.length; } /** Sets the time in seconds and the draw order for the specified key frame. @@ -1799,23 +1772,22 @@ module spine { } apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array, alpha: number, blend: MixBlend, direction: MixDirection) { - let drawOrder: Array = skeleton.drawOrder; - let slots: Array = skeleton.slots; if (direction == MixDirection.mixOut) { if (blend == MixBlend.setup) Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length); return; } - let frames = this.frames; if (time < frames[0]) { - if (blend == MixBlend.setup || blend == MixBlend.first) Utils.arrayCopy(skeleton.slots, 0, drawOrder, 0, skeleton.slots.length); + if (blend == MixBlend.setup || blend == MixBlend.first) Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length); return; } - let drawOrderToSetupIndex = this.drawOrders[Animation.search(frames, time)]; + let drawOrderToSetupIndex = this.drawOrders[Timeline.search(frames, time)]; if (drawOrderToSetupIndex == null) - Utils.arrayCopy(slots, 0, drawOrder, 0, slots.length); + Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length); else { + let drawOrder: Array = skeleton.drawOrder; + let slots: Array = skeleton.slots; for (let i = 0, n = drawOrderToSetupIndex.length; i < n; i++) drawOrder[i] = slots[drawOrderToSetupIndex[i]]; } @@ -1855,10 +1827,10 @@ module spine { } apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array, alpha: number, blend: MixBlend, direction: MixDirection) { - let frames = this.frames; let constraint: IkConstraint = skeleton.ikConstraints[this.ikConstraintIndex]; if (!constraint.active) return; + let frames = this.frames; if (time < frames[0]) { switch (blend) { case MixBlend.setup: @@ -1879,10 +1851,10 @@ module spine { } let mix = 0, softness = 0; - let i = Animation.search2(frames, time, IkConstraintTimeline.ENTRIES) + let i = Timeline.search2(frames, time, IkConstraintTimeline.ENTRIES) let curveType = this.curves[i / IkConstraintTimeline.ENTRIES]; switch (curveType) { - case IkConstraintTimeline.LINEAR: + case CurveTimeline.LINEAR: let before = frames[i]; mix = frames[i + IkConstraintTimeline.MIX]; softness = frames[i + IkConstraintTimeline.SOFTNESS]; @@ -1890,13 +1862,13 @@ module spine { mix += (frames[i + IkConstraintTimeline.ENTRIES + IkConstraintTimeline.MIX] - mix) * t; softness += (frames[i + IkConstraintTimeline.ENTRIES + IkConstraintTimeline.SOFTNESS] - softness) * t; break; - case IkConstraintTimeline.STEPPED: + case CurveTimeline.STEPPED: mix = frames[i + IkConstraintTimeline.MIX]; softness = frames[i + IkConstraintTimeline.SOFTNESS]; break; default: - mix = this.getBezierValue(time, i, IkConstraintTimeline.MIX, curveType - IkConstraintTimeline.BEZIER); - softness = this.getBezierValue(time, i, IkConstraintTimeline.SOFTNESS, curveType + IkConstraintTimeline.BEZIER_SIZE - IkConstraintTimeline.BEZIER); + mix = this.getBezierValue(time, i, IkConstraintTimeline.MIX, curveType - CurveTimeline.BEZIER); + softness = this.getBezierValue(time, i, IkConstraintTimeline.SOFTNESS, curveType + CurveTimeline.BEZIER_SIZE - CurveTimeline.BEZIER); } if (blend == MixBlend.setup) { @@ -1950,7 +1922,7 @@ module spine { mixShearY: number) { let frames = this.frames; frame *= TransformConstraintTimeline.ENTRIES; - this.frames[frame] = time; + frames[frame] = time; frames[frame + TransformConstraintTimeline.ROTATE] = mixRotate; frames[frame + TransformConstraintTimeline.X] = mixX; frames[frame + TransformConstraintTimeline.Y] = mixY; @@ -1960,11 +1932,10 @@ module spine { } apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array, alpha: number, blend: MixBlend, direction: MixDirection) { - let frames = this.frames; - let constraint: TransformConstraint = skeleton.transformConstraints[this.transformConstraintIndex]; if (!constraint.active) return; + let frames = this.frames; if (time < frames[0]) { let data = constraint.data; switch (blend) { @@ -1988,7 +1959,7 @@ module spine { } let rotate, x, y, scaleX, scaleY, shearY; - let i = Animation.search2(frames, time, TransformConstraintTimeline.ENTRIES); + let i = Timeline.search2(frames, time, TransformConstraintTimeline.ENTRIES); let curveType = this.curves[i / TransformConstraintTimeline.ENTRIES]; let ROTATE = TransformConstraintTimeline.ROTATE; let X = TransformConstraintTimeline.X; @@ -1997,10 +1968,8 @@ module spine { let SCALEY = TransformConstraintTimeline.SCALEY; let SHEARY = TransformConstraintTimeline.SHEARY; let ENTRIES = TransformConstraintTimeline.ENTRIES; - let BEZIER = TransformConstraintTimeline.BEZIER; - let BEZIER_SIZE = TransformConstraintTimeline.BEZIER_SIZE; switch (curveType) { - case TransformConstraintTimeline.LINEAR: + case CurveTimeline.LINEAR: let before = frames[i]; rotate = frames[i + ROTATE]; x = frames[i + X]; @@ -2016,7 +1985,7 @@ module spine { scaleY += (frames[i + ENTRIES + SCALEY] - scaleY) * t; shearY += (frames[i + ENTRIES + SHEARY] - shearY) * t; break; - case TransformConstraintTimeline.STEPPED: + case CurveTimeline.STEPPED: rotate = frames[i + ROTATE]; x = frames[i + X]; y = frames[i + Y]; @@ -2025,12 +1994,12 @@ module spine { shearY = frames[i + SHEARY]; break; default: - rotate = this.getBezierValue(time, i, ROTATE, curveType - BEZIER); - x = this.getBezierValue(time, i, X, curveType + BEZIER_SIZE - BEZIER); - y = this.getBezierValue(time, i, Y, curveType + BEZIER_SIZE * 2 - BEZIER); - scaleX = this.getBezierValue(time, i, SCALEX, curveType + BEZIER_SIZE * 3 - BEZIER); - scaleY = this.getBezierValue(time, i, SCALEY, curveType + BEZIER_SIZE * 4 - BEZIER); - shearY = this.getBezierValue(time, i, SHEARY, curveType + BEZIER_SIZE * 5 - BEZIER); + rotate = this.getBezierValue(time, i, ROTATE, curveType - CurveTimeline.BEZIER); + x = this.getBezierValue(time, i, X, curveType + CurveTimeline.BEZIER_SIZE - CurveTimeline.BEZIER); + y = this.getBezierValue(time, i, Y, curveType + CurveTimeline.BEZIER_SIZE * 2 - CurveTimeline.BEZIER); + scaleX = this.getBezierValue(time, i, SCALEX, curveType + CurveTimeline.BEZIER_SIZE * 3 - CurveTimeline.BEZIER); + scaleY = this.getBezierValue(time, i, SCALEY, curveType + CurveTimeline.BEZIER_SIZE * 4 - CurveTimeline.BEZIER); + shearY = this.getBezierValue(time, i, SHEARY, curveType + CurveTimeline.BEZIER_SIZE * 5 - CurveTimeline.BEZIER); } if (blend == MixBlend.setup) { @@ -2054,7 +2023,6 @@ module spine { /** Changes a path constraint's {@link PathConstraint#position}. */ export class PathConstraintPositionTimeline extends CurveTimeline1 { - /** The index of the path constraint slot in {@link Skeleton#pathConstraints} that will be changed. */ pathConstraintIndex: number; @@ -2066,10 +2034,10 @@ module spine { } apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array, alpha: number, blend: MixBlend, direction: MixDirection) { - let frames = this.frames; let constraint: PathConstraint = skeleton.pathConstraints[this.pathConstraintIndex]; if (!constraint.active) return; + let frames = this.frames; if (time < frames[0]) { switch (blend) { case MixBlend.setup: @@ -2103,10 +2071,10 @@ module spine { } apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array, alpha: number, blend: MixBlend, direction: MixDirection) { - let frames = this.frames; let constraint: PathConstraint = skeleton.pathConstraints[this.pathConstraintIndex]; if (!constraint.active) return; + let frames = this.frames; if (time < frames[0]) { switch (blend) { case MixBlend.setup: @@ -2130,11 +2098,12 @@ module spine { /** Changes a transform constraint's {@link PathConstraint#getMixRotate()}, {@link PathConstraint#getMixX()}, and * {@link PathConstraint#getMixY()}. */ export class PathConstraintMixTimeline extends CurveTimeline { - /** The index of the path constraint slot in {@link Skeleton#getPathConstraints()} that will be changed. */ - pathConstraintIndex = 0; static ENTRIES = 4; static ROTATE = 1; static X = 2; static Y = 3; + /** The index of the path constraint slot in {@link Skeleton#getPathConstraints()} that will be changed. */ + pathConstraintIndex = 0; + constructor (frameCount: number, bezierCount: number, pathConstraintIndex: number) { super(frameCount, bezierCount, [ Property.pathConstraintMix + "|" + pathConstraintIndex @@ -2142,7 +2111,7 @@ module spine { this.pathConstraintIndex = pathConstraintIndex; } - getFrameEntries() { + getFrameEntries () { return PathConstraintMixTimeline.ENTRIES; } @@ -2156,10 +2125,10 @@ module spine { } apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array, alpha: number, blend: MixBlend, direction: MixDirection) { - let frames = this.frames; let constraint: PathConstraint = skeleton.pathConstraints[this.pathConstraintIndex]; if (!constraint.active) return; + let frames = this.frames; if (time < frames[0]) { switch (blend) { case MixBlend.setup: @@ -2176,10 +2145,10 @@ module spine { } let rotate, x, y; - let i = Animation.search2(frames, time, PathConstraintMixTimeline.ENTRIES); + let i = Timeline.search2(frames, time, PathConstraintMixTimeline.ENTRIES); let curveType = this.curves[i >> 2]; switch (curveType) { - case PathConstraintMixTimeline.LINEAR: + case CurveTimeline.LINEAR: let before = frames[i]; rotate = frames[i + PathConstraintMixTimeline.ROTATE]; x = frames[i + PathConstraintMixTimeline.X]; @@ -2189,15 +2158,15 @@ module spine { x += (frames[i + PathConstraintMixTimeline.ENTRIES + PathConstraintMixTimeline.X] - x) * t; y += (frames[i + PathConstraintMixTimeline.ENTRIES + PathConstraintMixTimeline.Y] - y) * t; break; - case PathConstraintMixTimeline.STEPPED: + case CurveTimeline.STEPPED: rotate = frames[i + PathConstraintMixTimeline.ROTATE]; x = frames[i + PathConstraintMixTimeline.X]; y = frames[i + PathConstraintMixTimeline.Y]; break; default: - rotate = this.getBezierValue(time, i, PathConstraintMixTimeline.ROTATE, curveType - PathConstraintMixTimeline.BEZIER); - x = this.getBezierValue(time, i, PathConstraintMixTimeline.X, curveType + PathConstraintMixTimeline.BEZIER_SIZE - PathConstraintMixTimeline.BEZIER); - y = this.getBezierValue(time, i, PathConstraintMixTimeline.Y, curveType + PathConstraintMixTimeline.BEZIER_SIZE * 2 - PathConstraintMixTimeline.BEZIER); + rotate = this.getBezierValue(time, i, PathConstraintMixTimeline.ROTATE, curveType - CurveTimeline.BEZIER); + x = this.getBezierValue(time, i, PathConstraintMixTimeline.X, curveType + CurveTimeline.BEZIER_SIZE - CurveTimeline.BEZIER); + y = this.getBezierValue(time, i, PathConstraintMixTimeline.Y, curveType + CurveTimeline.BEZIER_SIZE * 2 - CurveTimeline.BEZIER); } if (blend == MixBlend.setup) { diff --git a/spine-ts/core/src/AnimationState.ts b/spine-ts/core/src/AnimationState.ts index fd4a6ce46..60ca73830 100644 --- a/spine-ts/core/src/AnimationState.ts +++ b/spine-ts/core/src/AnimationState.ts @@ -243,7 +243,7 @@ module spine { for (let ii = 0; ii < timelineCount; ii++) { let timeline = timelines[ii]; - let timelineBlend = timelineMode[ii] == AnimationState.SUBSEQUENT ? blend : MixBlend.setup; + let timelineBlend = timelineMode[ii] == AnimationState.SUBSEQUENT ? blend : MixBlend.setup; if (timeline instanceof RotateTimeline) { this.applyRotateTimeline(timeline, skeleton, applyTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame); } else if (timeline instanceof AttachmentTimeline) { @@ -293,19 +293,16 @@ module spine { if (blend != MixBlend.first) blend = from.mixBlend; } - let attachments = mix < from.attachmentThreshold, drawOrder = mix < from.drawOrderThreshold; let timelineCount = from.animation.timelines.length; let timelines = from.animation.timelines; let alphaHold = from.alpha * to.interruptAlpha, alphaMix = alphaHold * (1 - mix); let animationLast = from.animationLast, animationTime = from.getAnimationTime(), applyTime = animationTime; let events = null; - // let events = mix < from.eventThreshold ? this.events : null; - if (from.reverse) { + if (from.reverse) applyTime = from.animation.duration - applyTime; - } else { - if (mix < from.eventThreshold) events = this.events; - } + else if (mix < from.eventThreshold) + events = this.events; if (blend == MixBlend.add) { for (let i = 0; i < timelineCount; i++) @@ -373,7 +370,6 @@ module spine { } applyAttachmentTimeline (timeline: AttachmentTimeline, skeleton: Skeleton, time: number, blend: MixBlend, attachments: boolean) { - var slot = skeleton.slots[timeline.slotIndex]; if (!slot.bone.active) return; @@ -381,9 +377,8 @@ module spine { if (time < frames[0]) { // Time is before first frame. if (blend == MixBlend.setup || blend == MixBlend.first) this.setAttachment(skeleton, slot, slot.data.attachmentName, attachments); - } - else - this.setAttachment(skeleton, slot, timeline.attachmentNames[Animation.search(frames, time)], attachments); + } else + this.setAttachment(skeleton, slot, timeline.attachmentNames[Timeline.search(frames, time)], attachments); // If an attachment wasn't set (ie before the first frame or attachments is false), set the setup attachment later. if (slot.attachmentState <= this.unkeyedState) slot.attachmentState = this.unkeyedState + AnimationState.SETUP; @@ -394,7 +389,6 @@ module spine { if (attachments) slot.attachmentState = this.unkeyedState + AnimationState.CURRENT; } - applyRotateTimeline (timeline: Timeline, skeleton: Skeleton, time: number, alpha: number, blend: MixBlend, timelinesRotation: Array, i: number, firstFrame: boolean) { @@ -555,7 +549,7 @@ module spine { /** Sets an animation by name. * - * {@link #setAnimationWith(}. */ + * See {@link #setAnimationWith()}. */ setAnimation (trackIndex: number, animationName: string, loop: boolean) { let animation = this.data.skeletonData.findAnimation(animationName); if (animation == null) throw new Error("Animation not found: " + animationName); @@ -756,13 +750,12 @@ module spine { let timelinesCount = entry.animation.timelines.length; let timelineMode = Utils.setArraySize(entry.timelineMode, timelinesCount); entry.timelineHoldMix.length = 0; - let timelineDipMix = Utils.setArraySize(entry.timelineHoldMix, timelinesCount); + let timelineHoldMix = Utils.setArraySize(entry.timelineHoldMix, timelinesCount); let propertyIDs = this.propertyIDs; if (to != null && to.holdPrevious) { - for (let i = 0; i < timelinesCount; i++) { + for (let i = 0; i < timelinesCount; i++) timelineMode[i] = propertyIDs.addAll(timelines[i].getPropertyIds()) ? AnimationState.HOLD_FIRST : AnimationState.HOLD_SUBSEQUENT; - } return; } @@ -780,7 +773,7 @@ module spine { if (next.animation.hasTimeline(ids)) continue; if (entry.mixDuration > 0) { timelineMode[i] = AnimationState.HOLD_MIX; - timelineDipMix[i] = next; + timelineHoldMix[i] = next; continue outer; } break; @@ -980,8 +973,8 @@ module spine { timelinesRotation = new Array(); reset () { - this.previous = null; this.next = null; + this.previous = null; this.mixingFrom = null; this.mixingTo = null; this.animation = null; diff --git a/spine-ts/core/src/PathConstraint.ts b/spine-ts/core/src/PathConstraint.ts index 7cebf2402..7141980dd 100644 --- a/spine-ts/core/src/PathConstraint.ts +++ b/spine-ts/core/src/PathConstraint.ts @@ -99,58 +99,58 @@ module spine { let spacing = this.spacing; switch (data.spacingMode) { - case SpacingMode.Percent: - if (scale) { - for (let i = 0, n = spacesCount - 1; i < n; i++) { - let bone = bones[i]; - let setupLength = bone.data.length; - if (setupLength < PathConstraint.epsilon) - lengths[i] = 0; - else { - let x = setupLength * bone.a, y = setupLength * bone.c; - lengths[i] = Math.sqrt(x * x + y * y); - } - } - } - Utils.arrayFill(spaces, 1, spacesCount, spacing); - break; - case SpacingMode.Proportional: - let sum = 0; - for (let i = 0; i < boneCount;) { + case SpacingMode.Percent: + if (scale) { + for (let i = 0, n = spacesCount - 1; i < n; i++) { let bone = bones[i]; let setupLength = bone.data.length; - if (setupLength < PathConstraint.epsilon) { - if (scale) lengths[i] = 0; - spaces[++i] = spacing; - } else { + if (setupLength < PathConstraint.epsilon) + lengths[i] = 0; + else { let x = setupLength * bone.a, y = setupLength * bone.c; - let length = Math.sqrt(x * x + y * y); - if (scale) lengths[i] = length; - spaces[++i] = length; - sum += length; + lengths[i] = Math.sqrt(x * x + y * y); } } - if (sum > 0) { - sum = spacesCount / sum * spacing; - for (let i = 1; i < spacesCount; i++) - spaces[i] *= sum; + } + Utils.arrayFill(spaces, 1, spacesCount, spacing); + break; + case SpacingMode.Proportional: + let sum = 0; + for (let i = 0; i < boneCount;) { + let bone = bones[i]; + let setupLength = bone.data.length; + if (setupLength < PathConstraint.epsilon) { + if (scale) lengths[i] = 0; + spaces[++i] = spacing; + } else { + let x = setupLength * bone.a, y = setupLength * bone.c; + let length = Math.sqrt(x * x + y * y); + if (scale) lengths[i] = length; + spaces[++i] = length; + sum += length; } - break; - default: - let lengthSpacing = data.spacingMode == SpacingMode.Length; - for (let i = 0, n = spacesCount - 1; i < n;) { - let bone = bones[i]; - let setupLength = bone.data.length; - if (setupLength < PathConstraint.epsilon) { - if (scale) lengths[i] = 0; - spaces[++i] = spacing; - } else { - let x = setupLength * bone.a, y = setupLength * bone.c; - let length = Math.sqrt(x * x + y * y); - if (scale) lengths[i] = length; - spaces[++i] = (lengthSpacing ? setupLength + spacing : spacing) * length / setupLength; - } + } + if (sum > 0) { + sum = spacesCount / sum * spacing; + for (let i = 1; i < spacesCount; i++) + spaces[i] *= sum; + } + break; + default: + let lengthSpacing = data.spacingMode == SpacingMode.Length; + for (let i = 0, n = spacesCount - 1; i < n;) { + let bone = bones[i]; + let setupLength = bone.data.length; + if (setupLength < PathConstraint.epsilon) { + if (scale) lengths[i] = 0; + spaces[++i] = spacing; + } else { + let x = setupLength * bone.a, y = setupLength * bone.c; + let length = Math.sqrt(x * x + y * y); + if (scale) lengths[i] = length; + spaces[++i] = (lengthSpacing ? setupLength + spacing : spacing) * length / setupLength; } + } } let positions = this.computeWorldPositions(attachment, spacesCount, tangents); diff --git a/spine-ts/core/src/PathConstraintData.ts b/spine-ts/core/src/PathConstraintData.ts index 34ff3d2ef..56f82735a 100644 --- a/spine-ts/core/src/PathConstraintData.ts +++ b/spine-ts/core/src/PathConstraintData.ts @@ -31,7 +31,7 @@ module spine { /** Stores the setup pose for a {@link PathConstraint}. * - * See [Path constraints](http://esotericsoftware.com/spine-path-constraints) in the Spine User Guide. */ + * See [path constraints](http://esotericsoftware.com/spine-path-constraints) in the Spine User Guide. */ export class PathConstraintData extends ConstraintData { /** The bones that will be modified by this path constraint. */ @@ -69,21 +69,21 @@ module spine { /** Controls how the first bone is positioned along the path. * - * See [Position mode](http://esotericsoftware.com/spine-path-constraints#Position-mode) in the Spine User Guide. */ + * See [position](http://esotericsoftware.com/spine-path-constraints#Position) in the Spine User Guide. */ export enum PositionMode { Fixed, Percent } /** Controls how bones after the first bone are positioned along the path. * - * [Spacing mode](http://esotericsoftware.com/spine-path-constraints#Spacing-mode) in the Spine User Guide. */ + * See [spacing](http://esotericsoftware.com/spine-path-constraints#Spacing) in the Spine User Guide. */ export enum SpacingMode { Length, Fixed, Percent, Proportional } /** Controls how bones are rotated, translated, and scaled to match the path. * - * [Rotate mode](http://esotericsoftware.com/spine-path-constraints#Rotate-mod) in the Spine User Guide. */ + * See [rotate mix](http://esotericsoftware.com/spine-path-constraints#Rotate-mix) in the Spine User Guide. */ export enum RotateMode { Tangent, Chain, ChainScale } diff --git a/spine-ts/core/src/SkeletonBinary.ts b/spine-ts/core/src/SkeletonBinary.ts index 64adbbf49..eb1a46b4d 100644 --- a/spine-ts/core/src/SkeletonBinary.ts +++ b/spine-ts/core/src/SkeletonBinary.ts @@ -509,7 +509,7 @@ module spine { } private readAnimation (input: BinaryInput, name: string, skeletonData: SkeletonData): Animation { - let numTimelines = input.readInt(true); + input.readInt(true); // Number of timelines. let timelines = new Array(); let scale = this.scale; let tempColor1 = new Color(); @@ -839,8 +839,7 @@ module spine { data.spacingMode == SpacingMode.Length || data.spacingMode == SpacingMode.Fixed ? scale : 1)); break; case SkeletonBinary.PATH_MIX: - let timeline = new PathConstraintMixTimeline(input.readInt(true), input.readInt(true), - index); + let timeline = new PathConstraintMixTimeline(input.readInt(true), input.readInt(true), index); let time = input.readFloat(), mixRotate = input.readFloat(), mixX = input.readFloat(), mixY = input.readFloat(); for (let frame = 0, bezier = 0, frameLast = timeline.getFrameCount() - 1;; frame++) { timeline.setFrame(frame, time, mixRotate, mixX, mixY); @@ -855,7 +854,6 @@ module spine { SkeletonBinary.setBezier(input, timeline, bezier++, frame, 0, time, time2, mixRotate, mixRotate2, 1); SkeletonBinary.setBezier(input, timeline, bezier++, frame, 1, time, time2, mixX, mixX2, 1); SkeletonBinary.setBezier(input, timeline, bezier++, frame, 2, time, time2, mixY, mixY2, 1); - } time = time2; mixRotate = mixRotate2; @@ -979,11 +977,11 @@ module spine { let duration = 0; for (let i = 0, n = timelines.length; i < n; i++) - duration = Math.max(duration, (timelines[i]).getDuration()); + duration = Math.max(duration, timelines[i].getDuration()); return new Animation(name, timelines, duration); } - static readTimeline (input: BinaryInput, timeline: CurveTimeline1, scale: number): Timeline { + static readTimeline (input: BinaryInput, timeline: CurveTimeline1, scale: number): CurveTimeline1 { let time = input.readFloat(), value = input.readFloat() * scale; for (let frame = 0, bezier = 0, frameLast = timeline.getFrameCount() - 1;; frame++) { timeline.setFrame(frame, time, value); @@ -1002,7 +1000,7 @@ module spine { return timeline; } - static readTimeline2 (input: BinaryInput, timeline: CurveTimeline2, scale: number): Timeline { + static readTimeline2 (input: BinaryInput, timeline: CurveTimeline2, scale: number): CurveTimeline2 { let time = input.readFloat(), value1 = input.readFloat() * scale, value2 = input.readFloat() * scale; for (let frame = 0, bezier = 0, frameLast = timeline.getFrameCount() - 1;; frame++) { timeline.setFrame(frame, time, value1, value2); @@ -1013,8 +1011,8 @@ module spine { timeline.setStepped(frame); break; case SkeletonBinary.CURVE_BEZIER: - this.setBezier(input, timeline, bezier++, frame, 0, time, time2, value1, nvalue1, scale); - this.setBezier(input, timeline, bezier++, frame, 1, time, time2, value2, nvalue2, scale); + SkeletonBinary.setBezier(input, timeline, bezier++, frame, 0, time, time2, value1, nvalue1, scale); + SkeletonBinary.setBezier(input, timeline, bezier++, frame, 1, time, time2, value2, nvalue2, scale); } time = time2; value1 = nvalue1; @@ -1023,7 +1021,8 @@ module spine { return timeline; } - static setBezier (input: BinaryInput, timeline: CurveTimeline, bezier: number, frame: number, value: number, time1: number, time2: number, value1: number, value2: number, scale: number) { + static setBezier (input: BinaryInput, timeline: CurveTimeline, bezier: number, frame: number, value: number, + time1: number, time2: number, value1: number, value2: number, scale: number) { timeline.setBezier(bezier, frame, value, time1, value1, input.readFloat(), input.readFloat() * scale, input.readFloat(), input.readFloat() * scale, time2, value2); } } diff --git a/spine-ts/core/src/SkeletonJson.ts b/spine-ts/core/src/SkeletonJson.ts index 8a1bcda4e..20afade00 100644 --- a/spine-ts/core/src/SkeletonJson.ts +++ b/spine-ts/core/src/SkeletonJson.ts @@ -72,24 +72,24 @@ module spine { let boneMap = root.bones[i]; let parent: BoneData = null; - let parentName: string = this.getValue(boneMap, "parent", null); + let parentName: string = getValue(boneMap, "parent", null); if (parentName != null) { parent = skeletonData.findBone(parentName); if (parent == null) throw new Error("Parent bone not found: " + parentName); } let data = new BoneData(skeletonData.bones.length, boneMap.name, parent); - data.length = this.getValue(boneMap, "length", 0) * scale; - data.x = this.getValue(boneMap, "x", 0) * scale; - data.y = this.getValue(boneMap, "y", 0) * scale; - data.rotation = this.getValue(boneMap, "rotation", 0); - data.scaleX = this.getValue(boneMap, "scaleX", 1); - data.scaleY = this.getValue(boneMap, "scaleY", 1); - data.shearX = this.getValue(boneMap, "shearX", 0); - data.shearY = this.getValue(boneMap, "shearY", 0); - data.transformMode = SkeletonJson.transformModeFromString(this.getValue(boneMap, "transform", "normal")); - data.skinRequired = this.getValue(boneMap, "skin", false); + data.length = getValue(boneMap, "length", 0) * scale; + data.x = getValue(boneMap, "x", 0) * scale; + data.y = getValue(boneMap, "y", 0) * scale; + data.rotation = getValue(boneMap, "rotation", 0); + data.scaleX = getValue(boneMap, "scaleX", 1); + data.scaleY = getValue(boneMap, "scaleY", 1); + data.shearX = getValue(boneMap, "shearX", 0); + data.shearY = getValue(boneMap, "shearY", 0); + data.transformMode = SkeletonJson.transformModeFromString(getValue(boneMap, "transform", "normal")); + data.skinRequired = getValue(boneMap, "skin", false); - let color = this.getValue(boneMap, "color", null); + let color = getValue(boneMap, "color", null); if (color) data.color.setFromString(color); skeletonData.bones.push(data); @@ -106,17 +106,17 @@ module spine { if (boneData == null) throw new Error("Slot bone not found: " + boneName); let data = new SlotData(skeletonData.slots.length, slotName, boneData); - let color: string = this.getValue(slotMap, "color", null); + let color: string = getValue(slotMap, "color", null); if (color != null) data.color.setFromString(color); - let dark: string = this.getValue(slotMap, "dark", null); + let dark: string = getValue(slotMap, "dark", null); if (dark != null) { data.darkColor = new Color(1, 1, 1, 1); data.darkColor.setFromString(dark); } - data.attachmentName = this.getValue(slotMap, "attachment", null); - data.blendMode = SkeletonJson.blendModeFromString(this.getValue(slotMap, "blend", "normal")); + data.attachmentName = getValue(slotMap, "attachment", null); + data.blendMode = SkeletonJson.blendModeFromString(getValue(slotMap, "blend", "normal")); skeletonData.slots.push(data); } } @@ -126,8 +126,8 @@ module spine { for (let i = 0; i < root.ik.length; i++) { let constraintMap = root.ik[i]; let data = new IkConstraintData(constraintMap.name); - data.order = this.getValue(constraintMap, "order", 0); - data.skinRequired = this.getValue(constraintMap, "skin", false); + data.order = getValue(constraintMap, "order", 0); + data.skinRequired = getValue(constraintMap, "skin", false); for (let j = 0; j < constraintMap.bones.length; j++) { let boneName = constraintMap.bones[j]; @@ -140,12 +140,12 @@ module spine { data.target = skeletonData.findBone(targetName); if (data.target == null) throw new Error("IK target bone not found: " + targetName); - data.mix = this.getValue(constraintMap, "mix", 1); - data.softness = this.getValue(constraintMap, "softness", 0) * scale; - data.bendDirection = this.getValue(constraintMap, "bendPositive", true) ? 1 : -1; - data.compress = this.getValue(constraintMap, "compress", false); - data.stretch = this.getValue(constraintMap, "stretch", false); - data.uniform = this.getValue(constraintMap, "uniform", false); + data.mix = getValue(constraintMap, "mix", 1); + data.softness = getValue(constraintMap, "softness", 0) * scale; + data.bendDirection = getValue(constraintMap, "bendPositive", true) ? 1 : -1; + data.compress = getValue(constraintMap, "compress", false); + data.stretch = getValue(constraintMap, "stretch", false); + data.uniform = getValue(constraintMap, "uniform", false); skeletonData.ikConstraints.push(data); } @@ -156,8 +156,8 @@ module spine { for (let i = 0; i < root.transform.length; i++) { let constraintMap = root.transform[i]; let data = new TransformConstraintData(constraintMap.name); - data.order = this.getValue(constraintMap, "order", 0); - data.skinRequired = this.getValue(constraintMap, "skin", false); + data.order = getValue(constraintMap, "order", 0); + data.skinRequired = getValue(constraintMap, "skin", false); for (let j = 0; j < constraintMap.bones.length; j++) { let boneName = constraintMap.bones[j]; @@ -170,21 +170,21 @@ module spine { data.target = skeletonData.findBone(targetName); if (data.target == null) throw new Error("Transform constraint target bone not found: " + targetName); - data.local = this.getValue(constraintMap, "local", false); - data.relative = this.getValue(constraintMap, "relative", false); - data.offsetRotation = this.getValue(constraintMap, "rotation", 0); - data.offsetX = this.getValue(constraintMap, "x", 0) * scale; - data.offsetY = this.getValue(constraintMap, "y", 0) * scale; - data.offsetScaleX = this.getValue(constraintMap, "scaleX", 0); - data.offsetScaleY = this.getValue(constraintMap, "scaleY", 0); - data.offsetShearY = this.getValue(constraintMap, "shearY", 0); + data.local = getValue(constraintMap, "local", false); + data.relative = getValue(constraintMap, "relative", false); + data.offsetRotation = getValue(constraintMap, "rotation", 0); + data.offsetX = getValue(constraintMap, "x", 0) * scale; + data.offsetY = getValue(constraintMap, "y", 0) * scale; + data.offsetScaleX = getValue(constraintMap, "scaleX", 0); + data.offsetScaleY = getValue(constraintMap, "scaleY", 0); + data.offsetShearY = getValue(constraintMap, "shearY", 0); - data.mixRotate = this.getValue(constraintMap, "mixRotate", 1); - data.mixX = this.getValue(constraintMap, "mixX", 1); - data.mixY = this.getValue(constraintMap, "mixY", data.mixX); - data.mixScaleX = this.getValue(constraintMap, "mixScaleX", 1); - data.mixScaleY = this.getValue(constraintMap, "mixScaleY", data.mixScaleX); - data.mixShearY = this.getValue(constraintMap, "mixShearY", 1); + data.mixRotate = getValue(constraintMap, "mixRotate", 1); + data.mixX = getValue(constraintMap, "mixX", 1); + data.mixY = getValue(constraintMap, "mixY", data.mixX); + data.mixScaleX = getValue(constraintMap, "mixScaleX", 1); + data.mixScaleY = getValue(constraintMap, "mixScaleY", data.mixScaleX); + data.mixShearY = getValue(constraintMap, "mixShearY", 1); skeletonData.transformConstraints.push(data); } @@ -195,8 +195,8 @@ module spine { for (let i = 0; i < root.path.length; i++) { let constraintMap = root.path[i]; let data = new PathConstraintData(constraintMap.name); - data.order = this.getValue(constraintMap, "order", 0); - data.skinRequired = this.getValue(constraintMap, "skin", false); + data.order = getValue(constraintMap, "order", 0); + data.skinRequired = getValue(constraintMap, "skin", false); for (let j = 0; j < constraintMap.bones.length; j++) { let boneName = constraintMap.bones[j]; @@ -209,17 +209,17 @@ module spine { data.target = skeletonData.findSlot(targetName); if (data.target == null) throw new Error("Path target slot not found: " + targetName); - data.positionMode = SkeletonJson.positionModeFromString(this.getValue(constraintMap, "positionMode", "percent")); - data.spacingMode = SkeletonJson.spacingModeFromString(this.getValue(constraintMap, "spacingMode", "length")); - data.rotateMode = SkeletonJson.rotateModeFromString(this.getValue(constraintMap, "rotateMode", "tangent")); - data.offsetRotation = this.getValue(constraintMap, "rotation", 0); - data.position = this.getValue(constraintMap, "position", 0); + data.positionMode = SkeletonJson.positionModeFromString(getValue(constraintMap, "positionMode", "percent")); + data.spacingMode = SkeletonJson.spacingModeFromString(getValue(constraintMap, "spacingMode", "length")); + data.rotateMode = SkeletonJson.rotateModeFromString(getValue(constraintMap, "rotateMode", "tangent")); + data.offsetRotation = getValue(constraintMap, "rotation", 0); + data.position = getValue(constraintMap, "position", 0); if (data.positionMode == PositionMode.Fixed) data.position *= scale; - data.spacing = this.getValue(constraintMap, "spacing", 0); + data.spacing = getValue(constraintMap, "spacing", 0); if (data.spacingMode == SpacingMode.Length || data.spacingMode == SpacingMode.Fixed) data.spacing *= scale; - data.mixRotate = this.getValue(constraintMap, "mixRotate", 1); - data.mixX = this.getValue(constraintMap, "mixX", 1); - data.mixY = this.getValue(constraintMap, "mixY", 1); + data.mixRotate = getValue(constraintMap, "mixRotate", 1); + data.mixX = getValue(constraintMap, "mixX", 1); + data.mixY = getValue(constraintMap, "mixY", 1); skeletonData.pathConstraints.push(data); } @@ -295,13 +295,13 @@ module spine { for (let eventName in root.events) { let eventMap = root.events[eventName]; let data = new EventData(eventName); - data.intValue = this.getValue(eventMap, "int", 0); - data.floatValue = this.getValue(eventMap, "float", 0); - data.stringValue = this.getValue(eventMap, "string", ""); - data.audioPath = this.getValue(eventMap, "audio", null); + data.intValue = getValue(eventMap, "int", 0); + data.floatValue = getValue(eventMap, "float", 0); + data.stringValue = getValue(eventMap, "string", ""); + data.audioPath = getValue(eventMap, "audio", null); if (data.audioPath != null) { - data.volume = this.getValue(eventMap, "volume", 1); - data.balance = this.getValue(eventMap, "balance", 0); + data.volume = getValue(eventMap, "volume", 1); + data.balance = getValue(eventMap, "balance", 0); } skeletonData.events.push(data); } @@ -320,23 +320,23 @@ module spine { readAttachment (map: any, skin: Skin, slotIndex: number, name: string, skeletonData: SkeletonData): Attachment { let scale = this.scale; - name = this.getValue(map, "name", name); + name = getValue(map, "name", name); - switch (this.getValue(map, "type", "region")) { + switch (getValue(map, "type", "region")) { case "region": { - let path = this.getValue(map, "path", name); + let path = getValue(map, "path", name); let region = this.attachmentLoader.newRegionAttachment(skin, name, path); if (region == null) return null; region.path = path; - region.x = this.getValue(map, "x", 0) * scale; - region.y = this.getValue(map, "y", 0) * scale; - region.scaleX = this.getValue(map, "scaleX", 1); - region.scaleY = this.getValue(map, "scaleY", 1); - region.rotation = this.getValue(map, "rotation", 0); + region.x = getValue(map, "x", 0) * scale; + region.y = getValue(map, "y", 0) * scale; + region.scaleX = getValue(map, "scaleX", 1); + region.scaleY = getValue(map, "scaleY", 1); + region.rotation = getValue(map, "rotation", 0); region.width = map.width * scale; region.height = map.height * scale; - let color: string = this.getValue(map, "color", null); + let color: string = getValue(map, "color", null); if (color != null) region.color.setFromString(color); region.updateOffset(); @@ -346,26 +346,26 @@ module spine { let box = this.attachmentLoader.newBoundingBoxAttachment(skin, name); if (box == null) return null; this.readVertices(map, box, map.vertexCount << 1); - let color: string = this.getValue(map, "color", null); + let color: string = getValue(map, "color", null); if (color != null) box.color.setFromString(color); return box; } case "mesh": case "linkedmesh": { - let path = this.getValue(map, "path", name); + let path = getValue(map, "path", name); let mesh = this.attachmentLoader.newMeshAttachment(skin, name, path); if (mesh == null) return null; mesh.path = path; - let color = this.getValue(map, "color", null); + let color = getValue(map, "color", null); if (color != null) mesh.color.setFromString(color); - mesh.width = this.getValue(map, "width", 0) * scale; - mesh.height = this.getValue(map, "height", 0) * scale; + mesh.width = getValue(map, "width", 0) * scale; + mesh.height = getValue(map, "height", 0) * scale; - let parent: string = this.getValue(map, "parent", null); + let parent: string = getValue(map, "parent", null); if (parent != null) { - this.linkedMeshes.push(new LinkedMesh(mesh, this.getValue(map, "skin", null), slotIndex, parent, this.getValue(map, "deform", true))); + this.linkedMeshes.push(new LinkedMesh(mesh, getValue(map, "skin", null), slotIndex, parent, getValue(map, "deform", true))); return mesh; } @@ -375,15 +375,15 @@ module spine { mesh.regionUVs = uvs; mesh.updateUVs(); - mesh.edges = this.getValue(map, "edges", null); - mesh.hullLength = this.getValue(map, "hull", 0) * 2; + mesh.edges = getValue(map, "edges", null); + mesh.hullLength = getValue(map, "hull", 0) * 2; return mesh; } case "path": { let path = this.attachmentLoader.newPathAttachment(skin, name); if (path == null) return null; - path.closed = this.getValue(map, "closed", false); - path.constantSpeed = this.getValue(map, "constantSpeed", true); + path.closed = getValue(map, "closed", false); + path.constantSpeed = getValue(map, "constantSpeed", true); let vertexCount = map.vertexCount; this.readVertices(map, path, vertexCount << 1); @@ -393,18 +393,18 @@ module spine { lengths[i] = map.lengths[i] * scale; path.lengths = lengths; - let color: string = this.getValue(map, "color", null); + let color: string = getValue(map, "color", null); if (color != null) path.color.setFromString(color); return path; } case "point": { let point = this.attachmentLoader.newPointAttachment(skin, name); if (point == null) return null; - point.x = this.getValue(map, "x", 0) * scale; - point.y = this.getValue(map, "y", 0) * scale; - point.rotation = this.getValue(map, "rotation", 0); + point.x = getValue(map, "x", 0) * scale; + point.y = getValue(map, "y", 0) * scale; + point.rotation = getValue(map, "rotation", 0); - let color = this.getValue(map, "color", null); + let color = getValue(map, "color", null); if (color != null) point.color.setFromString(color); return point; } @@ -412,7 +412,7 @@ module spine { let clip = this.attachmentLoader.newClippingAttachment(skin, name); if (clip == null) return null; - let end = this.getValue(map, "end", null); + let end = getValue(map, "end", null); if (end != null) { let slot = skeletonData.findSlot(end); if (slot == null) throw new Error("Clipping end slot not found: " + end); @@ -422,7 +422,7 @@ module spine { let vertexCount = map.vertexCount; this.readVertices(map, clip, vertexCount << 1); - let color: string = this.getValue(map, "color", null); + let color: string = getValue(map, "color", null); if (color != null) clip.color.setFromString(color); return clip; } @@ -476,30 +476,28 @@ module spine { let timeline = new AttachmentTimeline(timelineMap.length, slotIndex); for (let frame = 0; frame < timelineMap.length; frame++) { let keyMap = timelineMap[frame]; - timeline.setFrame(frame, this.getValue(keyMap, "time", 0), keyMap.name); + timeline.setFrame(frame, getValue(keyMap, "time", 0), keyMap.name); } timelines.push(timeline); } else if (timelineName == "rgba") { let timeline = new RGBATimeline(timelineMap.length, timelineMap.length << 2, slotIndex); let keyMap = timelineMap[0]; - let time = this.getValue(keyMap, "time", 0); + let time = getValue(keyMap, "time", 0); let color = new Color().setFromString(keyMap.color); for (let frame = 0, bezier = 0;; frame++) { timeline.setFrame(frame, time, color.r, color.g, color.b, color.a); - if (timelineMap.length == frame + 1) { - break; - } + if (timelineMap.length == frame + 1) break; let nextMap = timelineMap[frame + 1]; - let time2 = this.getValue(nextMap, "time", 0); + let time2 = getValue(nextMap, "time", 0); let newColor = new Color().setFromString(nextMap.color); let curve = keyMap.curve; if (curve) { - bezier = this.readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1); - bezier = this.readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1); - bezier = this.readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1); - bezier = this.readCurve(curve, timeline, bezier, frame, 3, time, time2, color.a, newColor.a, 1); + bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1); + bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1); + bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1); + bezier = readCurve(curve, timeline, bezier, frame, 3, time, time2, color.a, newColor.a, 1); } time = time2; color = newColor; @@ -511,22 +509,20 @@ module spine { } else if (timelineName == "rgb") { let timeline = new RGBTimeline(timelineMap.length, timelineMap.length * 3, slotIndex); let keyMap = timelineMap[0]; - let time = this.getValue(keyMap, "time", 0); + let time = getValue(keyMap, "time", 0); let color = new Color().setFromString(keyMap.color); for (let frame = 0, bezier = 0;; frame++) { timeline.setFrame(frame, time, color.r, color.g, color.b); - if (timelineMap.length == frame + 1) { - break; - } + if (timelineMap.length == frame + 1) break; let nextMap = timelineMap[frame + 1]; - let time2 = this.getValue(nextMap, "time", 0); + let time2 = getValue(nextMap, "time", 0); let newColor = new Color().setFromString(nextMap.color); let curve = keyMap.curve; if (curve) { - bezier = this.readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1); - bezier = this.readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1); - bezier = this.readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1); + bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1); + bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1); + bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1); } time = time2; color = newColor; @@ -536,33 +532,31 @@ module spine { timelines.push(timeline); } else if (timelineName == "alpha") { - timelines.push(this.readTimeline(timelineMap, new AlphaTimeline(timelineMap.length, timelineMap.length, slotIndex), 0, 1)); + timelines.push(readTimeline(timelineMap, new AlphaTimeline(timelineMap.length, timelineMap.length, slotIndex), 0, 1)); } else if (timelineName == "rgba2") { let timeline = new RGBA2Timeline(timelineMap.length, timelineMap.length * 7, slotIndex); let keyMap = timelineMap[0]; - let time = this.getValue(keyMap, "time", 0); + let time = getValue(keyMap, "time", 0); let color = new Color().setFromString(keyMap.light); let color2 = new Color().setFromString(keyMap.dark); for (let frame = 0, bezier = 0;; frame++) { timeline.setFrame(frame, time, color.r, color.g, color.b, color.a, color2.r, color2.g, color2.b); - if (timelineMap.length == frame + 1) { - break; - } + if (timelineMap.length == frame + 1) break; let nextMap = timelineMap[frame + 1]; - let time2 = this.getValue(nextMap, "time", 0); + let time2 = getValue(nextMap, "time", 0); let newColor = new Color().setFromString(nextMap.light); let newColor2 = new Color().setFromString(nextMap.dark); let curve = keyMap.curve; if (curve) { - bezier = this.readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1); - bezier = this.readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1); - bezier = this.readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1); - bezier = this.readCurve(curve, timeline, bezier, frame, 3, time, time2, color.a, newColor.a, 1); - bezier = this.readCurve(curve, timeline, bezier, frame, 4, time, time2, color2.r, newColor2.r, 1); - bezier = this.readCurve(curve, timeline, bezier, frame, 5, time, time2, color2.g, newColor2.g, 1); - bezier = this.readCurve(curve, timeline, bezier, frame, 6, time, time2, color2.b, newColor2.b, 1); + bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1); + bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1); + bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1); + bezier = readCurve(curve, timeline, bezier, frame, 3, time, time2, color.a, newColor.a, 1); + bezier = readCurve(curve, timeline, bezier, frame, 4, time, time2, color2.r, newColor2.r, 1); + bezier = readCurve(curve, timeline, bezier, frame, 5, time, time2, color2.g, newColor2.g, 1); + bezier = readCurve(curve, timeline, bezier, frame, 6, time, time2, color2.b, newColor2.b, 1); } time = time2; color = newColor; @@ -576,27 +570,25 @@ module spine { let timeline = new RGB2Timeline(timelineMap.length, timelineMap.length * 6, slotIndex); let keyMap = timelineMap[0]; - let time = this.getValue(keyMap, "time", 0); + let time = getValue(keyMap, "time", 0); let color = new Color().setFromString(keyMap.light); let color2 = new Color().setFromString(keyMap.dark); for (let frame = 0, bezier = 0;; frame++) { timeline.setFrame(frame, time, color.r, color.g, color.b, color2.r, color2.g, color2.b); - if (timelineMap.length == frame + 1) { - break; - } + if (timelineMap.length == frame + 1) break; let nextMap = timelineMap[frame + 1]; - let time2 = this.getValue(nextMap, "time", 0); + let time2 = getValue(nextMap, "time", 0); let newColor = new Color().setFromString(nextMap.light); let newColor2 = new Color().setFromString(nextMap.dark); let curve = keyMap.curve; if (curve) { - bezier = this.readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1); - bezier = this.readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1); - bezier = this.readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1); - bezier = this.readCurve(curve, timeline, bezier, frame, 3, time, time2, color2.r, newColor2.r, 1); - bezier = this.readCurve(curve, timeline, bezier, frame, 4, time, time2, color2.g, newColor2.g, 1); - bezier = this.readCurve(curve, timeline, bezier, frame, 5, time, time2, color2.b, newColor2.b, 1); + bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1); + bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1); + bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1); + bezier = readCurve(curve, timeline, bezier, frame, 3, time, time2, color2.r, newColor2.r, 1); + bezier = readCurve(curve, timeline, bezier, frame, 4, time, time2, color2.g, newColor2.g, 1); + bezier = readCurve(curve, timeline, bezier, frame, 5, time, time2, color2.b, newColor2.b, 1); } time = time2; color = newColor; @@ -623,37 +615,36 @@ module spine { if (timelineMap.length == 0) continue; if (timelineName === "rotate") { - timelines.push(this.readTimeline(timelineMap, new RotateTimeline(timelineMap.length, timelineMap.length, boneIndex), 0, 1)); + timelines.push(readTimeline(timelineMap, new RotateTimeline(timelineMap.length, timelineMap.length, boneIndex), 0, 1)); } else if (timelineName === "translate") { let timeline = new TranslateTimeline(timelineMap.length, timelineMap.length << 1, boneIndex); - timelines.push(this.readTimeline2(timelineMap, timeline, "x", "y", 0, scale)); + timelines.push(readTimeline2(timelineMap, timeline, "x", "y", 0, scale)); } else if (timelineName === "translatex") { let timeline = new TranslateXTimeline(timelineMap.length, timelineMap.length, boneIndex); - timelines.push(this.readTimeline(timelineMap, timeline, 0, scale)); + timelines.push(readTimeline(timelineMap, timeline, 0, scale)); } else if (timelineName === "translatey") { let timeline = new TranslateYTimeline(timelineMap.length, timelineMap.length, boneIndex); - timelines.push(this.readTimeline(timelineMap, timeline, 0, scale)); + timelines.push(readTimeline(timelineMap, timeline, 0, scale)); } else if (timelineName === "scale") { let timeline = new ScaleTimeline(timelineMap.length, timelineMap.length << 1, boneIndex); - timelines.push(this.readTimeline2(timelineMap, timeline, "x", "y", 1, 1)); + timelines.push(readTimeline2(timelineMap, timeline, "x", "y", 1, 1)); } else if (timelineName === "scalex") { let timeline = new ScaleXTimeline(timelineMap.length, timelineMap.length, boneIndex); - timelines.push(this.readTimeline(timelineMap, timeline, 1, 1)); + timelines.push(readTimeline(timelineMap, timeline, 1, 1)); } else if (timelineName === "scaley") { let timeline = new ScaleYTimeline(timelineMap.length, timelineMap.length, boneIndex); - timelines.push(this.readTimeline(timelineMap, timeline, 1, 1)); + timelines.push(readTimeline(timelineMap, timeline, 1, 1)); } else if (timelineName === "shear") { let timeline = new ShearTimeline(timelineMap.length, timelineMap.length << 1, boneIndex); - timelines.push(this.readTimeline2(timelineMap, timeline, "x", "y", 0, 1)); + timelines.push(readTimeline2(timelineMap, timeline, "x", "y", 0, 1)); } else if (timelineName === "shearx") { let timeline = new ShearXTimeline(timelineMap.length, timelineMap.length, boneIndex); - timelines.push(this.readTimeline(timelineMap, timeline, 0, 1)); + timelines.push(readTimeline(timelineMap, timeline, 0, 1)); } else if (timelineName === "sheary") { let timeline = new ShearYTimeline(timelineMap.length, timelineMap.length, boneIndex); - timelines.push(this.readTimeline(timelineMap, timeline, 0, 1)); - } else { + timelines.push(readTimeline(timelineMap, timeline, 0, 1)); + } else throw new Error("Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")"); - } } } } @@ -669,24 +660,22 @@ module spine { let constraintIndex = skeletonData.ikConstraints.indexOf(constraint); let timeline = new IkConstraintTimeline(constraintMap.length, constraintMap.length << 1, constraintIndex); - let time = this.getValue(keyMap, "time", 0); - let mix = this.getValue(keyMap, "mix", 1); - let softness = this.getValue(keyMap, "softness", 0) * scale; + let time = getValue(keyMap, "time", 0); + let mix = getValue(keyMap, "mix", 1); + let softness = getValue(keyMap, "softness", 0) * scale; for (let frame = 0, bezier = 0;; frame++) { - timeline.setFrame(frame, time, mix, softness, this.getValue(keyMap, "bendPositive", true) ? 1 : -1, this.getValue(keyMap, "compress", false), this.getValue(keyMap, "stretch", false)) + timeline.setFrame(frame, time, mix, softness, getValue(keyMap, "bendPositive", true) ? 1 : -1, getValue(keyMap, "compress", false), getValue(keyMap, "stretch", false)); let nextMap = constraintMap[frame + 1]; - if (!nextMap) { - break; - } + if (!nextMap) break; - let time2 = this.getValue(nextMap, "time", 0); - let mix2 = this.getValue(nextMap, "mix", 1); - let softness2 = this.getValue(nextMap, "softness", 0) * scale; + let time2 = getValue(nextMap, "time", 0); + let mix2 = getValue(nextMap, "mix", 1); + let softness2 = getValue(nextMap, "softness", 0) * scale; let curve = keyMap.curve; if (curve) { - bezier = this.readCurve(curve, timeline, bezier, frame, 0, time, time2, mix, mix2, 1); - bezier = this.readCurve(curve, timeline, bezier, frame, 1, time, time2, softness, softness2, scale); + bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, mix, mix2, 1); + bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, softness, softness2, scale); } time = time2; @@ -709,36 +698,34 @@ module spine { let constraintIndex = skeletonData.transformConstraints.indexOf(constraint); let timeline = new TransformConstraintTimeline(timelineMap.length, timelineMap.length << 2, constraintIndex); - let time = this.getValue(keyMap, "time", 0); - let mixRotate = this.getValue(keyMap, "mixRotate", 1); - let mixShearY = this.getValue(keyMap, "mixShearY", 1); - let mixX = this.getValue(keyMap, "mixX", 1); - let mixY = this.getValue(keyMap, "mixY", mixX); - let mixScaleX = this.getValue(keyMap, "mixScaleX", 1); - let mixScaleY = this.getValue(keyMap, "mixScaleY", mixScaleX); + let time = getValue(keyMap, "time", 0); + let mixRotate = getValue(keyMap, "mixRotate", 1); + let mixShearY = getValue(keyMap, "mixShearY", 1); + let mixX = getValue(keyMap, "mixX", 1); + let mixY = getValue(keyMap, "mixY", mixX); + let mixScaleX = getValue(keyMap, "mixScaleX", 1); + let mixScaleY = getValue(keyMap, "mixScaleY", mixScaleX); for (let frame = 0, bezier = 0;; frame++) { timeline.setFrame(frame, time, mixRotate, mixX, mixY, mixScaleX, mixScaleY, mixShearY); let nextMap = timelineMap[frame + 1]; - if (!nextMap) { - break; - } + if (!nextMap) break; - let time2 = this.getValue(nextMap, "time", 0); - let mixRotate2 = this.getValue(nextMap, "mixRotate", 1); - let mixShearY2 = this.getValue(nextMap, "mixShearY", 1); - let mixX2 = this.getValue(nextMap, "mixX", 1); - let mixY2 = this.getValue(nextMap, "mixY", mixX2); - let mixScaleX2 = this.getValue(nextMap, "mixScaleX", 1); - let mixScaleY2 = this.getValue(nextMap, "mixScaleY", mixScaleX2); + let time2 = getValue(nextMap, "time", 0); + let mixRotate2 = getValue(nextMap, "mixRotate", 1); + let mixShearY2 = getValue(nextMap, "mixShearY", 1); + let mixX2 = getValue(nextMap, "mixX", 1); + let mixY2 = getValue(nextMap, "mixY", mixX2); + let mixScaleX2 = getValue(nextMap, "mixScaleX", 1); + let mixScaleY2 = getValue(nextMap, "mixScaleY", mixScaleX2); let curve = keyMap.curve; if (curve) { - bezier = this.readCurve(curve, timeline, bezier, frame, 0, time, time2, mixRotate, mixRotate2, 1); - bezier = this.readCurve(curve, timeline, bezier, frame, 1, time, time2, mixX, mixX2, 1); - bezier = this.readCurve(curve, timeline, bezier, frame, 2, time, time2, mixY, mixY2, 1); - bezier = this.readCurve(curve, timeline, bezier, frame, 3, time, time2, mixScaleX, mixScaleX2, 1); - bezier = this.readCurve(curve, timeline, bezier, frame, 4, time, time2, mixScaleY, mixScaleY2, 1); - bezier = this.readCurve(curve, timeline, bezier, frame, 5, time, time2, mixShearY, mixShearY2, 1); + bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, mixRotate, mixRotate2, 1); + bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, mixX, mixX2, 1); + bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, mixY, mixY2, 1); + bezier = readCurve(curve, timeline, bezier, frame, 3, time, time2, mixScaleX, mixScaleX2, 1); + bezier = readCurve(curve, timeline, bezier, frame, 4, time, time2, mixScaleY, mixScaleY2, 1); + bezier = readCurve(curve, timeline, bezier, frame, 5, time, time2, mixShearY, mixShearY2, 1); } time = time2; @@ -768,31 +755,29 @@ module spine { if (timelineName === "position") { let timeline = new PathConstraintPositionTimeline(timelineMap.length, timelineMap.length, index); - timelines.push(this.readTimeline(timelineMap, timeline, 0, data.positionMode == PositionMode.Fixed ? scale : 1)); + timelines.push(readTimeline(timelineMap, timeline, 0, data.positionMode == PositionMode.Fixed ? scale : 1)); } else if (timelineName === "spacing") { let timeline = new PathConstraintSpacingTimeline(timelineMap.length, timelineMap.length, index); - timelines.push(this.readTimeline(timelineMap, timeline, 0, data.spacingMode == SpacingMode.Length || data.spacingMode == SpacingMode.Fixed ? scale : 1)); + timelines.push(readTimeline(timelineMap, timeline, 0, data.spacingMode == SpacingMode.Length || data.spacingMode == SpacingMode.Fixed ? scale : 1)); } else if (timelineName === "mix") { let timeline = new PathConstraintMixTimeline(timelineMap.size, timelineMap.size * 3, index); - let time = this.getValue(keyMap, "time", 0); - let mixRotate = this.getValue(keyMap, "mixRotate", 1); - let mixX = this.getValue(keyMap, "mixX", 1); - let mixY = this.getValue(keyMap, "mixY", mixX); + let time = getValue(keyMap, "time", 0); + let mixRotate = getValue(keyMap, "mixRotate", 1); + let mixX = getValue(keyMap, "mixX", 1); + let mixY = getValue(keyMap, "mixY", mixX); for (let frame = 0, bezier = 0;; frame++) { timeline.setFrame(frame, time, mixRotate, mixX, mixY); let nextMap = timelineMap[frame + 1]; - if (!nextMap) { - break; - } - let time2 = this.getValue(nextMap, "time", 0); - let mixRotate2 = this.getValue(nextMap, "mixRotate", 1); - let mixX2 = this.getValue(nextMap, "mixX", 1); - let mixY2 = this.getValue(nextMap, "mixY", mixX2); + if (!nextMap) break; + let time2 = getValue(nextMap, "time", 0); + let mixRotate2 = getValue(nextMap, "mixRotate", 1); + let mixX2 = getValue(nextMap, "mixX", 1); + let mixY2 = getValue(nextMap, "mixY", mixX2); let curve = keyMap.curve; if (curve != null) { - bezier = this.readCurve(curve, timeline, bezier, frame, 0, time, time2, mixRotate, mixRotate2, 1); - bezier = this.readCurve(curve, timeline, bezier, frame, 1, time, time2, mixX, mixX2, 1); - bezier = this.readCurve(curve, timeline, bezier, frame, 2, time, time2, mixY, mixY2, 1); + bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, mixRotate, mixRotate2, 1); + bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, mixX, mixX2, 1); + bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, mixY, mixY2, 1); } time = time2; mixRotate = mixRotate2; @@ -828,15 +813,15 @@ module spine { let deformLength = weighted ? vertices.length / 3 * 2 : vertices.length; let timeline = new DeformTimeline(timelineMap.length, timelineMap.length, slotIndex, attachment); - let time = this.getValue(keyMap, "time", 0); + let time = getValue(keyMap, "time", 0); for (let frame = 0, bezier = 0;; frame++) { let deform: ArrayLike; - let verticesValue: Array = this.getValue(keyMap, "vertices", null); + let verticesValue: Array = getValue(keyMap, "vertices", null); if (verticesValue == null) deform = weighted ? Utils.newFloatArray(deformLength) : vertices; else { deform = Utils.newFloatArray(deformLength); - let start = this.getValue(keyMap, "offset", 0); + let start = getValue(keyMap, "offset", 0); Utils.arrayCopy(verticesValue, 0, deform, start, verticesValue.length); if (scale != 1) { for (let i = start, n = i + verticesValue.length; i < n; i++) @@ -850,14 +835,10 @@ module spine { timeline.setFrame(frame, time, deform); let nextMap = timelineMap[frame + 1]; - if (!nextMap) { - break; - } - let time2 = this.getValue(nextMap, "time", 0); + if (!nextMap) break; + let time2 = getValue(nextMap, "time", 0); let curve = keyMap.curve; - if (curve) { - bezier = this.readCurve(curve, timeline, bezier, frame, 0, time, time2, 0, 1, 1); - } + if (curve) bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, 0, 1, 1); time = time2; keyMap = nextMap; } @@ -867,7 +848,7 @@ module spine { } } - // Draw order timeline. + // Draw order timelines. let drawOrderNode = map.drawOrder; if (drawOrderNode == null) drawOrderNode = map.draworder; if (drawOrderNode != null) { @@ -877,7 +858,7 @@ module spine { for (let j = 0; j < drawOrderNode.length; j++, frame++) { let drawOrderMap = drawOrderNode[j]; let drawOrder: Array = null; - let offsets = this.getValue(drawOrderMap, "offsets", null); + let offsets = getValue(drawOrderMap, "offsets", null); if (offsets != null) { drawOrder = Utils.newArray(slotCount, -1); let unchanged = Utils.newArray(slotCount - offsets.length, 0); @@ -899,12 +880,12 @@ module spine { for (let i = slotCount - 1; i >= 0; i--) if (drawOrder[i] == -1) drawOrder[i] = unchanged[--unchangedIndex]; } - timeline.setFrame(frame, this.getValue(drawOrderMap, "time", 0), drawOrder); + timeline.setFrame(frame, getValue(drawOrderMap, "time", 0), drawOrder); } timelines.push(timeline); } - // Event timeline. + // Event timelines. if (map.events) { let timeline = new EventTimeline(map.events.length); let frame = 0; @@ -912,13 +893,13 @@ module spine { let eventMap = map.events[i]; let eventData = skeletonData.findEvent(eventMap.name); if (eventData == null) throw new Error("Event not found: " + eventMap.name); - let event = new Event(Utils.toSinglePrecision(this.getValue(eventMap, "time", 0)), eventData); - event.intValue = this.getValue(eventMap, "int", eventData.intValue); - event.floatValue = this.getValue(eventMap, "float", eventData.floatValue); - event.stringValue = this.getValue(eventMap, "string", eventData.stringValue); + let event = new Event(Utils.toSinglePrecision(getValue(eventMap, "time", 0)), eventData); + event.intValue = getValue(eventMap, "int", eventData.intValue); + event.floatValue = getValue(eventMap, "float", eventData.floatValue); + event.stringValue = getValue(eventMap, "string", eventData.stringValue); if (event.data.audioPath != null) { - event.volume = this.getValue(eventMap, "volume", 1); - event.balance = this.getValue(eventMap, "balance", 0); + event.volume = getValue(eventMap, "volume", 1); + event.balance = getValue(eventMap, "balance", 0); } timeline.setFrame(frame, event); } @@ -927,28 +908,25 @@ module spine { let duration = 0; for (let i = 0, n = timelines.length; i < n; i++) - duration = Math.max(duration, (timelines[i]).getDuration()); - - if (isNaN(duration)) { - throw new Error("Error while parsing animation, duration is NaN"); - } + duration = Math.max(duration, timelines[i].getDuration()); + if (isNaN(duration)) throw new Error("Animation duration is NaN."); skeletonData.animations.push(new Animation(name, timelines, duration)); } - private readTimeline (keys: any[], timeline: CurveTimeline1, defaultValue: number, scale: number) { + static private readTimeline (keys: any[], timeline: CurveTimeline1, defaultValue: number, scale: number) { let keyMap = keys[0]; - let time = this.getValue(keyMap, "time", 0); - let value = this.getValue(keyMap, "value", defaultValue) * scale; + let time = getValue(keyMap, "time", 0); + let value = getValue(keyMap, "value", defaultValue) * scale; let bezier = 0; for (let frame = 0;; frame++) { timeline.setFrame(frame, time, value); let nextMap = keys[frame + 1]; if (!nextMap) break; - let time2 = this.getValue(nextMap, "time", 0); - let value2 = this.getValue(nextMap, "value", defaultValue) * scale; + let time2 = getValue(nextMap, "time", 0); + let value2 = getValue(nextMap, "value", defaultValue) * scale; let curve = keyMap.curve; - if (curve) bezier = this.readCurve(curve, timeline, bezier, frame, 0, time, time2, value, value2, scale); + if (curve) bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, value, value2, scale); time = time2; value = value2; keyMap = nextMap; @@ -956,23 +934,23 @@ module spine { return timeline; } - private readTimeline2 (keys: any[], timeline: CurveTimeline2, name1: string, name2: string, defaultValue: number, scale: number) { + static private readTimeline2 (keys: any[], timeline: CurveTimeline2, name1: string, name2: string, defaultValue: number, scale: number) { let keyMap = keys[0]; - let time = this.getValue(keyMap, "time", 0); - let value1 = this.getValue(keyMap, name1, defaultValue) * scale; - let value2 = this.getValue(keyMap, name2, defaultValue) * scale; + let time = getValue(keyMap, "time", 0); + let value1 = getValue(keyMap, name1, defaultValue) * scale; + let value2 = getValue(keyMap, name2, defaultValue) * scale; let bezier = 0; for (let frame = 0;; frame++) { timeline.setFrame(frame, time, value1, value2); let nextMap = keys[frame + 1]; if (!nextMap) break; - let time2 = this.getValue(nextMap, "time", 0); - let nvalue1 = this.getValue(nextMap, name1, defaultValue) * scale; - let nvalue2 = this.getValue(nextMap, name2, defaultValue) * scale; + let time2 = getValue(nextMap, "time", 0); + let nvalue1 = getValue(nextMap, name1, defaultValue) * scale; + let nvalue2 = getValue(nextMap, name2, defaultValue) * scale; let curve = keyMap.curve; if (curve != null) { - bezier = this.readCurve(curve, timeline, bezier, frame, 0, time, time2, value1, nvalue1, scale); - bezier = this.readCurve(curve, timeline, bezier, frame, 1, time, time2, value2, nvalue2, scale); + bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, value1, nvalue1, scale); + bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, value2, nvalue2, scale); } time = time2; value1 = nvalue1; @@ -983,7 +961,7 @@ module spine { return timeline; } - private readCurve (curve: any, timeline: CurveTimeline, bezier: number, frame: number, value: number, time1: number, time2: number, + static private readCurve (curve: any, timeline: CurveTimeline, bezier: number, frame: number, value: number, time1: number, time2: number, value1: number, value2: number, scale: number) { if (curve == "stepped") { if (value != 0) timeline.setStepped(frame); @@ -993,21 +971,16 @@ module spine { let cy1 = curve[i++] * scale; let cx2 = curve[i++]; let cy2 = curve[i++] * scale; - this.setBezier(timeline, frame, value, bezier++, time1, value1, cx1, cy1, cx2, cy2, time2, value2); + timeline.setBezier(bezier++, frame, value, time1, value1, cx1, cy1, cx2, cy2, time2, value2); } return bezier; } - setBezier (timeline: CurveTimeline, frame: number, value: number, bezier: number, time1: number, value1: number, cx1: number, cy1: number, - cx2: number, cy2: number, time2: number, value2: number) { - timeline.setBezier(bezier, frame, value, time1, value1, cx1, cy1, cx2, cy2, time2, value2); - } - - getValue (map: any, property: string, defaultValue: any) { + static private getValue (map: any, property: string, defaultValue: any) { return map[property] !== undefined ? map[property] : defaultValue; } - static blendModeFromString (str: string) { + static private blendModeFromString (str: string) { str = str.toLowerCase(); if (str == "normal") return BlendMode.Normal; if (str == "additive") return BlendMode.Additive; @@ -1016,14 +989,14 @@ module spine { throw new Error(`Unknown blend mode: ${str}`); } - static positionModeFromString (str: string) { + static private positionModeFromString (str: string) { str = str.toLowerCase(); if (str == "fixed") return PositionMode.Fixed; if (str == "percent") return PositionMode.Percent; throw new Error(`Unknown position mode: ${str}`); } - static spacingModeFromString (str: string) { + static private spacingModeFromString (str: string) { str = str.toLowerCase(); if (str == "length") return SpacingMode.Length; if (str == "fixed") return SpacingMode.Fixed; @@ -1032,7 +1005,7 @@ module spine { throw new Error(`Unknown spacing mode: ${str}`); } - static rotateModeFromString (str: string) { + static private rotateModeFromString (str: string) { str = str.toLowerCase(); if (str == "tangent") return RotateMode.Tangent; if (str == "chain") return RotateMode.Chain; @@ -1040,7 +1013,7 @@ module spine { throw new Error(`Unknown rotate mode: ${str}`); } - static transformModeFromString(str: string) { + static private transformModeFromString(str: string) { str = str.toLowerCase(); if (str == "normal") return TransformMode.Normal; if (str == "onlytranslation") return TransformMode.OnlyTranslation; diff --git a/spine-ts/core/src/TransformConstraint.ts b/spine-ts/core/src/TransformConstraint.ts index ff3cb2bab..8a25df320 100644 --- a/spine-ts/core/src/TransformConstraint.ts +++ b/spine-ts/core/src/TransformConstraint.ts @@ -77,7 +77,6 @@ module spine { this.applyRelativeLocal(); else this.applyAbsoluteLocal(); - } else { if (this.data.relative) this.applyRelativeWorld(); @@ -90,6 +89,7 @@ module spine { let mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY, mixScaleX = this.mixScaleX, mixScaleY = this.mixScaleY, mixShearY = this.mixShearY; let translate = mixX != 0 || mixY != 0; + let target = this.target; let ta = target.a, tb = target.b, tc = target.c, td = target.d; let degRadReflect = ta * td - tb * tc > 0 ? MathUtils.degRad : -MathUtils.degRad; @@ -133,7 +133,6 @@ module spine { if (s != 0) s = (s + (Math.sqrt(tb * tb + td * td) - s + this.data.offsetScaleY) * mixScaleY) / s; bone.b *= s; bone.d *= s; - } if (mixShearY > 0) { @@ -148,7 +147,6 @@ module spine { let s = Math.sqrt(b * b + d * d); bone.b = Math.cos(r) * s; bone.d = Math.sin(r) * s; - } bone.appliedValid = false; diff --git a/spine-ts/core/src/Utils.ts b/spine-ts/core/src/Utils.ts index 330bb5106..6fa09a5f3 100644 --- a/spine-ts/core/src/Utils.ts +++ b/spine-ts/core/src/Utils.ts @@ -61,21 +61,22 @@ module spine { add (value: string): boolean { let contains = this.entries[value]; this.entries[value] = true; - if (!contains) this.size++; - return contains != true; + if (!contains) { + this.size++; + return true; + } + return false; } addAll (values: string[]): boolean { let oldSize = this.size; - for (var i = 0, n = values.length; i < n; i++) { + for (var i = 0, n = values.length; i < n; i++) this.add(values[i]); - } return oldSize != this.size; } contains (value: string) { - let contains = this.entries[value]; - return contains == true; + return this.entries[value]; } clear () { @@ -280,22 +281,22 @@ module spine { } static newFloatArray (size: number): ArrayLike { - if (Utils.SUPPORTS_TYPED_ARRAYS) { + if (Utils.SUPPORTS_TYPED_ARRAYS) return new Float32Array(size) - } else { - let array = new Array(size); - for (let i = 0; i < array.length; i++) array[i] = 0; - return array; + else { + let array = new Array(size); + for (let i = 0; i < array.length; i++) array[i] = 0; + return array; } } static newShortArray (size: number): ArrayLike { - if (Utils.SUPPORTS_TYPED_ARRAYS) { + if (Utils.SUPPORTS_TYPED_ARRAYS) return new Int16Array(size) - } else { - let array = new Array(size); - for (let i = 0; i < array.length; i++) array[i] = 0; - return array; + else { + let array = new Array(size); + for (let i = 0; i < array.length; i++) array[i] = 0; + return array; } } @@ -313,9 +314,8 @@ module spine { } static contains (array: Array, element: T, identity = true) { - for (var i = 0; i < array.length; i++) { + for (var i = 0; i < array.length; i++) if (array[i] == element) return true; - } return false; } } @@ -347,9 +347,8 @@ module spine { } freeAll (items: ArrayLike) { - for (let i = 0; i < items.length; i++) { + for (let i = 0; i < items.length; i++) this.free(items[i]); - } } clear () { @@ -431,8 +430,7 @@ module spine { } addValue (value: number) { - if (this.addedValues < this.values.length) - this.addedValues++; + if (this.addedValues < this.values.length) this.addedValues++; this.values[this.lastValue++] = value; if (this.lastValue > this.values.length - 1) this.lastValue = 0; this.dirty = true; @@ -442,16 +440,14 @@ module spine { if (this.hasEnoughData()) { if (this.dirty) { let mean = 0; - for (let i = 0; i < this.values.length; i++) { + for (let i = 0; i < this.values.length; i++) mean += this.values[i]; - } this.mean = mean / this.values.length; this.dirty = false; } return this.mean; - } else { - return 0; } + return 0; } } }