UNPKG

@drincs/pixi-vn

Version:

Pixi'VN is a npm package that provides various features for creating visual novels.

445 lines (428 loc) 15.1 kB
import { UPDATE_PRIORITY, Ticker as Ticker$1 } from 'pixi.js'; import { T as TickerArgs, d as TickerIdType } from '../../TickersSequence-_GvVF_1g.cjs'; export { a as TickerHistory, b as TickerHistoryForExport, c as TickersSequence } from '../../TickersSequence-_GvVF_1g.cjs'; interface Ticker<TArgs extends TickerArgs> { /** * 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 RegisteredTickers.getInstance} */ id: TickerIdType; } type TickerValue = Ticker$1; /** * A class is used to create a ticker element to add into a Pixi Application. * You can use {@link canvas.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: TickerValue, // the ticker that is calling this method * args: { // the arguments that you passed when you added the ticker * speed?: number, * }, * aliases: string[], // the aliases 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 canvas.currentTickers * ): void { * let speed = args.speed === undefined ? 0.1 : args.speed * aliases.forEach((alias) => { * let element = canvas.find(alias) * if (element && element instanceof Container) { * if (clockwise) * element.rotation += speed * t.deltaTime * else * element.rotation -= speed * t.deltaTime * } * }) * } * } * ``` */ declare class TickerBase<TArgs extends TickerArgs> implements Ticker<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 RegisteredTickers.getInstance} */ 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 {@link canvas.add()} 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 _alias The alias 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 canvas.currentTickers} */ fn(_ticker: TickerValue, _args: TArgs, _alias: string | string[], _tickerId: string): void; /** * This method is called when the ticker is added to the canvas. * @param alias The alias 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 canvas.currentTickers} * @param options The options that you passed when you added the ticker */ onEndOfTicker(_alias: string | string[], tickerId: string, args: TArgs): void; } type TickerProgrationType = TickerProgrationLinear | TickerProgrationExponential; interface TickerProgrationLinear { /** * The amount of the speed to increase every frame. */ amt: number; /** * The limit of the effect */ limit?: number; type: "linear"; } interface TickerProgrationExponential { /** * The percentage of the speed to increase every frame. if the percentage is 0.1, the speed will increase by 10% every frame. */ percentage: number; /** * The limit of the effect */ limit?: number; type: "exponential"; } type FadeAlphaTickerProps = { /** * @deprecated use speed instead * @default 1 */ duration?: number; /** * The speed of the effect (1 alpha per 10 second) * @default 5 */ speed?: number; /** * The type of the fade * @default "hide" */ type?: "hide" | "show"; /** * The limit of the fade * @default type === "hide" ? 0 : 1 */ limit?: number; /** * The progression of the speed */ speedProgression?: TickerProgrationType; /** * The alias to remove after the fade is done * @default [] */ aliasToRemoveAfter?: string[] | string; /** * If true, the effect only starts if the canvas element have a texture * @default false */ startOnlyIfHaveTexture?: boolean; /** * The alias to resume after the effect is done * @default [] */ tickerAliasToResume?: string[] | string; }; /** * A ticker that fades the alpha of the canvas element of the canvas. * This ticker can be used on all canvas elements that extend the {@link PixiContainer} class. * @example * ```typescript * let bunny = addImage("bunny1", "https://pixijs.com/assets/eggHead.png") * await bunny.load() * canvas.add("bunny", bunny); * // ... * const ticker = new FadeAlphaTicker({ * duration: 4, // 4 seconds * type: "hide", * }), * canvas.addTicker("bunny", ticker) * ``` */ declare class FadeAlphaTicker extends TickerBase<FadeAlphaTickerProps> { constructor(args?: FadeAlphaTickerProps, duration?: number, priority?: UPDATE_PRIORITY); fn(ticker: TickerValue, args: FadeAlphaTickerProps, aliases: string[], tickerId: string): void; onEndOfTicker(alias: string | string[], tickerId: string, args: FadeAlphaTickerProps, options?: { editAlpha?: boolean; }): void; private getLimit; private speedConvert; } type MoveTickerProps = { /** * The speed of the movement (1 pixels per 0.1 second) * @default 10 */ speed?: number | { x: number; y: number; }; /** * The destination of the movement */ destination: { /** * The type of the destination. Possible values are "pixel", "percentage" and "align": * - "pixel": The destination is in pixel * - "percentage": The destination is in percentage * - "align": The destination is in align * @default "pixel" */ type?: "pixel" | "percentage" | "align"; y: number; x: number; }; /** * The progression of the speed */ speedProgression?: TickerProgrationType; /** * The alias to remove after the fade is done * @default [] */ aliasToRemoveAfter?: string[] | string; /** * If true, the effect only starts if the canvas element have a texture * @default false */ startOnlyIfHaveTexture?: boolean; /** * The alias to resume after the effect is done * @default [] */ tickerAliasToResume?: string[] | string; }; /** * A ticker that moves the canvas element of the canvas. * This ticker can be used on all canvas elements that extend the {@link PixiContainer} class. * @example * ```typescript * let alien = addImage("alien", 'https://pixijs.com/assets/eggHead.png') * canvas.add("alien", alien); * const ticker = new MoveTicker({ * speed: 0.1, * destination: { x: 100, y: 100 }, * }), * ``` */ declare class MoveTicker extends TickerBase<MoveTickerProps> { fn(ticker: TickerValue, args: MoveTickerProps, aliases: string[], tickerId: string): void; onEndOfTicker(alias: string | string[], tickerId: string, args: MoveTickerProps, options?: { editPosition: boolean; }): void; private speedConvert; } /** * A ticker that rotates the canvas element of the canvas. For centre rotation, set the anchor of the canvas element to 0.5. * This ticker can be used on all canvas elements that extend the {@link PixiContainer} class. * @example * ```typescript * let alien = addImage("alien", 'https://pixijs.com/assets/eggHead.png') * alien.anchor.set(0.5); * canvas.add("alien", alien); * const ticker = new RotateTicker({ * speed: 0.1, * clockwise: true, * }), * canvas.addTicker("alien", ticker) * ``` */ declare class RotateTicker extends TickerBase<RotateTickerProps> { constructor(args?: RotateTickerProps, duration?: number, priority?: UPDATE_PRIORITY); fn(ticker: TickerValue, args: RotateTickerProps, aliases: string[], tickerId: string): void; onEndOfTicker(alias: string | string[], tickerId: string, args: RotateTickerProps, options?: { editRotation?: boolean; }): void; private speedConvert; } /** * A ticker that zooms the canvas element of the canvas. * This ticker can be used on all canvas elements that extend the {@link PixiContainer} class. * @example * ```typescript * let alien = addImage("alien", 'https://pixijs.com/assets/eggHead.png') * alien.anchor.set(0.5); * canvas.add("alien", alien); * const ticker = new ZoomTicker({ * speed: 0.1, * }), * canvas.addTicker("alien", ticker) * ``` */ declare class ZoomTicker extends TickerBase<ZoomTickerProps> { constructor(args?: ZoomTickerProps, duration?: number, priority?: UPDATE_PRIORITY); fn(ticker: TickerValue, args: ZoomTickerProps, alias: string[], tickerId: string): void; private speedConvert; onEndOfTicker(alias: string | string[], tickerId: string, args: ZoomTickerProps, options?: { editScale?: boolean; }): void; private getLimit; } /** * Is a decorator that register a ticker in the game. * Is a required decorator for use the ticker in the game. * Thanks to this decoration the game has the possibility of updating the tickers to the latest modification and saving the game. * @param name is th identifier of the label, by default is the name of the class * @returns */ declare function tickerDecorator(name?: TickerIdType): (target: typeof TickerBase<any>) => void; declare namespace RegisteredTickers { /** * Register a ticker in the game. * @param target The class of the ticker. * @param name Name of the ticker, by default it will use the class name. If the name is already registered, it will show a warning */ function add(target: typeof TickerBase<any>, name?: TickerIdType): void; /** * Get a ticker by the id. * @param canvasId The id of the ticker. * @returns The ticker type. */ function get<T = typeof TickerBase<any>>(tickerId: TickerIdType): T | undefined; /** * Get a ticker instance by the id. * @param tickerId The id of the ticker. * @param args The arguments that you want to pass to the ticker. * @param duration The duration of the ticker. If is undefined, the ticker will be called every frame. * @param priority The priority of the ticker. If is undefined, the priority will be UPDATE_PRIORITY.NORMAL. * @returns The instance of the ticker */ function getInstance<TArgs extends TickerArgs>(tickerId: TickerIdType, args: TArgs, duration?: number, priority?: UPDATE_PRIORITY): TickerBase<TArgs> | undefined; /** * Get a list of all tickers registered. * @returns An array of tickers. */ function values(): (typeof TickerBase<any>)[]; /** * Check if a ticker is registered. * @param id The id of the ticker. * @returns True if the ticker is registered, false otherwise. */ function has(id: string): boolean; } interface TickerTimeoutHistory { aliases: string[]; ticker: string; canBeDeletedBeforeEnd: boolean; } type RotateTickerProps = { /** * The speed of the rotation (360 degree per 10 second) * @default 1 */ speed?: number; /** * The direction of the rotation * @default true */ clockwise?: boolean; /** * The limit of the rotation, is specified in degree * @default undefined */ limit?: number; /** * The progression of the speed */ speedProgression?: TickerProgrationType; /** * The alias to remove after the fade is done * @default [] */ aliasToRemoveAfter?: string[] | string; /** * If true, the effect only starts if the canvas element have a texture * @default false */ startOnlyIfHaveTexture?: boolean; /** * The alias to resume after the effect is done * @default [] */ tickerAliasToResume?: string[] | string; }; type ZoomTickerProps = { /** * The speed of the zoom effect (100% zoom per 10 second) * @default 10 */ speed?: number | { x: number; y: number; }; /** * The type of the zoom effect * @default "zoom" */ type?: "zoom" | "unzoom"; /** * The limit of the effect * @default type === "zoom" ? Infinity : 0 */ limit?: number | { x: number; y: number; }; /** * The progression of the speed. * There are two types of progression: linear and exponential. * - Linear: The speed will increase by the amount of `amt` every frame. * - Exponential: The speed will increase by the percentage of the current speed every frame. * @default undefined */ speedProgression?: TickerProgrationType; /** * The alias to remove after the effect is done * @default [] */ aliasToRemoveAfter?: string[] | string; /** * If true, the effect only starts if the canvas element have a texture * @default false */ startOnlyIfHaveTexture?: boolean; /** * The alias to resume after the effect is done * @default [] */ tickerAliasToResume?: string[] | string; /** * Is a special prop used in the zoom in/out transition. * @default false */ isZoomInOut?: { pivot: { x: number; y: number; }; position: { x: number; y: number; }; }; }; export { FadeAlphaTicker, type FadeAlphaTickerProps, MoveTicker, type MoveTickerProps, RegisteredTickers, RotateTicker, type RotateTickerProps, type Ticker, TickerArgs, TickerBase, type TickerProgrationExponential, type TickerProgrationLinear, type TickerProgrationType, type TickerTimeoutHistory, type TickerValue, ZoomTicker, type ZoomTickerProps, tickerDecorator };