[ts] Port to 4.3 (WIP) - Format.

This commit is contained in:
Davide Tantillo 2025-06-10 17:42:39 +02:00
parent d7212370f6
commit 59d138124d
9 changed files with 35 additions and 35 deletions

View File

@ -283,7 +283,7 @@ export interface SlotTimeline {
slotIndex: number; slotIndex: number;
} }
export function isSlotTimeline(obj: any): obj is SlotTimeline { export function isSlotTimeline (obj: any): obj is SlotTimeline {
return typeof obj === 'object' && obj !== null && typeof obj.slotIndex === 'number'; return typeof obj === 'object' && obj !== null && typeof obj.slotIndex === 'number';
} }
@ -436,7 +436,7 @@ export abstract class CurveTimeline1 extends CurveTimeline {
} }
} }
getAbsoluteValue(time: number, alpha: number, blend: MixBlend, current: number, setup: number, value?: number) { getAbsoluteValue (time: number, alpha: number, blend: MixBlend, current: number, setup: number, value?: number) {
if (value === undefined) if (value === undefined)
return this.getAbsoluteValue1(time, alpha, blend, current, setup); return this.getAbsoluteValue1(time, alpha, blend, current, setup);
else else
@ -543,7 +543,7 @@ export abstract class BoneTimeline2 extends CurveTimeline implements BoneTimelin
if (bone.active) this.apply1(appliedPose ? bone.applied : bone.pose, bone.data.setup, time, alpha, blend, direction); if (bone.active) this.apply1(appliedPose ? bone.applied : bone.pose, bone.data.setup, time, alpha, blend, direction);
} }
protected abstract apply1 (pose: BoneLocal, setup: BoneLocal, time: number, alpha:number, blend: MixBlend, protected abstract apply1 (pose: BoneLocal, setup: BoneLocal, time: number, alpha: number, blend: MixBlend,
direction: MixDirection): void; direction: MixDirection): void;
} }
@ -552,7 +552,7 @@ export interface BoneTimeline {
boneIndex: number; boneIndex: number;
} }
export function isBoneTimeline(obj: any): obj is BoneTimeline { export function isBoneTimeline (obj: any): obj is BoneTimeline {
return typeof obj === 'object' && obj !== null && typeof obj.boneIndex === 'number'; return typeof obj === 'object' && obj !== null && typeof obj.boneIndex === 'number';
} }
@ -571,7 +571,7 @@ export abstract class BoneTimeline1 extends CurveTimeline1 implements BoneTimeli
if (bone.active) this.apply1(appliedPose ? bone.applied : bone.pose, bone.data.setup, time, alpha, blend, direction); if (bone.active) this.apply1(appliedPose ? bone.applied : bone.pose, bone.data.setup, time, alpha, blend, direction);
} }
protected abstract apply1 (pose: BoneLocal, setup: BoneLocal, time: number, alpha:number, blend: MixBlend, protected abstract apply1 (pose: BoneLocal, setup: BoneLocal, time: number, alpha: number, blend: MixBlend,
direction: MixDirection): void; direction: MixDirection): void;
} }
@ -581,7 +581,7 @@ export class RotateTimeline extends BoneTimeline1 {
super(frameCount, bezierCount, boneIndex, Property.rotate); super(frameCount, bezierCount, boneIndex, Property.rotate);
} }
apply1 (pose: BoneLocal, setup: BoneLocal, time: number, alpha:number, blend: MixBlend, direction: MixDirection) { apply1 (pose: BoneLocal, setup: BoneLocal, time: number, alpha: number, blend: MixBlend, direction: MixDirection) {
pose.rotation = this.getRelativeValue(time, alpha, blend, pose.rotation, setup.rotation); pose.rotation = this.getRelativeValue(time, alpha, blend, pose.rotation, setup.rotation);
} }
} }
@ -592,7 +592,7 @@ export class TranslateTimeline extends BoneTimeline2 {
super(frameCount, bezierCount, boneIndex, Property.x, Property.y); super(frameCount, bezierCount, boneIndex, Property.x, Property.y);
} }
apply1 (pose: BoneLocal, setup: BoneLocal, time: number, alpha:number, blend: MixBlend,direction: MixDirection) { apply1 (pose: BoneLocal, setup: BoneLocal, time: number, alpha: number, blend: MixBlend, direction: MixDirection) {
let frames = this.frames; let frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
switch (blend) { switch (blend) {
@ -651,7 +651,7 @@ export class TranslateXTimeline extends BoneTimeline1 {
super(frameCount, bezierCount, boneIndex, Property.x); super(frameCount, bezierCount, boneIndex, Property.x);
} }
protected apply1 (pose: BoneLocal, setup: BoneLocal, time: number, alpha:number, blend: MixBlend,direction: MixDirection) { protected apply1 (pose: BoneLocal, setup: BoneLocal, time: number, alpha: number, blend: MixBlend, direction: MixDirection) {
pose.x = this.getRelativeValue(time, alpha, blend, pose.x, setup.x); pose.x = this.getRelativeValue(time, alpha, blend, pose.x, setup.x);
} }
} }
@ -662,7 +662,7 @@ export class TranslateYTimeline extends BoneTimeline1 {
super(frameCount, bezierCount, boneIndex, Property.y); super(frameCount, bezierCount, boneIndex, Property.y);
} }
protected apply1 (pose: BoneLocal, setup: BoneLocal, time: number, alpha:number, blend: MixBlend,direction: MixDirection) { protected apply1 (pose: BoneLocal, setup: BoneLocal, time: number, alpha: number, blend: MixBlend, direction: MixDirection) {
pose.y = this.getRelativeValue(time, alpha, blend, pose.y, setup.y); pose.y = this.getRelativeValue(time, alpha, blend, pose.y, setup.y);
} }
} }
@ -673,7 +673,7 @@ export class ScaleTimeline extends BoneTimeline2 {
super(frameCount, bezierCount, boneIndex, Property.scaleX, Property.scaleY); super(frameCount, bezierCount, boneIndex, Property.scaleX, Property.scaleY);
} }
protected apply1 (pose: BoneLocal, setup: BoneLocal, time: number, alpha:number, blend: MixBlend, direction: MixDirection) { protected apply1 (pose: BoneLocal, setup: BoneLocal, time: number, alpha: number, blend: MixBlend, direction: MixDirection) {
let frames = this.frames; let frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
switch (blend) { switch (blend) {
@ -770,7 +770,7 @@ export class ScaleXTimeline extends BoneTimeline1 {
super(frameCount, bezierCount, boneIndex, Property.scaleX); super(frameCount, bezierCount, boneIndex, Property.scaleX);
} }
protected apply1 (pose: BoneLocal, setup: BoneLocal, time: number, alpha:number, blend: MixBlend,direction: MixDirection) { protected apply1 (pose: BoneLocal, setup: BoneLocal, time: number, alpha: number, blend: MixBlend, direction: MixDirection) {
pose.scaleX = this.getScaleValue(time, alpha, blend, direction, pose.scaleX, setup.scaleX); pose.scaleX = this.getScaleValue(time, alpha, blend, direction, pose.scaleX, setup.scaleX);
} }
} }
@ -781,7 +781,7 @@ export class ScaleYTimeline extends BoneTimeline1 {
super(frameCount, bezierCount, boneIndex, Property.scaleY); super(frameCount, bezierCount, boneIndex, Property.scaleY);
} }
protected apply1 (pose: BoneLocal, setup: BoneLocal, time: number, alpha:number, blend: MixBlend,direction: MixDirection) { protected apply1 (pose: BoneLocal, setup: BoneLocal, time: number, alpha: number, blend: MixBlend, direction: MixDirection) {
pose.scaleY = this.getScaleValue(time, alpha, blend, direction, pose.scaleY, setup.scaleY); pose.scaleY = this.getScaleValue(time, alpha, blend, direction, pose.scaleY, setup.scaleY);
} }
} }
@ -792,7 +792,7 @@ export class ShearTimeline extends BoneTimeline2 {
super(frameCount, bezierCount, boneIndex, Property.shearX, Property.shearY); super(frameCount, bezierCount, boneIndex, Property.shearX, Property.shearY);
} }
protected apply1 (pose: BoneLocal, setup: BoneLocal, time: number, alpha:number, blend: MixBlend,direction: MixDirection) { protected apply1 (pose: BoneLocal, setup: BoneLocal, time: number, alpha: number, blend: MixBlend, direction: MixDirection) {
let frames = this.frames; let frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
switch (blend) { switch (blend) {
@ -851,7 +851,7 @@ export class ShearXTimeline extends BoneTimeline1 {
super(frameCount, bezierCount, boneIndex, Property.shearX); super(frameCount, bezierCount, boneIndex, Property.shearX);
} }
protected apply1 (pose: BoneLocal, setup: BoneLocal, time: number, alpha:number, blend: MixBlend,direction: MixDirection) { protected apply1 (pose: BoneLocal, setup: BoneLocal, time: number, alpha: number, blend: MixBlend, direction: MixDirection) {
pose.shearX = this.getRelativeValue(time, alpha, blend, pose.shearX, setup.shearX); pose.shearX = this.getRelativeValue(time, alpha, blend, pose.shearX, setup.shearX);
} }
} }
@ -862,7 +862,7 @@ export class ShearYTimeline extends BoneTimeline1 {
super(frameCount, bezierCount, boneIndex, Property.shearY); super(frameCount, bezierCount, boneIndex, Property.shearY);
} }
protected apply1 (pose: BoneLocal, setup: BoneLocal, time: number, alpha:number, blend: MixBlend,direction: MixDirection) { protected apply1 (pose: BoneLocal, setup: BoneLocal, time: number, alpha: number, blend: MixBlend, direction: MixDirection) {
pose.shearY = this.getRelativeValue(time, alpha, blend, pose.shearY, setup.shearY); pose.shearY = this.getRelativeValue(time, alpha, blend, pose.shearY, setup.shearY);
} }
} }
@ -957,7 +957,7 @@ export class RGBATimeline extends SlotCurveTimeline {
switch (blend) { switch (blend) {
case MixBlend.setup: color.setFromColor(setup); break; case MixBlend.setup: color.setFromColor(setup); break;
case MixBlend.first: color.add((setup.r - color.r) * alpha, (setup.g - color.g) * alpha, (setup.b - color.b) * alpha, case MixBlend.first: color.add((setup.r - color.r) * alpha, (setup.g - color.g) * alpha, (setup.b - color.b) * alpha,
(setup.a - color.a) * alpha); break; (setup.a - color.a) * alpha); break;
} }
return; return;
} }
@ -1228,7 +1228,7 @@ export class RGBA2Timeline extends SlotCurveTimeline {
} }
/** Changes a slot's {@link SlotPose.color} and {@link SlotPose.darkColor} for two color tinting. */ /** Changes a slot's {@link SlotPose.color} and {@link SlotPose.darkColor} for two color tinting. */
export class RGB2Timeline extends SlotCurveTimeline { export class RGB2Timeline extends SlotCurveTimeline {
constructor (frameCount: number, bezierCount: number, slotIndex: number) { constructor (frameCount: number, bezierCount: number, slotIndex: number) {
super(frameCount, bezierCount, slotIndex, // super(frameCount, bezierCount, slotIndex, //
Property.rgb + "|" + slotIndex, // Property.rgb + "|" + slotIndex, //
@ -1826,7 +1826,7 @@ export interface ConstraintTimeline {
readonly constraintIndex: number; readonly constraintIndex: number;
} }
export function isConstraintTimeline(obj: any): obj is ConstraintTimeline { export function isConstraintTimeline (obj: any): obj is ConstraintTimeline {
return typeof obj === 'object' && obj !== null && typeof obj.constraintIndex === 'number'; return typeof obj === 'object' && obj !== null && typeof obj.constraintIndex === 'number';
} }
@ -2103,11 +2103,11 @@ export class PathConstraintSpacingTimeline extends ConstraintTimeline1 {
apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, blend: MixBlend, apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, blend: MixBlend,
direction: MixDirection, appliedPose: boolean) { direction: MixDirection, appliedPose: boolean) {
const constraint = skeleton.constraints[this.constraintIndex]; const constraint = skeleton.constraints[this.constraintIndex];
if (constraint.active) { if (constraint.active) {
const pose = appliedPose ? constraint.applied : constraint.pose; const pose = appliedPose ? constraint.applied : constraint.pose;
pose.spacing = this.getAbsoluteValue(time, alpha, blend, pose.spacing, constraint.data.setup.spacing); pose.spacing = this.getAbsoluteValue(time, alpha, blend, pose.spacing, constraint.data.setup.spacing);
} }
} }
} }

View File

@ -73,9 +73,9 @@ export class BoneLocal implements Pose<BoneLocal> {
this.y = y; this.y = y;
} }
setScale(scaleX: number, scaleY: number): void; setScale (scaleX: number, scaleY: number): void;
setScale(scale: number): void; setScale (scale: number): void;
setScale(scaleOrX: number, scaleY?: number): void { setScale (scaleOrX: number, scaleY?: number): void {
this.scaleX = scaleOrX; this.scaleX = scaleOrX;
this.scaleY = scaleY === undefined ? scaleOrX : scaleY; this.scaleY = scaleY === undefined ? scaleOrX : scaleY;
} }

