UNPKG

@drincs/pixi-vn

Version:

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

241 lines (238 loc) 8.71 kB
import { ChoiceMenuOptionClose } from '../classes/ChoiceMenuOption.js'; import { LabelIdType } from '../types/LabelIdType.js'; import { StepLabelPropsType, StepLabelResultType, StepLabelType } from '../types/StepLabelType.js'; import CharacterBaseModel from '../classes/CharacterBaseModel.js'; import DialogueBaseModel from '../classes/DialogueBaseModel.js'; import Label from '../classes/Label.js'; import IHistoryStep from '../interface/IHistoryStep.js'; import IOpenedLabel from '../interface/IOpenedLabel.js'; import ExportedStep from '../interface/export/ExportedStep.js'; import '../types/StorageElementType.js'; import '../types/CloseType.js'; import '../types/LabelRunModeType.js'; import '@drincs/pixi-vn/dist/override'; import '../classes/LabelAbstract.js'; import '../types/StepHistoryDataType.js'; import '../interface/LabelProps.js'; import '../interface/CharacterBaseModelProps.js'; import '../classes/StoredClassModel.js'; import 'deep-diff'; import '../interface/export/ExportedCanvas.js'; import '../interface/canvas/ICanvasBaseMemory.js'; import '../interface/ITickersSteps.js'; import 'pixi.js'; import '../TickerBase-3rLpDpmb.js'; import '../types/TickerIdType.js'; import '../types/PauseType.js'; import '../types/RepeatType.js'; import '../interface/TickerHistory.js'; import '../interface/export/ExportedStorage.js'; /** * GameStepManager is a class that manages the steps and labels of the game. */ declare class GameStepManager { private constructor(); /** * stepHistory is a list of label events and steps that occurred during the progression of the steps. */ private static _stepsHistory; static get stepsHistory(): IHistoryStep<DialogueBaseModel<CharacterBaseModel>>[]; private static _lastStepIndex; /** * lastStepIndex is the last step index that occurred during the progression of the steps. **Not is the length of the stepsHistory - 1.** */ static get lastStepIndex(): number; /** * Increase the last step index that occurred during the progression of the steps. */ private static increaseLastStepIndex; private static _openedLabels; static get openedLabels(): IOpenedLabel[]; /** * currentLabelId is the current label id that occurred during the progression of the steps. */ private static get currentLabelId(); /** * currentLabel is the current label that occurred during the progression of the steps. */ static get currentLabel(): Label | undefined; private static get currentLabelStepIndex(); /** * lastHistoryStep is the last history step that occurred during the progression of the steps. */ private static get lastHistoryStep(); private static _originalStepData; private static get originalStepData(); private static set originalStepData(value); private static get currentStepData(); /** * Add a label to the history. * @param label The label to add to the history. */ private static addStepHistory; /** * Add a label to the history. * @param label The label to add to the history. */ private static pushNewLabel; /** * Close the current label and add it to the history. * @returns */ static closeCurrentLabel(): void; /** * Close all labels and add them to the history. **Attention: This method can cause an unhandled game ending.** */ static closeAllLabels(): void; /** * Increase the current step index of the current label. */ private static increaseCurrentStepIndex; private static restorLastLabelList; static get canGoNext(): boolean; /** * Execute the next step and add it to the history. * @param props The props to pass to the step. * @param choiseMade The index of the choise made by the player. (This params is used in the choice menu) * @returns StepLabelResultType or undefined. * @example * ```typescript * function nextOnClick() { * setLoading(true) * GameStepManager.goNext(yourParams) * .then((result) => { * setUpdate((p) => p + 1) * setLoading(false) * if (result) { * // your code * } * }) * .catch((e) => { * setLoading(false) * console.error(e) * }) * } * ``` */ static goNext(props: StepLabelPropsType, choiseMade?: number): Promise<StepLabelResultType>; /** * Execute the current step and add it to the history. * @param props The props to pass to the step. * @param choiseMade The choise made by the player. * @returns StepLabelResultType or undefined. */ private static runCurrentStep; /** * Execute the label and add it to the history. (It's similar to Ren'Py's call function) * @param label The label to execute or the id of the label * @param props The props to pass to the label. * @returns StepLabelResultType or undefined. * @example * ```typescript * GameStepManager.callLabel(startLabel, yourParams).then((result) => { * if (result) { * // your code * } * }) * ``` * @example * ```typescript * // if you use it in a step label you should return the result. * return GameStepManager.callLabel(startLabel).then((result) => { * return result * }) * ``` */ static callLabel<T extends {} = {}>(label: Label<T> | LabelIdType, props: StepLabelPropsType<T>): Promise<StepLabelResultType>; /** * Execute the label, close the current label, execute the new label and add the new label to the history. (It's similar to Ren'Py's jump function) * @param label The label to execute. * @param props The props to pass to the label or the id of the label * @returns StepLabelResultType or undefined. * @example * ```typescript * GameStepManager.jumpLabel(startLabel, yourParams).then((result) => { * if (result) { * // your code * } * }) * ``` * @example * ```typescript * // if you use it in a step label you should return the result. * return GameStepManager.jumpLabel(startLabel).then((result) => { * return result * }) * ``` */ static jumpLabel<T extends {}>(label: Label<T> | LabelIdType, props: StepLabelPropsType<T>): Promise<StepLabelResultType>; /** * When the player is in a choice menu, can use this function to exit to the choice menu. * @param choice * @param props * @returns StepLabelResultType or undefined. * @example * ```typescript * GameStepManager.closeChoiceMenu(yourParams).then((result) => { * if (result) { * // your code * } * }) * ``` */ static closeChoiceMenu<T extends {} = {}>(choice: ChoiceMenuOptionClose<T>, props: StepLabelPropsType<T>): Promise<StepLabelResultType>; /** * Go back to the last step and add it to the history. * @param navigate The navigate function. * @param steps The number of steps to go back. * @returns * @example * ```typescript * export function goBack(navigate: (path: string) => void, afterBack?: () => void) { * GameStepManager.goBack(navigate) * afterBack && afterBack() * } * ``` */ static goBack(navigate: (path: string) => void, steps?: number): Promise<void>; private static goBackInternal; /** * Return true if it is possible to go back. */ static get canGoBack(): boolean; /** * Add a label to the history. */ static clear(): void; /** * Export the history to a JSON string. * @returns The history in a JSON string. */ static exportJson(): string; /** * Export the history to an object. * @returns The history in an object. */ static export(): ExportedStep; /** * Import the history from a JSON string. * @param dataString The history in a JSON string. */ static importJson(dataString: string): Promise<void>; /** * Import the history from an object. * @param data The history in an object. */ static import(data: object): Promise<void>; /** * Function to be executed at the end of the game. It should be set in the game initialization. * @example * ```typescript * GameStepManager.gameEnd = async (props) => { * props.navigate("/end") * } * ``` */ static gameEnd: StepLabelType | undefined; } export { GameStepManager as default };