@drincs/pixi-vn 1.8.13 → 1.8.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas.cjs +1 -1
- package/dist/canvas.mjs +1 -1
- package/dist/characters.cjs +1 -1
- package/dist/characters.d.cts +3 -2
- package/dist/characters.d.ts +3 -2
- package/dist/characters.mjs +1 -1
- package/dist/chunk-GIYMPXBT.mjs +1 -1
- package/dist/chunk-HQQ5WH6C.mjs +1 -1
- package/dist/history.cjs +1 -1
- package/dist/history.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/motion.cjs +1 -1
- package/dist/motion.mjs +1 -1
- package/dist/narration.cjs +1 -1
- package/dist/narration.d.cts +19 -7
- package/dist/narration.d.ts +19 -7
- package/dist/narration.mjs +1 -1
- package/dist/pixi/browser.js +156 -156
- package/dist/sound.cjs +1 -1
- package/dist/sound.mjs +1 -1
- package/dist/storage.cjs +1 -1
- package/dist/vite-listener.cjs +1 -1
- package/dist/vite-listener.mjs +1 -1
- package/dist/vite.cjs +2 -2
- package/dist/vite.d.cts +16 -4
- package/dist/vite.d.ts +16 -4
- package/dist/vite.mjs +2 -2
- package/package.json +2 -2
package/dist/narration.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ interface NarrationManagerInterface {
|
|
|
30
30
|
*/
|
|
31
31
|
getRandomNumber(min: number, max: number, options?: {
|
|
32
32
|
/**
|
|
33
|
-
* If true
|
|
33
|
+
* If `true`, the number will be generated only once for the current `step` of the `label` (default: `false`). Note: `min` and `max` affect the storage of already generated numbers.
|
|
34
34
|
* @default false
|
|
35
35
|
*/
|
|
36
36
|
onceOnly?: boolean;
|
|
@@ -253,9 +253,12 @@ interface NarrationManagerInterface {
|
|
|
253
253
|
* If true, the player must enter a value.
|
|
254
254
|
*/
|
|
255
255
|
readonly isRequiredInput: boolean;
|
|
256
|
+
/**
|
|
257
|
+
* Returns the type of input prompt requested.
|
|
258
|
+
*/
|
|
256
259
|
readonly inputType: string | undefined;
|
|
257
260
|
/**
|
|
258
|
-
*
|
|
261
|
+
* Returns `true` if the player must enter a value.
|
|
259
262
|
* @param info The input value to be inserted by the player.
|
|
260
263
|
* @param defaultValue The default value to be inserted.
|
|
261
264
|
*/
|
|
@@ -450,12 +453,17 @@ declare class Label<T extends {} = {}> extends LabelAbstract<Label<T>, T> {
|
|
|
450
453
|
|
|
451
454
|
interface ChoiceMenuOptionOptions extends Omit<ChoiceInterface$1, "text" | "label" | "type" | "props" | "closeCurrentLabel"> {
|
|
452
455
|
/**
|
|
453
|
-
*
|
|
456
|
+
* How the `label` will be performed. Can be `call` or `jump`.
|
|
457
|
+
* @default "call"
|
|
454
458
|
*/
|
|
455
459
|
type?: LabelRunModeType;
|
|
456
460
|
}
|
|
457
461
|
/**
|
|
458
462
|
* Function to create a new choice menu option.
|
|
463
|
+
* @param text The text displayed in the choice menu.
|
|
464
|
+
* @param label The `label` to call when the player selects the option.
|
|
465
|
+
* @param props The properties passed to the `label`. If the `label` does not require parameters, pass an empty object `{}`.
|
|
466
|
+
* @param options An object with the `choice`'s options
|
|
459
467
|
* @example
|
|
460
468
|
* ```ts
|
|
461
469
|
* newChoiceOption("Hello", HelloLabel, {})
|
|
@@ -465,12 +473,16 @@ declare function newChoiceOption<T extends StorageObjectType>(text: ChoiceInterf
|
|
|
465
473
|
|
|
466
474
|
interface ChoiceMenuOptionCloseOptions extends Omit<ChoiceInterface$1, "text" | "label" | "type" | "props" | "closeCurrentLabel"> {
|
|
467
475
|
/**
|
|
468
|
-
*
|
|
476
|
+
* IIf `true`, the current `label` will be closed.
|
|
477
|
+
* @default false
|
|
469
478
|
*/
|
|
470
479
|
closeCurrentLabel?: boolean;
|
|
471
480
|
}
|
|
472
481
|
/**
|
|
473
|
-
*
|
|
482
|
+
* In addition to `newChoiceOption`, you can use `newCloseChoiceOption` to create a closing option.
|
|
483
|
+
* This closes the choice menu and continues with the `steps`, without calling any `label`.
|
|
484
|
+
* @param text The text displayed in the choice menu.
|
|
485
|
+
* @param options An object with the `choice`'s options
|
|
474
486
|
* @example
|
|
475
487
|
* ```ts
|
|
476
488
|
* newCloseChoiceOption("Return")
|
|
@@ -499,9 +511,9 @@ declare namespace RegisteredLabels {
|
|
|
499
511
|
function get<T = LabelAbstract<any>, T2 extends LabelIdType | string = LabelIdType>(id: T2): T | undefined;
|
|
500
512
|
/**
|
|
501
513
|
* Saves a label in the system
|
|
502
|
-
* @param
|
|
514
|
+
* @param labels The label(s) to be saved
|
|
503
515
|
*/
|
|
504
|
-
function add(
|
|
516
|
+
function add(...labels: (LabelAbstract<any, any>)[]): void;
|
|
505
517
|
/**
|
|
506
518
|
* Get a list of all labels registered.
|
|
507
519
|
* @returns An array of labels.
|
package/dist/narration.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {a}from'./chunk-6GLWL3NH.mjs';import {l,n}from'./chunk-IWAXXFXE.mjs';import {d,c,e,f}from'./chunk-HQQ5WH6C.mjs';import {GameUnifier,PixiError}from'./core.mjs';var h=new d({cacheSize:10}),R;(d=>{function i(p){let f=h.get(p);if(!f){e.error(`Label "${p}" not found`);return}return f}d.get=i;function e$1(p){if(Array.isArray(p)){p.forEach(f=>{e$1(f);});return}h.has(p.id)&&e.info(`Label "${p.id}" already exists, it will be overwritten`),h.set(p.id,p);}d.add=e$1;function t(){return Array.from(h.values())}d.values=t;function r(p){return h.has(p)}d.has=r;function n(){return Array.from(h.keys())}d.keys=n;function a(){h.clear();}d.clear=a;})(R||={});var L=R;var o=class i{constructor(){}static choiceMadeTemp=void 0;static lastHistoryStep=null;static get allOpenedLabels(){return GameUnifier.getVariable(l,n.OPENED_LABELS_COUNTER_KEY)||{}}static set allOpenedLabels(e){GameUnifier.setVariable(l,n.OPENED_LABELS_COUNTER_KEY,e);}static getCurrentStepTimesCounterData(e$1=""){let t=i.currentLabelStepIndex;if(t===null)return e.error("currentLabelStepIndex is null"),null;let r=`${t}${e$1}`,n$1=i.currentLabelId,a=i._currentLabel;if(!n$1||t===null||!a)return e.error("currentLabelId or currentLabelStepIndex is null or currentLabel not found"),null;let d=a.getStepSha(t)||"error",p=GameUnifier.getVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY)||{};return p[n$1]||(p[n$1]={}),(!p[n$1][r]||p[n$1][r].stepSha1!==d)&&(p[n$1][r]={stepSha1:d}),p[n$1][r]}static setCurrentStepTimesCounterData(e$1="",t){let r=i.currentLabelStepIndex,n$1=r+e$1,a=i.currentLabelId;if(!a||r===null){e.error("currentLabelId or currentLabelStepIndex is null");return}let d=GameUnifier.getVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY)||{};d[a]||(d[a]={}),d[a][n$1]=t,GameUnifier.setVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY,d);}static getCurrentStepTimesCounter(e$1=""){let t=i._stepCounter,r=i.getCurrentStepTimesCounterData(e$1);if(!r)return e.error("getCurrentStepTimesCounter obj is null"),0;let n=r.stepCounters||[];return n.find(d=>d===t)||(n.push(t),r.stepCounters=n,i.setCurrentStepTimesCounterData(e$1,r)),n.length}static getRandomNumber(e,t,r={}){let n=r.nestedId||"";if(r.onceOnly||false){let d=i.getCurrentStepTimesCounterData(n);if(!d)return;let p=d.usedRandomNumbers||{},f=Array.from({length:t-e+1},(E,N)=>N+e).filter(E=>!p[`${e}-${t}`]?.includes(E));if(f.length===0)return;let S=Math.floor(Math.random()*f.length),b=f[S];return p[`${e}-${t}`]||(p[`${e}-${t}`]=[]),p[`${e}-${t}`].push(b),d.usedRandomNumbers=p,i.setCurrentStepTimesCounterData(n,d),b}return Math.floor(Math.random()*(t-e+1))+e}static resetCurrentStepTimesCounter(e$1=""){let t=i.currentLabelStepIndex,r=t+e$1,n$1=i.currentLabelId;if(!n$1||t===null){e.error("currentLabelId or currentLabelStepIndex is null");return}let a=GameUnifier.getVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY)||{};a[n$1]||(a[n$1]={}),a[n$1][r]={stepCounters:[],stepSha1:""},GameUnifier.setVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY,a);}static get allChoicesMade(){return GameUnifier.getVariable(l,n.ALL_CHOICES_MADE_KEY)||[]}static set allChoicesMade(e){GameUnifier.setVariable(l,n.ALL_CHOICES_MADE_KEY,e);}static _stepCounter=0;static increaseStepCounter(){i._stepCounter++;}static _openedLabels=[];static get openedLabels(){return f(i._openedLabels)}static set openedLabels(e){i._openedLabels=f(e);}static _originalOpenedLabels=[];static get originalOpenedLabels(){return f(i._originalOpenedLabels)}static set originalOpenedLabels(e){i._originalOpenedLabels=f(e);}static get _currentLabel(){if(i.currentLabelId)return L.get(i.currentLabelId)}static get currentLabelId(){if(i._openedLabels.length>0)return i._openedLabels[i._openedLabels.length-1].label}static get currentLabelStepIndex(){return i._openedLabels.length>0?i._openedLabels[i._openedLabels.length-1].currentStepIndex:null}static addLabelHistory(e,t){let r=i.allOpenedLabels,n=i.allOpenedLabels[e]?.biggestStep||0,a=i.allOpenedLabels[e]?.openCount||0;(!n||n<t)&&(r[e]={biggestStep:t,openCount:a},i.allOpenedLabels=r);}static addChoicesMade(e,t,r,n){let a=i.allChoicesMade,d=a.findIndex(p=>p.labelId===e&&p.stepIndex===t&&p.choiceIndex===n&&p.stepSha1===r);d<0?a.push({labelId:e,stepIndex:t,choiceIndex:n,stepSha1:r,madeTimes:1}):a[d].madeTimes++,i.allChoicesMade=a;}static pushNewLabel(e){if(!L.get(e))throw new PixiError("unregistered_element",`Label ${e} not found`);i._openedLabels.push({label:e,currentStepIndex:0});let r=i.allOpenedLabels,n=i.allOpenedLabels[e]?.biggestStep||0,a=i.allOpenedLabels[e]?.openCount||0;r[e]={biggestStep:n,openCount:a+1},i.allOpenedLabels=r;}static increaseCurrentStepIndex(){if(i._openedLabels.length>0){let e=i._openedLabels[i._openedLabels.length-1];i._openedLabels[i._openedLabels.length-1]={...e,currentStepIndex:e.currentStepIndex+1};}}static _onStepStart;static set onStepStart(e){i._onStepStart=e;}static get onStepStart(){return async(e,t)=>{let r=[];return i.onLoadingLabel&&e===0&&r.push(i.onLoadingLabel(e,t)),i._onStepStart&&r.push(i._onStepStart(e,t)),await Promise.all(r)}}static onLoadingLabel;static onStepEnd};var C=class{get currentStepTimesCounter(){return o.getCurrentStepTimesCounter()}set currentStepTimesCounter(e){o.resetCurrentStepTimesCounter();}getRandomNumber(e,t,r={}){return o.getRandomNumber(e,t,r)}get stepCounter(){return o._stepCounter}get openedLabels(){return o.openedLabels}get currentLabel(){return o._currentLabel}addStepHistory(e,t={}){let{choiceMade:r,ignoreSameStep:n$1}=t,a,d,p,f=GameUnifier.getVariable(l,n.LAST_STEP_GLUED)===this.stepCounter;GameUnifier.getVariable(l,n.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(a=GameUnifier.getVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY)),GameUnifier.getVariable(l,n.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(d=GameUnifier.getVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY)),GameUnifier.getVariable(l,n.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(p=GameUnifier.getVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY));let S=o.openedLabels,b={currentLabel:o.currentLabelId,dialogue:a,choices:d,stepSha1:e,index:this.stepCounter,labelStepIndex:o.currentLabelStepIndex,choiceIndexMade:r,inputValue:p,alreadyMadeChoices:this.alreadyCurrentStepMadeChoices,isGlued:f,openedLabels:S};o.originalOpenedLabels=S,GameUnifier.addHistoryItem(b,{ignoreSameStep:n$1}),o.lastHistoryStep=b,o.increaseStepCounter();}closeCurrentLabel(){if(!o.currentLabelId){e.warn("No label to close");return}if(!this.currentLabel){e.error("currentLabel not found");return}let e$1=o.openedLabels;e$1.pop(),o.openedLabels=e$1,GameUnifier.onLabelClosing(this.openedLabels.length);}closeAllLabels(){for(;o.openedLabels.length>0;)this.closeCurrentLabel(),GameUnifier.onLabelClosing(this.openedLabels.length);}isLabelAlreadyCompleted(e){let t;typeof e=="string"?t=e:t=e.id;let n=o.allOpenedLabels[t]?.biggestStep||0;if(n){let a=L.get(t);if(a)return a.stepCount<=n}return false}get alreadyCurrentStepMadeChoicesObj(){let e$1=o.currentLabelStepIndex,t=this.currentLabel;if(e$1===null||!t)return;let r=t.getStepSha(e$1);return r||(e.warn("stepSha not found, setting to ERROR"),r="error"),o.allChoicesMade.filter(n=>n.labelId===t?.id&&n.stepIndex===e$1&&n.stepSha1===r)}get alreadyCurrentStepMadeChoices(){return this.alreadyCurrentStepMadeChoicesObj?.map(e=>e.choiceIndex)}get isCurrentStepAlreadyOpened(){let e=o.currentLabelId;if(e){let t=o.allOpenedLabels[e]?.openCount||0;if(o.currentLabelStepIndex&&t>=o.currentLabelStepIndex)return true}return false}getTimesLabelOpened(e){return o.allOpenedLabels[e]?.openCount||0}getTimesChoiceMade(e){return this.alreadyCurrentStepMadeChoicesObj?.find(t=>t.choiceIndex===e)?.madeTimes||0}addCurrentStepToHistory(){this.addStepHistory("dev",{ignoreSameStep:true});}getCanContinue(e$1){let t=e$1?.showWarn||false,r=this.choices;return r&&r.length>0?(t&&e.warn("The player must make a choice"),false):this.isRequiredInput?(t&&e.warn("The player must enter a value"),false):true}get canContinue(){return GameUnifier.runningStepsCount!==0?false:this.getCanContinue()}async onStepStart(e,t){let r=[];return e.onStepStart&&r.push(e.onStepStart(t,e)),o.onStepStart&&r.push(o.onStepStart(t,e)),await Promise.all(r)}async onStepEnd(e,t){let r=[];return e.onStepEnd&&r.push(e.onStepEnd(t,e)),o.onStepEnd&&r.push(o.onStepEnd(t,e)),await Promise.all(r)}async continue(e$1,t={}){let{runNow:r=false,steps:n=1}=t;if(!Number.isFinite(n)){e.warn(`[continue] The parameter steps must be a valid finite number, received: ${n}`);return}if(n<=0){e.warn(`[continue] The parameter steps must be greater than 0, received: ${n}`);return}if(!r&&!this.getCanContinue({showWarn:true}))return;if(!r&&GameUnifier.runningStepsCount!==0){GameUnifier.increaseContinueRequest(n);return}n>1&&GameUnifier.increaseContinueRequest(n-1),GameUnifier.runningStepsCount++;let a;try{GameUnifier.runningStepsCount===1&&await GameUnifier.onPreContinue(),o.increaseCurrentStepIndex(),a=await this.runCurrentStep(e$1,t);}catch(d){throw e.error("Error continuing",d),d}return GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(e$1)||a}async afterRunCurrentStep(e$1){if(GameUnifier.runningStepsCount===0&&GameUnifier.continueRequestsCount!==0)return await GameUnifier.processNavigationRequests(e$1);if(this.openedLabels.length===0){if(GameUnifier.onEnd)return await GameUnifier.onEnd(e$1,{labelId:"end"});e.error("The end of the game is not managed, so the game is blocked. Read this documentation to know how to manage the end of the game: https://pixi-vn.com/start/other-narrative-features.html#how-manage-the-end-of-the-game");}}async runCurrentStep(e$1,t={}){let{choiceMade:r}=t;if(o.currentLabelId){let n=o.currentLabelStepIndex;if(n===null){e.error("currentLabelStepIndex is null");return}let a=o._currentLabel;if(!a){e.error("currentLabel not found");return}if(a.stepCount>n){try{await this.onStepStart(a,n);}catch(b){e.error("Error running onStepStart",b),this.onStepError&&await this.onStepError(b,e$1);return}let d=a.getStepById(n);if(!d){e.error("step not found");return}let p=a.getStepSha(n);p||(e.warn("stepSha not found, setting to ERROR"),p="error");let f,S;try{f=await d(e$1,{labelId:a.id});}catch(b){e.error("Error running step",b),S=b;}try{let b=this.choices;if(b?.length===1&&b[0].autoSelect){let E=b[0];f=await this.selectChoice(E,e$1);}}catch(b){e.error("Error auto-selecting choice",b),S||(S=b);}try{let b=o.lastHistoryStep;r!==void 0&&b&&(p=b.stepSha1,p||(e.warn("stepSha not found, setting to ERROR"),p="error"),o.addChoicesMade(b.currentLabel||"error",typeof b.labelStepIndex=="number"?b.labelStepIndex:-1,b.stepSha1||"error",r),o.choiceMadeTemp=r);}catch(b){e.warn("Error adding choice made to history",b);}try{GameUnifier.runningStepsCount===1&&(o.addLabelHistory(a.id,n),this.addStepHistory(p,{...t,choiceMade:o.choiceMadeTemp}),o.choiceMadeTemp=void 0);}catch(b){e.warn("Error adding step to history",b);}try{this.currentLabel&&await this.onStepEnd(this.currentLabel,o.currentLabelStepIndex||0);}catch(b){e.warn("Error running onStepEnd",b);}return S&&this.onStepError&&await this.onStepError(S,e$1),f}else {if(this.openedLabels.length>1)return this.closeCurrentLabel(),await this.continue(e$1,t);if(this.openedLabels.length===1){o.openedLabels=[];return}}}else {if(this.openedLabels.length===0)return;e.error("currentLabelId not found");}}async call(e$1,t,r){let{choiceMade:n}=r||{},a;typeof e$1=="string"?a=e$1:a=e$1.id,GameUnifier.runningStepsCount++;let d;try{let p=L.get(a);if(!p)throw new PixiError("unregistered_element",`Label ${a} not found`);o.pushNewLabel(p.id),d=await this.runCurrentStep(t,{choiceMade:n});}catch(p){throw e.error("Error calling label",p),p}return GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(t)||d}async jump(e$1,t,r){if(this.stepCounter===0)return await this.call(e$1,t,r);this.openedLabels.length>0&&this.closeCurrentLabel();let{choiceMade:n}=r||{},a;typeof e$1=="string"?a=e$1:a=e$1.id,GameUnifier.runningStepsCount++;let d;try{let p=L.get(a);if(!p)throw new PixiError("unregistered_element",`Label ${a} not found`);o.pushNewLabel(p.id),d=await this.runCurrentStep(t,{choiceMade:n});}catch(p){throw e.error("Error jumping to label",p),p}return GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(t)||d}async selectChoice(e$1,t){this.choices=void 0;let r=e$1.type;switch(r){case "call":return await this.call(e$1.label,{...e$1.props,...t},{choiceMade:e$1.choiceIndex});case "jump":return await this.jump(e$1.label,{...e$1.props,...t},{choiceMade:e$1.choiceIndex});case "close":return await this.closeChoiceMenu(e$1,{...e$1.props,...t});default:throw e.error(`Type ${r} not found`),new PixiError("invalid_usage",`Type ${r} not found`)}}async closeChoiceMenu(e$1,t){if(e$1.type!=="close")throw e.error("For closeChoiceMenu, the type must be close"),new PixiError("invalid_usage","For closeChoiceMenu, the type must be close");let r;return typeof e$1.choiceIndex=="number"&&(r=e$1.choiceIndex),e$1.closeCurrentLabel&&this.closeCurrentLabel(),await this.continue(t,{choiceMade:r})}get onStepError(){return async(e$1,t)=>{try{await GameUnifier.runOnError(e$1,t);}catch(r){e.error("Error in onError handler",r);}}}get dialogue(){let e=GameUnifier.getVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY);if(e)return {...e,character:e.character?GameUnifier.getCharacter(e.character)||e.character:void 0}}set dialogue(e$1){if(e$1===void 0){GameUnifier.setVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY,void 0);return}if((typeof e$1=="string"||Array.isArray(e$1))&&(e$1={text:e$1}),this.dialogGlue){let t=GameUnifier.getVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY);if(t){let r=[];Array.isArray(t.text)?r=[...t.text]:r=[t.text],Array.isArray(e$1.text)?r=[...r,...e$1.text]:r=[...r,e$1.text],e$1.text=r,e$1.character=e$1.character||t.character;}GameUnifier.setVariable(l,n.LAST_STEP_GLUED,this.stepCounter),this.dialogGlue=false;}try{GameUnifier.setVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY,f({...e$1,character:typeof e$1.character=="string"?e$1.character:e$1.character?.id})),GameUnifier.setVariable(l,n.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw e.error("DialogueInterface cannot contain functions or classes"),new PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}get choices(){let e=GameUnifier.getVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY);if(e){let t=[],r=e.map((a,d)=>({...a,choiceIndex:d})),n=this.alreadyCurrentStepMadeChoices;if(r=r.filter((a,d)=>a.oneTime&&n?.includes(d)?false:a.onlyHaveNoChoice?(t.push(a),false):true),r.length>0)return r;if(t.length>0)return [t[0]]}}set choices(e$1){if(!e$1||e$1.length===0){GameUnifier.setVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY,void 0);return}try{GameUnifier.setVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY,f(e$1)),GameUnifier.setVariable(l,n.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw e.error("ChoiceInterface cannot contain functions or classes"),new PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}get dialogGlue(){return GameUnifier.getFlag(n.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY)}set dialogGlue(e){GameUnifier.setFlag(n.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,e);}get inputValue(){return GameUnifier.getVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY)}set inputValue(e){this.removeInputRequest(),GameUnifier.setVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY,e),GameUnifier.setVariable(l,n.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}get isRequiredInput(){return GameUnifier.getVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY)?.isRequired||false}get inputType(){return GameUnifier.getVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY)?.type}requestInput(e,t){e.isRequired=true,GameUnifier.setVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY,e),t!==void 0?GameUnifier.setVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY,t):GameUnifier.removeVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY);}removeInputRequest(){GameUnifier.removeVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY),GameUnifier.removeVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY);}clear(){o.openedLabels=[],o._stepCounter=0;}export(){return {openedLabels:f(o.openedLabels),stepCounter:this.stepCounter}}async onLoadingLabel(e){let t=this.openedLabels.map(async r=>{let n=[],a=L.get(r.label);return a&&(a.onLoadingLabel&&n.push(a.onLoadingLabel(e,a)),o.onLoadingLabel&&n.push(o.onLoadingLabel(e,a))),await Promise.all(n)});return await Promise.all(t)}async restore(e$1,t){this.clear();try{o.lastHistoryStep=t,Object.hasOwn(e$1,"openedLabels")?(o.openedLabels=e$1.openedLabels,o.originalOpenedLabels=o.openedLabels):e.warn("Could not import openedLabels data, so will be ignored"),Object.hasOwn(e$1,"stepCounter")?o._stepCounter=e$1.stepCounter:e.warn("Could not import stepCounter data, so will be ignored");try{await this.onLoadingLabel(o.currentLabelStepIndex||0);}catch(r){e.error("Error running onLoadingLabel",r);}}catch(r){e.error("Error importing data",r);}}};function D(i,e,t,r){let n=typeof e=="string"?e:e.id;return {...r,label:n,props:t,text:i,type:r?.type||"call"}}var O="close";function U(i,e){return {...e,type:O,text:i}}var M=c(a(),1);var g=class{constructor(e,t){this.id=e,this._onStepStart=t?.onStepStart,this._onLoadingLabel=t?.onLoadingLabel,this._onStepEnd=t?.onStepEnd;}id;_onStepStart;get onStepStart(){return async(e,t)=>{if(this._onLoadingLabel&&e===0&&await this._onLoadingLabel(e,t),this._onStepStart)return await this._onStepStart(e,t)}}_onLoadingLabel;get onLoadingLabel(){return this._onLoadingLabel}_onStepEnd;get onStepEnd(){return this._onStepEnd}};var I=class extends g{get stepCount(){return this.steps.length}getStepById(e){return this.steps[e]}constructor(e,t,r){super(e,r),this._steps=t;}_steps;get steps(){return typeof this._steps=="function"?this._steps():this._steps}getStepSha(e$1){if(e$1<0||e$1>=this.steps.length)return e.warn("stepSha not found, setting to ERROR"),"error";try{let t=this.steps[e$1];return (0,M.default)(t.toString().toLocaleLowerCase()).toString()}catch(t){return e.warn("stepSha not found, setting to ERROR",t),"error"}}};function x(i,e,t){let r=new I(i,e,t);return L.add(r),r}var fe=new C;
|
|
1
|
+
import {a}from'./chunk-6GLWL3NH.mjs';import {l,n}from'./chunk-IWAXXFXE.mjs';import {d,c,e,f}from'./chunk-HQQ5WH6C.mjs';import {GameUnifier,PixiError}from'@drincs/pixi-vn/core';var h=new d({cacheSize:10}),R;(d=>{function i(l){let f=h.get(l);if(!f){e.error(`Label "${l}" not found`);return}return f}d.get=i;function e$1(...l){for(let f of l)h.has(f.id)&&e.info(`Label "${f.id}" already exists, it will be overwritten`),h.set(f.id,f);}d.add=e$1;function t(){return Array.from(h.values())}d.values=t;function r(l){return h.has(l)}d.has=r;function n(){return Array.from(h.keys())}d.keys=n;function a(){h.clear();}d.clear=a;})(R||={});var L=R;var o=class i{constructor(){}static choiceMadeTemp=void 0;static lastHistoryStep=null;static get allOpenedLabels(){return GameUnifier.getVariable(l,n.OPENED_LABELS_COUNTER_KEY)||{}}static set allOpenedLabels(e){GameUnifier.setVariable(l,n.OPENED_LABELS_COUNTER_KEY,e);}static getCurrentStepTimesCounterData(e$1=""){let t=i.currentLabelStepIndex;if(t===null)return e.error("currentLabelStepIndex is null"),null;let r=`${t}${e$1}`,n$1=i.currentLabelId,a=i._currentLabel;if(!n$1||t===null||!a)return e.error("currentLabelId or currentLabelStepIndex is null or currentLabel not found"),null;let d=a.getStepSha(t)||"error",l$1=GameUnifier.getVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY)||{};return l$1[n$1]||(l$1[n$1]={}),(!l$1[n$1][r]||l$1[n$1][r].stepSha1!==d)&&(l$1[n$1][r]={stepSha1:d}),l$1[n$1][r]}static setCurrentStepTimesCounterData(e$1="",t){let r=i.currentLabelStepIndex,n$1=r+e$1,a=i.currentLabelId;if(!a||r===null){e.error("currentLabelId or currentLabelStepIndex is null");return}let d=GameUnifier.getVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY)||{};d[a]||(d[a]={}),d[a][n$1]=t,GameUnifier.setVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY,d);}static getCurrentStepTimesCounter(e$1=""){let t=i._stepCounter,r=i.getCurrentStepTimesCounterData(e$1);if(!r)return e.error("getCurrentStepTimesCounter obj is null"),0;let n=r.stepCounters||[];return n.find(d=>d===t)||(n.push(t),r.stepCounters=n,i.setCurrentStepTimesCounterData(e$1,r)),n.length}static getRandomNumber(e,t,r={}){let n=r.nestedId||"";if(r.onceOnly||false){let d=i.getCurrentStepTimesCounterData(n);if(!d)return;let l=d.usedRandomNumbers||{},f=Array.from({length:t-e+1},(E,N)=>N+e).filter(E=>!l[`${e}-${t}`]?.includes(E));if(f.length===0)return;let S=Math.floor(Math.random()*f.length),b=f[S];return l[`${e}-${t}`]||(l[`${e}-${t}`]=[]),l[`${e}-${t}`].push(b),d.usedRandomNumbers=l,i.setCurrentStepTimesCounterData(n,d),b}return Math.floor(Math.random()*(t-e+1))+e}static resetCurrentStepTimesCounter(e$1=""){let t=i.currentLabelStepIndex,r=t+e$1,n$1=i.currentLabelId;if(!n$1||t===null){e.error("currentLabelId or currentLabelStepIndex is null");return}let a=GameUnifier.getVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY)||{};a[n$1]||(a[n$1]={}),a[n$1][r]={stepCounters:[],stepSha1:""},GameUnifier.setVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY,a);}static get allChoicesMade(){return GameUnifier.getVariable(l,n.ALL_CHOICES_MADE_KEY)||[]}static set allChoicesMade(e){GameUnifier.setVariable(l,n.ALL_CHOICES_MADE_KEY,e);}static _stepCounter=0;static increaseStepCounter(){i._stepCounter++;}static _openedLabels=[];static get openedLabels(){return f(i._openedLabels)}static set openedLabels(e){i._openedLabels=f(e);}static _originalOpenedLabels=[];static get originalOpenedLabels(){return f(i._originalOpenedLabels)}static set originalOpenedLabels(e){i._originalOpenedLabels=f(e);}static get _currentLabel(){if(i.currentLabelId)return L.get(i.currentLabelId)}static get currentLabelId(){if(i._openedLabels.length>0)return i._openedLabels[i._openedLabels.length-1].label}static get currentLabelStepIndex(){return i._openedLabels.length>0?i._openedLabels[i._openedLabels.length-1].currentStepIndex:null}static addLabelHistory(e,t){let r=i.allOpenedLabels,n=i.allOpenedLabels[e]?.biggestStep||0,a=i.allOpenedLabels[e]?.openCount||0;(!n||n<t)&&(r[e]={biggestStep:t,openCount:a},i.allOpenedLabels=r);}static addChoicesMade(e,t,r,n){let a=i.allChoicesMade,d=a.findIndex(l=>l.labelId===e&&l.stepIndex===t&&l.choiceIndex===n&&l.stepSha1===r);d<0?a.push({labelId:e,stepIndex:t,choiceIndex:n,stepSha1:r,madeTimes:1}):a[d].madeTimes++,i.allChoicesMade=a;}static pushNewLabel(e){if(!L.get(e))throw new PixiError("unregistered_element",`Label ${e} not found`);i._openedLabels.push({label:e,currentStepIndex:0});let r=i.allOpenedLabels,n=i.allOpenedLabels[e]?.biggestStep||0,a=i.allOpenedLabels[e]?.openCount||0;r[e]={biggestStep:n,openCount:a+1},i.allOpenedLabels=r;}static increaseCurrentStepIndex(){if(i._openedLabels.length>0){let e=i._openedLabels[i._openedLabels.length-1];i._openedLabels[i._openedLabels.length-1]={...e,currentStepIndex:e.currentStepIndex+1};}}static _onStepStart;static set onStepStart(e){i._onStepStart=e;}static get onStepStart(){return async(e,t)=>{let r=[];return i.onLoadingLabel&&e===0&&r.push(i.onLoadingLabel(e,t)),i._onStepStart&&r.push(i._onStepStart(e,t)),await Promise.all(r)}}static onLoadingLabel;static onStepEnd};var C=class{get currentStepTimesCounter(){return o.getCurrentStepTimesCounter()}set currentStepTimesCounter(e){o.resetCurrentStepTimesCounter();}getRandomNumber(e,t,r={}){return o.getRandomNumber(e,t,r)}get stepCounter(){return o._stepCounter}get openedLabels(){return o.openedLabels}get currentLabel(){return o._currentLabel}addStepHistory(e,t={}){let{choiceMade:r,ignoreSameStep:n$1}=t,a,d,l$1,f=GameUnifier.getVariable(l,n.LAST_STEP_GLUED)===this.stepCounter;GameUnifier.getVariable(l,n.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(a=GameUnifier.getVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY)),GameUnifier.getVariable(l,n.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(d=GameUnifier.getVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY)),GameUnifier.getVariable(l,n.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(l$1=GameUnifier.getVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY));let S=o.openedLabels,b={currentLabel:o.currentLabelId,dialogue:a,choices:d,stepSha1:e,index:this.stepCounter,labelStepIndex:o.currentLabelStepIndex,choiceIndexMade:r,inputValue:l$1,alreadyMadeChoices:this.alreadyCurrentStepMadeChoices,isGlued:f,openedLabels:S};o.originalOpenedLabels=S,GameUnifier.addHistoryItem(b,{ignoreSameStep:n$1}),o.lastHistoryStep=b,o.increaseStepCounter();}closeCurrentLabel(){if(!o.currentLabelId){e.warn("No label to close");return}if(!this.currentLabel){e.error("currentLabel not found");return}let e$1=o.openedLabels;e$1.pop(),o.openedLabels=e$1,GameUnifier.onLabelClosing(this.openedLabels.length);}closeAllLabels(){for(;o.openedLabels.length>0;)this.closeCurrentLabel(),GameUnifier.onLabelClosing(this.openedLabels.length);}isLabelAlreadyCompleted(e){let t;typeof e=="string"?t=e:t=e.id;let n=o.allOpenedLabels[t]?.biggestStep||0;if(n){let a=L.get(t);if(a)return a.stepCount<=n}return false}get alreadyCurrentStepMadeChoicesObj(){let e$1=o.currentLabelStepIndex,t=this.currentLabel;if(e$1===null||!t)return;let r=t.getStepSha(e$1);return r||(e.warn("stepSha not found, setting to ERROR"),r="error"),o.allChoicesMade.filter(n=>n.labelId===t?.id&&n.stepIndex===e$1&&n.stepSha1===r)}get alreadyCurrentStepMadeChoices(){return this.alreadyCurrentStepMadeChoicesObj?.map(e=>e.choiceIndex)}get isCurrentStepAlreadyOpened(){let e=o.currentLabelId;if(e){let t=o.allOpenedLabels[e]?.openCount||0;if(o.currentLabelStepIndex&&t>=o.currentLabelStepIndex)return true}return false}getTimesLabelOpened(e){return o.allOpenedLabels[e]?.openCount||0}getTimesChoiceMade(e){return this.alreadyCurrentStepMadeChoicesObj?.find(t=>t.choiceIndex===e)?.madeTimes||0}addCurrentStepToHistory(){this.addStepHistory("dev",{ignoreSameStep:true});}getCanContinue(e$1){let t=e$1?.showWarn||false,r=this.choices;return r&&r.length>0?(t&&e.warn("The player must make a choice"),false):this.isRequiredInput?(t&&e.warn("The player must enter a value"),false):true}get canContinue(){return GameUnifier.runningStepsCount!==0?false:this.getCanContinue()}async onStepStart(e,t){let r=[];return e.onStepStart&&r.push(e.onStepStart(t,e)),o.onStepStart&&r.push(o.onStepStart(t,e)),await Promise.all(r)}async onStepEnd(e,t){let r=[];return e.onStepEnd&&r.push(e.onStepEnd(t,e)),o.onStepEnd&&r.push(o.onStepEnd(t,e)),await Promise.all(r)}async continue(e$1,t={}){let{runNow:r=false,steps:n=1}=t;if(!Number.isFinite(n)){e.warn(`[continue] The parameter steps must be a valid finite number, received: ${n}`);return}if(n<=0){e.warn(`[continue] The parameter steps must be greater than 0, received: ${n}`);return}if(!r&&!this.getCanContinue({showWarn:true}))return;if(!r&&GameUnifier.runningStepsCount!==0){GameUnifier.increaseContinueRequest(n);return}n>1&&GameUnifier.increaseContinueRequest(n-1),GameUnifier.runningStepsCount++;let a;try{GameUnifier.runningStepsCount===1&&await GameUnifier.onPreContinue(),o.increaseCurrentStepIndex(),a=await this.runCurrentStep(e$1,t);}catch(d){throw e.error("Error continuing",d),d}return GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(e$1)||a}async afterRunCurrentStep(e$1){if(GameUnifier.runningStepsCount===0&&GameUnifier.continueRequestsCount!==0)return await GameUnifier.processNavigationRequests(e$1);if(this.openedLabels.length===0){if(GameUnifier.onEnd)return await GameUnifier.onEnd(e$1,{labelId:"end"});e.error("The end of the game is not managed, so the game is blocked. Read this documentation to know how to manage the end of the game: https://pixi-vn.com/start/other-narrative-features.html#how-manage-the-end-of-the-game");}}async runCurrentStep(e$1,t={}){let{choiceMade:r}=t;if(o.currentLabelId){let n=o.currentLabelStepIndex;if(n===null){e.error("currentLabelStepIndex is null");return}let a=o._currentLabel;if(!a){e.error("currentLabel not found");return}if(a.stepCount>n){try{await this.onStepStart(a,n);}catch(b){e.error("Error running onStepStart",b),this.onStepError&&await this.onStepError(b,e$1);return}let d=a.getStepById(n);if(!d){e.error("step not found");return}let l=a.getStepSha(n);l||(e.warn("stepSha not found, setting to ERROR"),l="error");let f,S;try{f=await d(e$1,{labelId:a.id});}catch(b){e.error("Error running step",b),S=b;}try{let b=this.choices;if(b?.length===1&&b[0].autoSelect){let E=b[0];f=await this.selectChoice(E,e$1);}}catch(b){e.error("Error auto-selecting choice",b),S||(S=b);}try{let b=o.lastHistoryStep;r!==void 0&&b&&(l=b.stepSha1,l||(e.warn("stepSha not found, setting to ERROR"),l="error"),o.addChoicesMade(b.currentLabel||"error",typeof b.labelStepIndex=="number"?b.labelStepIndex:-1,b.stepSha1||"error",r),o.choiceMadeTemp=r);}catch(b){e.warn("Error adding choice made to history",b);}try{GameUnifier.runningStepsCount===1&&(o.addLabelHistory(a.id,n),this.addStepHistory(l,{...t,choiceMade:o.choiceMadeTemp}),o.choiceMadeTemp=void 0);}catch(b){e.warn("Error adding step to history",b);}try{this.currentLabel&&await this.onStepEnd(this.currentLabel,o.currentLabelStepIndex||0);}catch(b){e.warn("Error running onStepEnd",b);}return S&&this.onStepError&&await this.onStepError(S,e$1),f}else {if(this.openedLabels.length>1)return this.closeCurrentLabel(),await this.continue(e$1,t);if(this.openedLabels.length===1){o.openedLabels=[];return}}}else {if(this.openedLabels.length===0)return;e.error("currentLabelId not found");}}async call(e$1,t,r){let{choiceMade:n}=r||{},a;typeof e$1=="string"?a=e$1:a=e$1.id,GameUnifier.runningStepsCount++;let d;try{let l=L.get(a);if(!l)throw new PixiError("unregistered_element",`Label ${a} not found`);o.pushNewLabel(l.id),d=await this.runCurrentStep(t,{choiceMade:n});}catch(l){throw e.error("Error calling label",l),l}return GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(t)||d}async jump(e$1,t,r){if(this.stepCounter===0)return await this.call(e$1,t,r);this.openedLabels.length>0&&this.closeCurrentLabel();let{choiceMade:n}=r||{},a;typeof e$1=="string"?a=e$1:a=e$1.id,GameUnifier.runningStepsCount++;let d;try{let l=L.get(a);if(!l)throw new PixiError("unregistered_element",`Label ${a} not found`);o.pushNewLabel(l.id),d=await this.runCurrentStep(t,{choiceMade:n});}catch(l){throw e.error("Error jumping to label",l),l}return GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(t)||d}async selectChoice(e$1,t){this.choices=void 0;let r=e$1.type;switch(r){case "call":return await this.call(e$1.label,{...e$1.props,...t},{choiceMade:e$1.choiceIndex});case "jump":return await this.jump(e$1.label,{...e$1.props,...t},{choiceMade:e$1.choiceIndex});case "close":return await this.closeChoiceMenu(e$1,{...e$1.props,...t});default:throw e.error(`Type ${r} not found`),new PixiError("invalid_usage",`Type ${r} not found`)}}async closeChoiceMenu(e$1,t){if(e$1.type!=="close")throw e.error("For closeChoiceMenu, the type must be close"),new PixiError("invalid_usage","For closeChoiceMenu, the type must be close");let r;return typeof e$1.choiceIndex=="number"&&(r=e$1.choiceIndex),e$1.closeCurrentLabel&&this.closeCurrentLabel(),await this.continue(t,{choiceMade:r})}get onStepError(){return async(e$1,t)=>{try{await GameUnifier.runOnError(e$1,t);}catch(r){e.error("Error in onError handler",r);}}}get dialogue(){let e=GameUnifier.getVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY);if(e)return {...e,character:e.character?GameUnifier.getCharacter(e.character)||e.character:void 0}}set dialogue(e$1){if(e$1===void 0){GameUnifier.setVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY,void 0);return}if((typeof e$1=="string"||Array.isArray(e$1))&&(e$1={text:e$1}),this.dialogGlue){let t=GameUnifier.getVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY);if(t){let r=[];Array.isArray(t.text)?r=[...t.text]:r=[t.text],Array.isArray(e$1.text)?r=[...r,...e$1.text]:r=[...r,e$1.text],e$1.text=r,e$1.character=e$1.character||t.character;}GameUnifier.setVariable(l,n.LAST_STEP_GLUED,this.stepCounter),this.dialogGlue=false;}try{GameUnifier.setVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY,f({...e$1,character:typeof e$1.character=="string"?e$1.character:e$1.character?.id})),GameUnifier.setVariable(l,n.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw e.error("DialogueInterface cannot contain functions or classes"),new PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}get choices(){let e=GameUnifier.getVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY);if(e){let t=[],r=e.map((a,d)=>({...a,choiceIndex:d})),n=this.alreadyCurrentStepMadeChoices;if(r=r.filter((a,d)=>a.oneTime&&n?.includes(d)?false:a.onlyHaveNoChoice?(t.push(a),false):true),r.length>0)return r;if(t.length>0)return [t[0]]}}set choices(e$1){if(!e$1||e$1.length===0){GameUnifier.setVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY,void 0);return}try{GameUnifier.setVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY,f(e$1)),GameUnifier.setVariable(l,n.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw e.error("ChoiceInterface cannot contain functions or classes"),new PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}get dialogGlue(){return GameUnifier.getFlag(n.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY)}set dialogGlue(e){GameUnifier.setFlag(n.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,e);}get inputValue(){return GameUnifier.getVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY)}set inputValue(e){this.removeInputRequest(),GameUnifier.setVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY,e),GameUnifier.setVariable(l,n.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}get isRequiredInput(){return GameUnifier.getVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY)?.isRequired||false}get inputType(){return GameUnifier.getVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY)?.type}requestInput(e,t){e.isRequired=true,GameUnifier.setVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY,e),t!==void 0?GameUnifier.setVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY,t):GameUnifier.removeVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY);}removeInputRequest(){GameUnifier.removeVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY),GameUnifier.removeVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY);}clear(){o.openedLabels=[],o._stepCounter=0;}export(){return {openedLabels:f(o.openedLabels),stepCounter:this.stepCounter}}async onLoadingLabel(e){let t=this.openedLabels.map(async r=>{let n=[],a=L.get(r.label);return a&&(a.onLoadingLabel&&n.push(a.onLoadingLabel(e,a)),o.onLoadingLabel&&n.push(o.onLoadingLabel(e,a))),await Promise.all(n)});return await Promise.all(t)}async restore(e$1,t){this.clear();try{o.lastHistoryStep=t,Object.hasOwn(e$1,"openedLabels")?(o.openedLabels=e$1.openedLabels,o.originalOpenedLabels=o.openedLabels):e.warn("Could not import openedLabels data, so will be ignored"),Object.hasOwn(e$1,"stepCounter")?o._stepCounter=e$1.stepCounter:e.warn("Could not import stepCounter data, so will be ignored");try{await this.onLoadingLabel(o.currentLabelStepIndex||0);}catch(r){e.error("Error running onLoadingLabel",r);}}catch(r){e.error("Error importing data",r);}}};function D(i,e,t,r){let n=typeof e=="string"?e:e.id;return {...r,label:n,props:t,text:i,type:r?.type||"call"}}var O="close";function U(i,e){return {...e,type:O,text:i}}var M=c(a(),1);var g=class{constructor(e,t){this.id=e,this._onStepStart=t?.onStepStart,this._onLoadingLabel=t?.onLoadingLabel,this._onStepEnd=t?.onStepEnd;}id;_onStepStart;get onStepStart(){return async(e,t)=>{if(this._onLoadingLabel&&e===0&&await this._onLoadingLabel(e,t),this._onStepStart)return await this._onStepStart(e,t)}}_onLoadingLabel;get onLoadingLabel(){return this._onLoadingLabel}_onStepEnd;get onStepEnd(){return this._onStepEnd}};var I=class extends g{get stepCount(){return this.steps.length}getStepById(e){return this.steps[e]}constructor(e,t,r){super(e,r),this._steps=t;}_steps;get steps(){return typeof this._steps=="function"?this._steps():this._steps}getStepSha(e$1){if(e$1<0||e$1>=this.steps.length)return e.warn("stepSha not found, setting to ERROR"),"error";try{let t=this.steps[e$1];return (0,M.default)(t.toString().toLocaleLowerCase()).toString()}catch(t){return e.warn("stepSha not found, setting to ERROR",t),"error"}}};function x(i,e,t){let r=new I(i,e,t);return L.add(r),r}var fe=new C;
|
|
2
2
|
export{I as Label,g as LabelAbstract,o as NarrationManagerStatic,L as RegisteredLabels,fe as narration,D as newChoiceOption,U as newCloseChoiceOption,x as newLabel};
|