View File

@ -280,19 +280,19 @@ export class BonePose extends BoneLocal implements Update {
if (this.local === skeleton._update) this.updateLocalTransform(skeleton); if (this.local === skeleton._update) this.updateLocalTransform(skeleton);
} }
modifyLocal (skeleton: Skeleton): void { modifyLocal (skeleton: Skeleton): void {
if (this.local === skeleton._update) this.updateLocalTransform(skeleton); if (this.local === skeleton._update) this.updateLocalTransform(skeleton);
this.world = 0; this.world = 0;
this.resetWorld(skeleton._update); this.resetWorld(skeleton._update);
} }
modifyWorld (update: number): void { modifyWorld (update: number): void {
this.local = update; this.local = update;
this.world = update; this.world = update;
this.resetWorld(update); this.resetWorld(update);
} }
resetWorld (update: number): void { resetWorld (update: number): void {
const children = this.bone.children; const children = this.bone.children;
for (let i = 0, n = children.length; i < n; i++) { for (let i = 0, n = children.length; i < n; i++) {
const child = children[i].applied; const child = children[i].applied;

View File

@ -110,7 +110,7 @@ export class IkConstraint extends Constraint<IkConstraint, IkConstraintData, IkC
this.apply1(skeleton, boneOrParent, targetXorChild, targetYOrTargetX, compressOrTargetY as boolean, stretchOrBendDir as boolean, uniformOrStretch, mixOrUniform as number); this.apply1(skeleton, boneOrParent, targetXorChild, targetYOrTargetX, compressOrTargetY as boolean, stretchOrBendDir as boolean, uniformOrStretch, mixOrUniform as number);
else else
this.apply2(skeleton, boneOrParent, targetXorChild as BonePose, targetYOrTargetX, compressOrTargetY as number, stretchOrBendDir as number, this.apply2(skeleton, boneOrParent, targetXorChild as BonePose, targetYOrTargetX, compressOrTargetY as number, stretchOrBendDir as number,
uniformOrStretch, mixOrUniform as boolean, softness as number, mix as number); uniformOrStretch, mixOrUniform as boolean, softness as number, mix as number);
} }
private static apply1 (skeleton: Skeleton, bone: BonePose, targetX: number, targetY: number, compress: boolean, stretch: boolean, uniform: boolean, mix: number) { private static apply1 (skeleton: Skeleton, bone: BonePose, targetX: number, targetY: number, compress: boolean, stretch: boolean, uniform: boolean, mix: number) {

View File

@ -46,7 +46,7 @@ export class PathConstraintData extends ConstraintData<PathConstraint, PathConst
public set slot (slotData: SlotData) { this._slot = slotData; } public set slot (slotData: SlotData) { this._slot = slotData; }
public get slot () { public get slot () {
if (!this._slot) throw new Error("SlotData not set.") if (!this._slot) throw new Error("SlotData not set.")
else return this._slot; else return this._slot;
} }
private _slot: SlotData | null = null; private _slot: SlotData | null = null;

View File

@ -127,7 +127,7 @@ export class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsCons
return; return;
case Physics.reset: case Physics.reset:
this.reset(skeleton); this.reset(skeleton);
// Fall through. // Fall through.
case Physics.update: case Physics.update:
const delta = Math.max(skeleton.time - this.lastTime, 0), aa = this.remaining; const delta = Math.max(skeleton.time - this.lastTime, 0), aa = this.remaining;
this.remaining += delta; this.remaining += delta;

View File

@ -42,7 +42,7 @@ export class PhysicsConstraintData extends ConstraintData<PhysicsConstraint, Phy
public set bone (boneData: BoneData) { this._bone = boneData; } public set bone (boneData: BoneData) { this._bone = boneData; }
public get bone () { public get bone () {
if (!this._bone) throw new Error("BoneData not set.") if (!this._bone) throw new Error("BoneData not set.")
else return this._bone; else return this._bone;
} }
private _bone: BoneData | null = null; private _bone: BoneData | null = null;

View File

@ -243,7 +243,7 @@ export class Skeleton {
* <p> * <p>
* See <a href="https://esotericsoftware.com/spine-runtime-skeletons#World-transforms">World transforms</a> in the Spine * See <a href="https://esotericsoftware.com/spine-runtime-skeletons#World-transforms">World transforms</a> in the Spine
* Runtimes Guide. */ * Runtimes Guide. */
updateWorldTransform(physics: Physics): void { updateWorldTransform (physics: Physics): void {
this._update++; this._update++;
const resetCache = this.resetCache; const resetCache = this.resetCache;

View File

@ -46,7 +46,7 @@ export class TransformConstraintData extends ConstraintData<TransformConstraint,
public set source (source: BoneData) { this._source = source; } public set source (source: BoneData) { this._source = source; }
public get source () { public get source () {
if (!this._source) throw new Error("BoneData not set.") if (!this._source) throw new Error("BoneData not set.")
else return this._source; else return this._source;
} }
private _source: BoneData | null = null; private _source: BoneData | null = null;