@drincs/pixi-vn
Version:
Pixi'VN is a npm package that provides various features for creating visual novels.
1 lines • 8.28 kB
Source Map (JSON)
{"version":3,"sources":["../../src/functions/StepLabelUtility.ts","../../src/classes/LabelAbstract.ts","../../src/classes/Label.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAmBO,SAAS,mBAAA,CAAoB,OAAiD,KAA0D,EAAA;AAC3I,EAAA,OAAO,KAAU,KAAA,KAAA,CAAA;AACrB,CAAA;;;ACdA,IAA8B,gBAA9B,MAA4E;AAAA;AAAA;AAAA;AAAA;AAAA,EAKxE,WAAA,CAAY,IAAiB,KAA4B,EAAA;AACrD,IAAA,IAAA,CAAK,GAAM,GAAA,EAAA,CAAA;AACX,IAAA,IAAA,CAAK,eAAe,KAAO,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,KAAA,CAAA,WAAA,CAAA;AAC3B,IAAA,IAAA,CAAK,cAAc,KAAO,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,KAAA,CAAA,UAAA,CAAA;AAC1B,IAAA,IAAA,CAAK,aAAa,KAAO,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,KAAA,CAAA,SAAA,CAAA;AACzB,IAAA,IAAA,CAAK,eAAe,KAAO,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,KAAA,CAAA,WAAA,CAAA;AAAA,GAC/B;AAAA;AAAA;AAAA;AAAA,EAMA,IAAW,EAAkB,GAAA;AACzB,IAAA,OAAO,IAAK,CAAA,GAAA,CAAA;AAAA,GAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYU,4BAA4B,aAAgE,EAAA;AAClG,IAAI,IAAA,aAAA,CAAc,WAAW,CAAG,EAAA;AAC5B,MAAO,OAAA,CAAA,CAAA;AAAA,KACX;AACA,IAAA,IAAI,GAAc,GAAA,CAAA,CAAA;AAClB,IAAc,aAAA,CAAA,OAAA,CAAQ,CAAC,IAAA,EAAM,KAAU,KAAA;AACnC,MAAA,IAAI,oBAA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C,IAAI,IAAA,OAAO,IAAK,CAAA,MAAA,KAAW,UAAY,EAAA;AACnC,MAAA,OAAO,KAAK,MAAO,EAAA,CAAA;AAAA,KACvB;AACA,IAAA,OAAO,IAAK,CAAA,MAAA,CAAA;AAAA,GAChB;AACJ","file":"Label.mjs","sourcesContent":["import sha1 from 'crypto-js/sha1';\nimport { StepHistoryDataType } from \"../types/StepHistoryDataType\";\nimport { StepLabelType } from \"../types/StepLabelType\";\n\n/**\n * Convert StepLabel to StepHistoryData\n * @param step\n * @returns\n */\nexport function getStepSha1(step: StepLabelType): StepHistoryDataType {\n let sha1String = sha1(step.toString().toLocaleLowerCase())\n return sha1String.toString()\n}\n/**\n * Check if two steps are equal\n * @param step1\n * @param step2\n * @returns\n */\nexport function checkIfStepsIsEqual(step1: StepHistoryDataType | StepLabelType<any>, step2: StepHistoryDataType | StepLabelType<any>): boolean {\n return step1 === step2\n}\n","import { getLabelById } from \"../decorators\"\nimport { checkIfStepsIsEqual } from \"../functions/StepLabelUtility\"\nimport { LabelProps } from \"../interface\"\nimport { LabelIdType } from \"../types/LabelIdType\"\nimport { StepHistoryDataType } from \"../types/StepHistoryDataType\"\nimport { StepLabelType } from \"../types/StepLabelType\"\n\nexport default abstract class LabelAbstract<TLabel, TProps extends {} = {}> {\n /**\n * @param id is the id of the label\n * @param props is the properties of the label\n */\n constructor(id: LabelIdType, props?: LabelProps<TLabel>) {\n this._id = id\n this._onStepStart = props?.onStepStart\n this._onLoadStep = props?.onLoadStep\n this._onStepEnd = props?.onStepEnd\n this._choiseIndex = props?.choiseIndex\n }\n\n private _id: LabelIdType\n /**\n * Get the id of the label. This variable is used in the system to get the label by id, {@link getLabelById}\n */\n public get id(): LabelIdType {\n return this._id\n }\n\n /**\n * Get the steps of the label.\n */\n public abstract get steps(): StepLabelType<TProps>[]\n\n /**\n * Get the corresponding steps number\n * @param externalSteps\n * @returns Numer of corresponding steps, for example, if externalSteps is [ABC, DEF, GHI] and the steps of the label is [ABC, GHT], the result will be 1\n */\n protected getCorrespondingStepsNumber(externalSteps: StepHistoryDataType[] | StepLabelType[]): number {\n if (externalSteps.length === 0) {\n return 0\n }\n let res: number = 0\n externalSteps.forEach((step, index) => {\n if (checkIfStepsIsEqual(step, this.steps[index])) {\n res = index\n }\n })\n return res\n }\n\n private _onStepStart: ((stepIndex: number, label: TLabel) => void | Promise<void>) | undefined\n /**\n * Is a function that will be executed in {@link Label#onStepStart} and when the user goes back to it or when the user laods a save file.\n * @returns Promise<void> or void\n */\n public get onStepStart(): ((stepIndex: number, label: TLabel) => void | Promise<void>) | undefined {\n return async (stepIndex: number, label: TLabel) => {\n if (this._onLoadStep) {\n await this._onLoadStep(stepIndex, label)\n }\n if (this._onStepStart) {\n return await this._onStepStart(stepIndex, label)\n }\n }\n }\n\n private _onLoadStep: ((stepIndex: number, label: TLabel) => void | Promise<void>) | undefined\n /**\n * Get the function that will be executed a old step is reloaded. A step is reloaded when the user goes back to it or when the user laods a save file.\n * @returns Promise<void> or void\n */\n public get onLoadStep(): ((stepIndex: number, label: TLabel) => void | Promise<void>) | undefined {\n return this._onLoadStep\n }\n\n private _onStepEnd: ((stepIndex: number, label: TLabel) => void | Promise<void>) | undefined\n /**\n * Is a function that will be executed when the step ends.\n * @returns Promise<void> or void\n */\n public get onStepEnd(): ((stepIndex: number, label: TLabel) => void | Promise<void>) | undefined {\n return this._onStepEnd\n }\n\n private _choiseIndex: number | undefined\n public get choiseIndex(): number | undefined {\n return this._choiseIndex\n }\n}\n","import { LabelProps } from \"../interface\"\nimport { LabelIdType } from \"../types/LabelIdType\"\nimport { StepLabelType } from \"../types/StepLabelType\"\nimport LabelAbstract from \"./LabelAbstract\"\n\n/**\n * Label is a class that contains a list of steps, which will be performed as the game continues.\n * For Ren'py this is the equivalent of a label.\n * @example\n * ```typescript\n * const START_LABEL_ID = \"StartLabel\"\n * \n * export const startLabel = newLabel(START_LABEL_ID,\n * [\n * (props) => {\n * GameWindowManager.clear()\n * setDialogue({ character: liam, text: \"Which test do you want to perform?\" })\n * setChoiceMenuOptions([\n * new ChoiceMenuOption(\"Events Test\", eventsTestLabel),\n * new ChoiceMenuOption(\"Show Image Test\", showImageTest),\n * ])\n * },\n * (props) => GameStepManager.jumpLabel(START_LABEL_ID, props),\n * ]\n * )\n * \n * GameStepManager.callLabel(StartLabel)\n * ```\n */\nexport default class Label<T extends {} = {}> extends LabelAbstract<Label<T>, T> {\n /**\n * @param id is the id of the label\n * @param steps is the list of steps that the label will perform\n * @param props is the properties of the label\n */\n constructor(id: LabelIdType, steps: StepLabelType<T>[] | (() => StepLabelType<T>[]), props?: LabelProps<Label<T>>) {\n super(id, props)\n this._steps = steps\n }\n\n private _steps: StepLabelType<T>[] | (() => StepLabelType<T>[])\n /**\n * Get the steps of the label.\n */\n public get steps(): StepLabelType<T>[] {\n if (typeof this._steps === \"function\") {\n return this._steps()\n }\n return this._steps\n }\n}\n"]}