UNPKG

@drincs/pixi-vn

Version:

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

1 lines 6.05 kB
{"version":3,"sources":["../../src/functions/StepLabelUtility.ts","../../src/classes/LabelAbstract.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,oBAAoB,IAAM,EAAA,IAAA,CAAK,KAAM,CAAA,KAAK,CAAC,CAAG,EAAA;AAC9C,QAAM,GAAA,GAAA,KAAA,CAAA;AAAA,OACV;AAAA,KACH,CAAA,CAAA;AACD,IAAO,OAAA,GAAA,CAAA;AAAA,GACX;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAW,WAAwF,GAAA;AAC/F,IAAO,OAAA,CAAO,WAAmB,KAAkB,KAAA,OAAA,CAAA,IAAA,EAAA,IAAA,EAAA,aAAA;AAC/C,MAAA,IAAI,KAAK,WAAa,EAAA;AAClB,QAAM,MAAA,IAAA,CAAK,WAAY,CAAA,SAAA,EAAW,KAAK,CAAA,CAAA;AAAA,OAC3C;AACA,MAAA,IAAI,KAAK,YAAc,EAAA;AACnB,QAAA,OAAO,MAAM,IAAA,CAAK,YAAa,CAAA,SAAA,EAAW,KAAK,CAAA,CAAA;AAAA,OACnD;AAAA,KACJ,CAAA,CAAA;AAAA,GACJ;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAW,UAAuF,GAAA;AAC9F,IAAA,OAAO,IAAK,CAAA,WAAA,CAAA;AAAA,GAChB;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAW,SAAsF,GAAA;AAC7F,IAAA,OAAO,IAAK,CAAA,UAAA,CAAA;AAAA,GAChB;AAAA,EAGA,IAAW,WAAkC,GAAA;AACzC,IAAA,OAAO,IAAK,CAAA,YAAA,CAAA;AAAA,GAChB;AACJ","file":"LabelAbstract.js","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"]}