@drincs/pixi-vn
Version:
Pixi'VN is a npm package that provides various features for creating visual novels.
88 lines (84 loc) • 3.78 kB
TypeScript
import { UPDATE_PRIORITY, Ticker } from 'pixi.js';
import { StorageElementType } from './types/StorageElementType.js';
import { TickerIdType } from './types/TickerIdType.js';
interface ITicker<TArgs extends TickerArgsType> {
/**
* Arguments to pass to the ticker
*/
args: TArgs;
/**
* Duration in seconds to run the ticker
*/
duration?: number;
/**
* Priority of the ticker
*/
priority?: UPDATE_PRIORITY;
/**
* Get the id of the ticker. This variable is used in the system to get the ticker by id, {@link geTickerInstanceById}
*/
id: TickerIdType;
}
type TickerArgsType = {
[id: string]: StorageElementType;
} | {
tagToRemoveAfter?: string[] | string;
[id: string]: StorageElementType;
}[];
/**
* A class is used to create a ticker element to add into a Pixi Application.
* You can use GameWindowManager.addTicker() to add this element into the application.
* This class should be extended and the fn method should be overridden.
* You must use the {@link tickerDecorator} to register the ticker in the game.
* In Ren'Py is a transform.
* @example
* ```typescript
* \@tickerDecorator() // this is equivalent to tickerDecorator("RotateTicker")
* export class RotateTicker extends TickerBase<{ speed?: number }> {
* override fn(
* t: Ticker, // the ticker that is calling this method
* args: { // the arguments that you passed when you added the ticker
* speed?: number,
* },
* tags: string[], // the tags of the canvas elements that are connected to this ticker
* tickerId: string, // the id of the ticker. You can use this to get the ticker from the GameWindowManager.currentTickers
* ): void {
* let speed = args.speed === undefined ? 0.1 : args.speed
* tags.forEach((tag) => {
* let element = GameWindowManager.getCanvasElement(tag)
* if (element && element instanceof Container) {
* if (clockwise)
* element.rotation += speed * t.deltaTime
* else
* element.rotation -= speed * t.deltaTime
* }
* })
* }
* }
* ```
*/
declare class TickerBase<TArgs extends TickerArgsType> implements ITicker<TArgs> {
/**
* @param args The arguments that you want to pass to the ticker.
* @param duration The duration of the ticker in seconds. If is undefined, the step will end only when the animation is finished (if the animation doesn't have a goal to reach then it won't finish). @default undefined
* @param priority The priority of the ticker. @default UPDATE_PRIORITY.NORMAL
*/
constructor(args: TArgs, duration?: number, priority?: UPDATE_PRIORITY);
/**
* Get the id of the ticker. This variable is used in the system to get the ticker by id, {@link geTickerInstanceById}
*/
id: TickerIdType;
args: TArgs;
duration?: number;
priority?: UPDATE_PRIORITY;
/**
* The method that will be called every frame.
* This method should be overridden and you can use GameWindowManager.addCanvasElement() to get the canvas element of the canvas, and edit them.
* @param _ticker The ticker that is calling this method
* @param _args The arguments that you passed when you added the ticker
* @param _tags The tags of the canvas elements that are connected to this ticker
* @param _tickerId The id of the ticker. You can use this to get the ticker from the {@link GameWindowManager.currentTickers}
*/
fn(_ticker: Ticker, _args: TArgs, _tags: string | string[], _tickerId: string): void;
}
export { type ITicker as I, TickerBase as T, type TickerArgsType as a };