Skip to content

Commit

Permalink
Merge pull request #407 from liamf1986/wip-interfaces-
Browse files Browse the repository at this point in the history
Interface integration
  • Loading branch information
ivanpopelyshev authored Aug 24, 2021
2 parents a47dc9a + 8ce27d6 commit 54d7129
Show file tree
Hide file tree
Showing 44 changed files with 376 additions and 381 deletions.
2 changes: 2 additions & 0 deletions packages/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"@pixi/math": "^6.1.0",
"@pixi/mesh": "^6.1.0",
"@pixi/mesh-extras": "^6.1.0",
"@pixi/runner": "^6.1.0",
"@pixi/settings": "^6.1.0",
"@pixi/sprite": "^6.1.0",
"@pixi/utils": "^6.1.0"
},
Expand Down
4 changes: 3 additions & 1 deletion packages/base/src/SpineBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {TextureAtlasRegion} from './core/TextureAtlas';
import {MathUtils} from './core/Utils';
import type {
IAnimationState,
IAnimationStateData,
IAnimationStateData
} from './core/IAnimation';
import type {
IAttachment, IClippingAttachment, IMeshAttachment,
IRegionAttachment,
ISkeleton,
Expand Down
136 changes: 136 additions & 0 deletions packages/base/src/core/IAnimation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import {ISkeleton, ISkeletonData} from './ISkeleton';
import type {Map} from './Utils';

// Those enums were moved from Animation.ts of spine 3.8 and 4.0

/** Controls how a timeline value is mixed with the setup pose value or current pose value when a timeline's `alpha`
* < 1.
*
* See Timeline {@link Timeline#apply(Skeleton, float, float, Array, float, MixBlend, MixDirection)}.
* @public
* */
export enum MixBlend {
/** Transitions from the setup value to the timeline value (the current value is not used). Before the first key, the setup
* value is set. */
setup,
/** Transitions from the current value to the timeline value. Before the first key, transitions from the current value to
* the setup value. Timelines which perform instant transitions, such as DrawOrderTimeline or
* AttachmentTimeline, use the setup value before the first key.
*
* `first` is intended for the first animations applied, not for animations layered on top of those. */
first,
/** Transitions from the current value to the timeline value. No change is made before the first key (the current value is
* kept until the first key).
*
* `replace` is intended for animations layered on top of others, not for the first animations applied. */
replace,
/** Transitions from the current value to the current value plus the timeline value. No change is made before the first key
* (the current value is kept until the first key).
*
* `add` is intended for animations layered on top of others, not for the first animations applied. Properties
* keyed by additive animations must be set manually or by another animation before applying the additive animations, else
* the property values will increase continually. */
add
}

/** Indicates whether a timeline's `alpha` is mixing out over time toward 0 (the setup or current pose value) or
* mixing in toward 1 (the timeline's value).
*
* See Timeline {@link Timeline#apply(Skeleton, float, float, Array, float, MixBlend, MixDirection)}.
* @public
* */
export enum MixDirection {
mixIn, mixOut
}

/**
* @public
*/
export interface IAnimation<Timeline extends ITimeline = ITimeline> {
name: string;
timelines: Timeline[];
duration: number;
}

/**
* @public
*/
export interface IAnimationState<AnimationStateData extends IAnimationStateData = IAnimationStateData> {
data: AnimationStateData;
tracks: ITrackEntry[];
listeners: IAnimationStateListener[];
timeScale: number;

update(dt: number): void;
apply(skeleton: ISkeleton): boolean;

setAnimation (trackIndex: number, animationName: string, loop: boolean): ITrackEntry;
addAnimation (trackIndex: number, animationName: string, loop: boolean, delay: number): ITrackEntry;
addEmptyAnimation (trackIndex: number, mixDuration: number, delay: number): ITrackEntry;
setEmptyAnimation (trackIndex: number, mixDuration: number): ITrackEntry;
setEmptyAnimations (mixDuration: number): void;
hasAnimation(animationName: string): boolean;
addListener (listener: IAnimationStateListener): void;
removeListener (listener: IAnimationStateListener): void;
clearListeners (): void;
clearTracks (): void;
clearTrack (index: number): void;
}

/**
* @public
*/
export interface IAnimationStateData<SkeletonData extends ISkeletonData = ISkeletonData, Animation extends IAnimation = IAnimation> {
skeletonData: SkeletonData;
animationToMixTime: Map<number>;
defaultMix: number;
setMix (fromName: string, toName: string, duration: number): void;
setMixWith (from: Animation, to: Animation, duration: number): void;
getMix (from: Animation, to: Animation): number;
}

/**
* @public
*/
export interface IAnimationStateListener {
start? (entry: ITrackEntry): void;
interrupt? (entry: ITrackEntry): void;
end? (entry: ITrackEntry): void;
dispose? (entry: ITrackEntry): void;
complete? (entry: ITrackEntry): void;
event? (entry: ITrackEntry, event: IEvent): void;
}

/**
* @public
*/
export interface ITimeline {
}

/**
* @public
*/
export interface ITrackEntry {
trackIndex: number;
loop: boolean;
animationEnd: number;
listener: IAnimationStateListener;

delay: number; trackTime: number; trackLast: number; nextTrackLast: number; trackEnd: number; timeScale: number;
alpha: number; mixTime: number; mixDuration: number; interruptAlpha: number; totalAlpha: number;
}

/**
* @public
*/
export interface IEventData {
name: string;
}

/**
* @public
*/
export interface IEvent {
time: number;
data: IEventData;
}
104 changes: 104 additions & 0 deletions packages/base/src/core/IConstraint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@

// These enums were moved from PathConstraintData.ts of spine 3.7, 3.8 and 4.0

/** 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.
* @public
* */
export enum PositionMode {
Fixed, Percent
}

/** 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.
* @public
* */
export enum RotateMode {
Tangent, Chain, ChainScale
}

/**
* @public
*/
export interface IConstraintData {
name: string;
order: number;
}

/**
* @public
*/
export interface IIkConstraint {
data: IIkConstraintData;
/** -1 | 0 | 1 */
bendDirection: number;
compress: boolean;
stretch: boolean;

/** A percentage (0-1) */
mix: number;
}

/**
* @public
*/
export interface IIkConstraintData extends IConstraintData {
/** -1 | 0 | 1 */
bendDirection: number;
compress: boolean;
stretch: boolean;
uniform: boolean;

/** A percentage (0-1) */
mix: number;
}

/**
* @public
*/
export interface IPathConstraint {
data: IPathConstraintData;
position: number;
spacing: number;

spaces: number[];
positions: number[];
world: number[];
curves: number[];
lengths: number[];
segments: number[];
}

/**
* @public
*/
export interface IPathConstraintData extends IConstraintData {
positionMode: PositionMode;
rotateMode: RotateMode;
offsetRotation: number;
position: number;
spacing: number;
}

/**
* @public
*/
export interface ITransformConstraint {
data: ITransformConstraintData;
}

/**
* @public
*/
export interface ITransformConstraintData extends IConstraintData {
offsetRotation: number;
offsetX: number;
offsetY: number;
offsetScaleX: number;
offsetScaleY: number;
offsetShearY: number;
relative: boolean;
local: boolean;
}
Loading

0 comments on commit 54d7129

Please sign in to comment.