UNPKG

@drincs/pixi-vn

Version:

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

280 lines (277 loc) 10.8 kB
import * as pixi_js from 'pixi.js'; import { Application, ApplicationOptions, Container } from 'pixi.js'; import CanvasBase from '../classes/canvas/CanvasBase.mjs'; import { a as TickerArgsType, T as TickerBase, I as ITicker } from '../TickerBase-DKYzbzro.mjs'; import { PauseType } from '../types/PauseType.mjs'; import { RepeatType } from '../types/RepeatType.mjs'; import ExportedCanvas from '../interface/export/ExportedCanvas.mjs'; import ITickersSteps from '../interface/ITickersSteps.mjs'; import TickerHistory from '../interface/TickerHistory.mjs'; import '../interface/canvas/ICanvasBaseMemory.mjs'; import '../types/StorageElementType.mjs'; import '../types/TickerIdType.mjs'; /** * This class is responsible for managing the canvas, the tickers, the events, and the window size and the children of the window. */ declare class GameWindowManager { private constructor(); private static _app; /** * The PIXI Application instance. * It not recommended to use this property directly. */ static get app(): Application<pixi_js.Renderer>; private static _isInitialized; /** * If the manager is initialized. */ static get isInitialized(): boolean; /** * This is the div that have same size of the canvas. * This is useful to put interface elements. * You can use React or other framework to put elements in this div. */ static htmlLayout: HTMLElement; static canvasWidth: number; static canvasHeight: number; static get screen(): pixi_js.Rectangle; /** * Initialize the PIXI Application and the interface div. * This method should be called before any other method. * @param element The html element where I will put the canvas. Example: document.body * @param width The width of the canvas * @param height The height of the canvas * @param options The options of PIXI Application * @example * ```typescript * const body = document.body * if (!body) { * throw new Error('body element not found') * } * await GameWindowManager.initialize(body, 1920, 1080, { * backgroundColor: "#303030" * }) * ``` */ static initialize(element: HTMLElement, width: number, height: number, options?: Partial<ApplicationOptions>): Promise<void>; /** * Add the canvas into a html element. * @param element it is the html element where I will put the canvas. Example: document.body */ private static addCanvasIntoHTMLElement; /** * Initialize the interface div and add it into a html element. * @param element it is the html element where I will put the interface div. Example: document.getElementById('root') * @example * ```tsx * const root = document.getElementById('root') * if (!root) { * throw new Error('root element not found') * } * GameWindowManager.initializeHTMLLayout(root) * const reactRoot = createRoot(GameWindowManager.htmlLayout) * reactRoot.render( * <App /> * ) * ``` */ static initializeHTMLLayout(element: HTMLElement): void; /** * This method returns the scale of the screen. */ static get screenScale(): number; /** * This method returns the width of the screen enlarged by the scale. */ static get screenWidth(): number; /** * This method returns the height of the screen enlarged by the scale. */ static get screenHeight(): number; /** * This method returns the horizontal margin of the screen. */ static get horizontalMargin(): number; /** * This method returns the vertical margin of the screen. */ static get verticalMargin(): number; /** * This method is called when the screen is resized. */ private static resize; /** * This is a dictionary that contains all Canvas Elements of Canvas, currently. */ static get currentCanvasElements(): { [tag: string]: CanvasBase<any>; }; private static _children; /** * The order of the children tags. */ private static childrenTagsOrder; /** * Add a canvas element to the canvas. * If there is a canvas element with the same tag, it will be removed. * @param tag The tag of the canvas element. * @param canvasElement The canvas elements to be added. * @example * ```typescript * const texture = await Assets.load('https://pixijs.com/assets/bunny.png'); * const sprite = CanvasSprite.from(texture); * GameWindowManager.addCanvasElement("bunny", sprite); * ``` */ static addCanvasElement(tag: string, canvasElement: CanvasBase<any>): void; /** * Remove a canvas element from the canvas. * And remove all tickers that are not connected to any canvas element. * @param tags The tag of the canvas element to be removed. * @returns * @example * ```typescript * GameWindowManager.removeCanvasElement("bunny"); * ``` */ static removeCanvasElement(tags: string | string[]): void; /** * Get a canvas element by the tag. * @param tag The tag of the canvas element. * @returns The canvas element. * @example * ```typescript * const sprite = GameWindowManager.getCanvasElement<CanvasSprite>("bunny"); * ``` */ static getCanvasElement<T extends CanvasBase<any>>(tag: string): T | undefined; /** * Check if a DisplayObject is on the canvas. * @param pixiElement The DisplayObject to be checked. * @returns If the DisplayObject is on the canvas. */ static canvasElementIsOnCanvas<T extends Container>(pixiElement: T): boolean; /** * Remove all canvas elements from the canvas. * And remove all tickers that are not connected to any canvas element. */ static removeCanvasElements(): void; /** * Edit the tag of a canvas element. * @param oldTag The old tag of the canvas element. * @param newTag The new tag of the canvas element. */ static editCanvasElementTag(oldTag: string, newTag: string): void; /** Edit Tickers Methods */ /** * Currently tickers that are running. */ static get currentTickers(): { [id: string]: TickerHistory<any>; }; static get currentTickersList(): TickerHistory<any>[]; private static get currentTickersWithoutCreatedBySteps(); private static _currentTickers; /** * The steps of the tickers */ static get currentTickersSteps(): { [tag: string]: ITickersSteps; }; private static _currentTickersSteps; private static _currentTickersTimeouts; private static generateTickerId; /** * Run a ticker. You can run multiple addTicker with the same tag and different tickerClasses. * If you run a ticker with the same tag and tickerClass, the old ticker will be removed. * If already exists a sequence of tickers with the same tag, it will be removed. * @param canvasEslementTag The tag of the canvas element that will use the ticker. * @param ticker The ticker class to be run. * @param args The arguments to be used in the ticker. * @param duration The time to be used in the ticker. This number is in seconds. If it is undefined, the ticker will run forever. * @param priority The priority to be used in the ticker. * @returns * @example * ```typescript * GameWindowManager.addTicker("alien", new RotateTicker({ speed: 0.2 })) * ``` */ static addTicker<TArgs extends TickerArgsType>(canvasElementTag: string | string[], ticker: TickerBase<TArgs>): void; private static pushTicker; /** * Run a sequence of tickers. If exists a ticker steps with the same tag, it will be removed. * @param tag The tag of canvas element that will use the tickers. * @param steps The steps of the tickers. * @param currentStepNumber The current step number. It is used to continue the sequence of tickers. * @returns * @example * ```typescript * GameWindowManager.addTickersSteps("alien", [ * new RotateTicker({ speed: 0.1, clockwise: true }, 2), // 2 seconds * Pause(1), // 1 second * new RotateTicker({ speed: 0.2, clockwise: false }, 2), * Repeat, * ]) * ``` */ static addTickersSteps<TArgs extends TickerArgsType>(tag: string, steps: (ITicker<TArgs> | RepeatType | PauseType)[], currentStepNumber?: number): void; private static restoneTickersSteps; private static runTickersSteps; private static nextTickerStep; static onEndOfTicker(canvasElementTags: string | string[], ticker: typeof TickerBase<any> | TickerBase<any> | string, canvasElementTagsToDelete: string | string[], tickerId: string): void; /** * Remove a connection between a canvas element and a ticker. * And remove the ticker if there is no canvas element connected to it. * @param tags The tag of the canvas element that will use the ticker. * @param ticker The ticker class to be removed. * @example * ```typescript * GameWindowManager.removeAssociationBetweenTickerCanvasElement("alien", RotateTicker) * ``` */ static removeAssociationBetweenTickerCanvasElement(tags: string | string[], ticker: typeof TickerBase<any> | TickerBase<any> | string): void; /** * Remove all tickers that are not connected to any existing canvas element. */ private static removeTickersWithoutAssociatedCanvasElement; private static addTickerTimeoutInfo; private static removeTickerTimeoutInfo; private static removeTickerTimeout; private static removeTickerTimeoutsByTag; /** * Remove all tickers from the canvas. */ static removeAllTickers(): void; /** * Remove all tickers from a canvas element. * @param tag The tag of the canvas element that will use the ticker. */ private static removeTickerByCanvasElement; private static removeTickerStepByCanvasElement; private static removeTicker; /** * Clear the canvas and the tickers. */ static clear(): void; /** * Export the canvas and the tickers to a JSON string. * @returns The JSON string. */ static exportJson(): string; /** * Export the canvas and the tickers to an object. * @returns The object. */ static export(): ExportedCanvas; /** * Import the canvas and the tickers from a JSON string. * @param dataString The JSON string. */ static importJson(dataString: string): void; /** * Import the canvas and the tickers from an object. * @param data The object. */ static import(data: object): void; } export { GameWindowManager as default };