@dill-pixel/plugin-rive
Version:
Rive
192 lines • 7.33 kB
TypeScript
import { Artboard, LinearAnimationInstance, RiveCanvas, SMIInput, StateMachineInstance } from '../node_modules/@rive-app/canvas-advanced-lite/rive_advanced.mjs.d.ts';
import { Container, Signal } from 'dill-pixel';
import { FederatedPointerEvent, Sprite, Ticker } from 'pixi.js';
import { RivePlugin } from './RivePlugin';
import { Alignment, Fit, RiveOptions } from './types';
declare const RiveEntity_base: typeof Container & import('dill-pixel').Constructor<import('dill-pixel').ISignalContainer>;
/**
* @see https://www.npmjs.com/package/pixi-rive
* RiveEntity component extended from Dill Pixel Container
* PIXI.Assets.add({ alias: 'vehicles', src: 'https://cdn.rive.app/animations/vehicles.riv' });
* const vehicles = new RiveEntity({ asset: 'vehicles', autoPlay: true });
* app.stage.addChild(vehicles);
*
* @param {Artboard} artboard current Rive Artboard instance
* @param {LinearAnimationInstance} animations current Animation instances
* @param {StateMachineInstance} stateMachines current Rive State Machine instances
* @param {Map<string, SMIInput>} inputFields current artboard input fields from all state machines
* @param {Function} onStateChange callback method for catching state machines changes
* @param {Fit} fit fit Rive component into container sizes (Contain by default)
* @param {Alignment} align align Rive component in container (Center by default)
* @param {number} maxWidth max width of sprite (original Rive artboard size will be used if maxWidth is not set)
* @param {number} maxHeight max height of sprite (original Rive artboard size will be used if maxHeight is not set)
*/
export declare class RiveEntity extends RiveEntity_base {
options: RiveOptions;
onStateChange: Signal<(states?: any) => void>;
onReady: Signal<(rive?: RiveCanvas) => void>;
onPlay: Signal<(animations: string | string[]) => void>;
onStop: Signal<(animations: string | string[]) => void>;
onPause: Signal<() => void>;
onResume: Signal<() => void>;
animations: LinearAnimationInstance[];
stateMachines: StateMachineInstance[];
inputFields: Map<string, SMIInput>;
artboard?: Artboard;
private _debug;
private _file?;
private _aligned?;
private _renderer?;
private _canvas?;
private _paused;
private _enabled;
/**
* Constructor will load Rive wasm if it not loaded yet
* and create instances of Rive scene components (artboard, animation, stateMachine)
* after initialize will call onReady method and run animation if autoPlay was setted
* @param {RiveOptions} options initial component options
*/
constructor(options: RiveOptions);
private _align;
get align(): Alignment;
set align(value: Alignment);
private _fit;
get fit(): Fit;
set fit(value: Fit);
private _maxWidth;
get maxWidth(): number;
set maxWidth(value: number);
private _maxHeight;
get maxHeight(): number;
set maxHeight(value: number);
private _rive?;
get rive(): RiveCanvas;
private _view;
get view(): Sprite;
get plugin(): RivePlugin;
initialize(): Promise<void>;
/**
* Enable rive scene animation
*/
enable(): void;
/**
* Disable rive scene animation
*/
disable(): void;
/**
* Load Rive scene artboard by name or load default artboard if name is not set
* Rive should be initialized before (RiveOptions.onReady was emited)
* @param {string|number} artboard name of the loading artboard
*/
loadArtboard(artboard: string | undefined): void | Promise<void>;
/**
* Load Rive state machines by names or load first state machine
* Artbaord should be loaded before
* Will load first state machine if name is empty
* @param {string|number} machines name or names of the loading state machines
*/
loadStateMachine(machines?: string | string[]): void;
/**
* Unload state machine and destroy instance
* @param {string} name name of the state machine
*/
unloadStateMachine(name: string): void;
/**
* Play Rive animation by name (artbaord should be loaded before)
* You can play only one timeline animation at the same time.
* If animation is looped or it's a pingpong, it will be repeated endlessly
* otherwise it plays only once
*
* TODO: add onStart/onEnd/onLoop methods for animation
*
* @param {string|number} animations animation name or array of nmaes
*/
playAnimation(animations?: string | string[]): void;
/**
* Stop current animation and destroy Rive animation instance
*/
stopAnimation(animations: string | string[]): void;
pause(): void;
resume(): void;
/**
* Get list of available artboards in current Rive file
*/
getAvailableArtboards(): string[];
/**
* Get list of available state machines in current artboard
*/
getAvailableStateMachines(): string[];
/**
* Get list of available animations in current artboard
*/
getAvailableAnimations(): string[];
/**
* Recalculate and update sizes of ofscreencanvas due to artboard size
* Artboard should be loaded before
*/
updateSize(): void;
/**
* Receive input fields from all active state machines
*/
initInputFields(): void;
/**
* Get state machine input field by name
* @param {string} name input field name
* @returns {number|boolean} value of the input field
*/
getInputValue(name: string): number | boolean | undefined;
/**
* Set state machine input field value by name
* @param {string} name of the input field
* @param {number|boolean} value of the input field
*/
setInput(name: string, value: number | boolean): void;
/**
* Trigger state machine input field
* @param {string} name of the trigger field
*/
fireTrigger(name: string): void;
/**
* Destroy all component resources
*/
destroy(): void;
update(ticker?: Ticker): void;
protected handlePointerdown(e: FederatedPointerEvent): void;
protected handlePointerup(e: FederatedPointerEvent): void;
protected handlePointermove(e: FederatedPointerEvent): void;
private _destroyInternals;
/**
* Will load wasm and rive sprite asset from assets library
* also create offscreen canvas and rive renderer
* @param riv
*/
private initRive;
/**
* Attach pointer events to the pixi sprite and pass them to the Rive state machine
* @param {boolean} interactive true if we need to attach pointer events to sprite
*/
private initEvents;
/**
* Convert global Pixi.js coordinates to Rive point coordinates
* @param {{x:number,y:number}} global point coordinates
* @returns
*/
private translatePoint;
/**
* Will create offscreen canvas
* In debug mode will create a regular canvas and display it over the page
*/
private createCanvas;
/**
* Play all state machines animations
* @param {number} elapsed time from last update
*/
private advanceStateMachines;
/**
* Play all scene animations
* @param {number} elapsed time from last update
*/
private advanceAnimations;
}
export {};
//# sourceMappingURL=RiveEntity.d.ts.map