129 lines
4.3 KiB
TypeScript
129 lines
4.3 KiB
TypeScript
import { ClientRemoteObject, RemoteClient } from 'jibo-client-framework';
|
|
import { Event, EventContainer } from 'jibo-typed-events';
|
|
import { PlayStatus } from 'jibo-common-types';
|
|
import { DOFSet } from 'animation-utilities';
|
|
/**
|
|
* @description Enum of animation states
|
|
* @typedef AnimationState
|
|
* @prop INVALID
|
|
* @prop PLAYING
|
|
* @prop STOPPED
|
|
* @prop STOPPING
|
|
* @prop CANCELLED
|
|
* @prop PAUSED
|
|
* @prop RESUMED
|
|
* @prop STARTED
|
|
* @prop REJECTED
|
|
*/
|
|
export declare enum AnimationState {
|
|
INVALID = "INVALID",
|
|
PLAYING = "PLAYING",
|
|
STOPPED = "STOPPED",
|
|
STOPPING = "STOPPING",
|
|
CANCELLED = "CANCELLED",
|
|
PAUSED = "PAUSED",
|
|
RESUMED = "RESUMED",
|
|
STARTED = "STARTED",
|
|
REJECTED = "REJECTED",
|
|
}
|
|
/**
|
|
* @interface AnimationInstanceEvents
|
|
* @description Typed Events for an `AnimationInstance`.
|
|
* @prop {Event<Object>} general Emits when any other event occurs. Passes in an object with
|
|
* a `name` property, which is the event name, and a `payload`
|
|
* property, which is the payload of the event.
|
|
* @prop {Event<Object>} audio Emits when animation encounters an audio event. Passes in an
|
|
* object with a `file` property.
|
|
* @prop {Event<Object>} pixi Emits when animation encounters a pixi event. Passes in an
|
|
* object with a `file` property.
|
|
* @prop {Event<void>} holdSafe Emits when the animation encounters a "HOLD_SAFE" event.
|
|
* @prop {Event<void>} stopped Emits when the animation stops. Usually use the resolution of `play`
|
|
* to determine when this happens.
|
|
* @prop {Event<void>} started Emits when the animation starts.
|
|
* @prop {Event<void>} cancelled Emits when the animation is canceled by a higher priority system.
|
|
* @prop {Event<void>} rejected Emits when the animation is is rejected since a higher priority
|
|
* animation is currently playing.
|
|
*/
|
|
export declare class AnimationEvents extends EventContainer {
|
|
general: Event<{
|
|
name: string;
|
|
payload: any;
|
|
}>;
|
|
audio: Event<{
|
|
file: string;
|
|
}>;
|
|
pixi: Event<{
|
|
file: string;
|
|
layerNum: number;
|
|
attach: boolean;
|
|
offset: string;
|
|
}>;
|
|
holdSafe: Event<void>;
|
|
stopped: Event<void>;
|
|
cancelled: Event<void>;
|
|
rejected: Event<void>;
|
|
started: Event<void>;
|
|
stateChange: Event<AnimationState>;
|
|
}
|
|
/**
|
|
* Handle to an animation instance. Can only be played *once*.
|
|
* @class AnimationInstance
|
|
*/
|
|
export declare class AnimationInstance extends ClientRemoteObject {
|
|
protected client: RemoteClient;
|
|
id: string;
|
|
dofs: DOFSet;
|
|
/**
|
|
* Set of animation event emitters.
|
|
* @type {AnimationInstanceEvents}
|
|
* @name AnimationInstance#events
|
|
*/
|
|
events: AnimationEvents;
|
|
AnimationState: typeof AnimationState;
|
|
/**
|
|
* Current state of the animation.
|
|
* @type {AnimationState}
|
|
* @name AnimationInstance#state
|
|
*/
|
|
state: AnimationState;
|
|
private played;
|
|
/**
|
|
* Set of dofs this animation acts on.
|
|
* @type {DOFSet}
|
|
* @name AnimationInstance#dofs
|
|
*/
|
|
constructor(client: RemoteClient, instanceId: number, id: string, dofs: DOFSet, didPlay?: boolean);
|
|
/**
|
|
* Plays this animation on the robot.
|
|
* @param {string} [requestor='Behavior'] The system making the animation request.
|
|
* @returns {Promise<PlayStatus>} Resolves when the animation is finished playing or is canceled.
|
|
* @method AnimationInstance#play
|
|
*/
|
|
play(requestor?: string): Promise<PlayStatus>;
|
|
/**
|
|
* Stops this animation if it is running.
|
|
* @returns {Promise<void>} Resolves when the animation is stopped.
|
|
* @method AnimationInstance#stop
|
|
*/
|
|
stop(): Promise<void>;
|
|
/**
|
|
* Pauses this animation if it is running.
|
|
* @returns {Promise<void>} Resolves when the animation is paused.
|
|
* @method AnimationInstance#pause
|
|
*/
|
|
pause(): Promise<void>;
|
|
/**
|
|
* Resumes this animation if it is paused.
|
|
* @returns {Promise<void>} Resolves when the animation is resumed.
|
|
* @method AnimationInstance#resume
|
|
*/
|
|
resume(): Promise<void>;
|
|
/**
|
|
* Removes all event listensers and
|
|
* @method AnimationInstance#destroy
|
|
*/
|
|
destroy(): void;
|
|
private setState(newState);
|
|
private onEvent(eventName, payload);
|
|
}
|