Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expanding types to closer match runtimes #404

Merged
merged 2 commits into from
Aug 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions packages/base/src/core/ISkeleton.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {AttachmentType} from './AttachmentType';
import type {Color, Vector2} from './Utils';
import type {Color, Vector2, Map} from './Utils';
import type {TextureRegion} from './TextureRegion';

import type {Matrix} from '@pixi/math';
Expand All @@ -12,6 +12,18 @@ export interface IBone {
matrix: Matrix;
}

/**
* @public
*/
export interface ISkin {
name: string;
attachments: Array<Map<IAttachment>>;

setAttachment (slotIndex: number, name: string, attachment: IAttachment): void;
getAttachment (slotIndex: number, name: string): IAttachment | null;
attachAll (skeleton: ISkeleton, oldSkin: ISkin): void;
}

/**
* @public
*/
Expand Down Expand Up @@ -93,17 +105,21 @@ export interface ISlot {
/**
* @public
*/
export interface ISkeleton<Bone extends IBone = IBone, Slot extends ISlot = ISlot> {
export interface ISkeleton<Bone extends IBone = IBone, Slot extends ISlot = ISlot, Skin extends ISkin = ISkin> {
bones: Bone[]
slots: Slot[]
drawOrder: Slot[]
skin: Skin;
data: ISkeletonData;
updateWorldTransform (): void;
setToSetupPose (): void;
findSlotIndex (slotName: string): number;
getAttachmentByName (slotName: string, attachmentName: string): IAttachment;

setBonesToSetupPose (): void;
setSlotsToSetupPose (): void;
findBone (boneName: string): Bone;
findSlot (slotName: string): Slot;
findBoneIndex (boneName: string): number;
findSlotIndex (slotName: string): number;
setSkinByName (skinName: string): void;
Expand All @@ -125,6 +141,10 @@ export interface ISkeletonData {
name: string;
version: string;
hash: string;
width: number;
height: number;

findSkin (skinName: string): ISkin | null;
}

/**
Expand All @@ -133,6 +153,8 @@ export interface ISkeletonData {
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;
Expand All @@ -142,16 +164,23 @@ export interface ITrackEntry {
* @public
*/
export interface IAnimationState {
tracks: ITrackEntry;
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);
removeListener (listener: IAnimationStateListener);
addListener (listener: IAnimationStateListener): void;
removeListener (listener: IAnimationStateListener): void;
clearListeners (): void;
clearTracks (): void;
clearTrack (index: number): void;
}

/**
Expand Down