@drincs/pixi-vn 1.8.25 → 1.9.0

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.
Files changed (53) hide show
  1. package/README.md +23 -1
  2. package/dist/{ContainerMemory-D2HtgX7w.d.cts → ContainerMemory-BpDgacyr.d.cts} +2 -15
  3. package/dist/{ContainerMemory-D2HtgX7w.d.ts → ContainerMemory-BpDgacyr.d.ts} +2 -15
  4. package/dist/{HistoryChoiceMenuOption-DVMD78W7.d.cts → HistoryChoiceMenuOption-BxMSXnyI.d.cts} +1 -1
  5. package/dist/{HistoryChoiceMenuOption-B8RfQz5H.d.ts → HistoryChoiceMenuOption-hSI4SHV-.d.ts} +1 -1
  6. package/dist/{HistoryGameState-CmjUtlkV.d.ts → HistoryGameState-C8ATx9K6.d.ts} +1 -1
  7. package/dist/{HistoryGameState-C28NcKKl.d.cts → HistoryGameState-CGfvq5iL.d.cts} +1 -1
  8. package/dist/{HistoryStep-G9dUn0Lf.d.cts → HistoryStep-WGB6nA4N.d.cts} +5 -0
  9. package/dist/{HistoryStep-G9dUn0Lf.d.ts → HistoryStep-WGB6nA4N.d.ts} +5 -0
  10. package/dist/{OpenedLabel-DLfFuZgk.d.ts → OpenedLabel-CmRdzTXP.d.ts} +1 -1
  11. package/dist/{OpenedLabel-BxfL31aQ.d.cts → OpenedLabel-Cmd675NI.d.cts} +1 -1
  12. package/dist/SoundGameState-C_6ZsQX6.d.cts +186 -0
  13. package/dist/SoundGameState-C_6ZsQX6.d.ts +186 -0
  14. package/dist/{StorageGameState-CtjNJpvE.d.cts → StorageGameState-C3PGrFPr.d.cts} +2 -2
  15. package/dist/{StorageGameState-BJy57o6K.d.ts → StorageGameState-jAexrJLj.d.ts} +2 -2
  16. package/dist/canvas.cjs +2 -2
  17. package/dist/canvas.d.cts +265 -24
  18. package/dist/canvas.d.ts +265 -24
  19. package/dist/canvas.mjs +2 -2
  20. package/dist/characters.cjs +1 -1
  21. package/dist/characters.mjs +1 -1
  22. package/dist/chunk-HD353M4B.mjs +1 -0
  23. package/dist/chunk-I7DOUH5V.mjs +1 -0
  24. package/dist/history.cjs +1 -1
  25. package/dist/history.d.cts +38 -15
  26. package/dist/history.d.ts +38 -15
  27. package/dist/history.mjs +1 -1
  28. package/dist/index.cjs +2 -2
  29. package/dist/index.d.cts +32 -34
  30. package/dist/index.d.ts +32 -34
  31. package/dist/index.mjs +2 -2
  32. package/dist/motion.cjs +1 -1
  33. package/dist/motion.mjs +1 -1
  34. package/dist/narration.cjs +2 -2
  35. package/dist/narration.d.cts +196 -52
  36. package/dist/narration.d.ts +196 -52
  37. package/dist/narration.mjs +2 -2
  38. package/dist/pixi/browser.js +115 -115
  39. package/dist/sound.cjs +1 -1
  40. package/dist/sound.d.cts +313 -6
  41. package/dist/sound.d.ts +313 -6
  42. package/dist/sound.mjs +1 -1
  43. package/dist/storage.cjs +1 -1
  44. package/dist/storage.d.cts +50 -3
  45. package/dist/storage.d.ts +50 -3
  46. package/dist/storage.mjs +1 -1
  47. package/dist/vite.cjs +2 -2
  48. package/dist/vite.mjs +2 -2
  49. package/package.json +2 -1
  50. package/dist/SoundManagerInterface-Dd0b88_N.d.cts +0 -436
  51. package/dist/SoundManagerInterface-Dd0b88_N.d.ts +0 -436
  52. package/dist/chunk-GIYMPXBT.mjs +0 -1
  53. package/dist/chunk-IWAXXFXE.mjs +0 -1
@@ -1,14 +1,156 @@
1
1
  import { S as StorageElementType, a as StorageObjectType } from './StorageElementType-C7ETezlL.js';
2
- import { L as LabelIdType, D as DialogueInterface, H as HistoryStep } from './HistoryStep-G9dUn0Lf.js';
3
- export { P as PixivnLabelIds } from './HistoryStep-G9dUn0Lf.js';
2
+ import { L as LabelIdType, D as DialogueInterface, H as HistoryStep } from './HistoryStep-WGB6nA4N.js';
3
+ export { P as PixivnLabelIds } from './HistoryStep-WGB6nA4N.js';
4
4
  import { ChoiceInterface as ChoiceInterface$1 } from '@drincs/pixi-vn';
5
- import { L as LabelRunModeType, C as CloseType } from './HistoryChoiceMenuOption-B8RfQz5H.js';
6
- export { H as HistoryChoiceMenuOption, N as NarrationHistory } from './HistoryChoiceMenuOption-B8RfQz5H.js';
5
+ import { L as LabelRunModeType, C as CloseType } from './HistoryChoiceMenuOption-hSI4SHV-.js';
6
+ export { H as HistoryChoiceMenuOption, N as NarrationHistory } from './HistoryChoiceMenuOption-hSI4SHV-.js';
7
7
  import { S as StepLabelPropsType, a as StepLabelResultType, b as StepLabelType } from './StepLabelType-CN97wZzm.js';
8
- import { O as OpenedLabel } from './OpenedLabel-DLfFuZgk.js';
8
+ import { O as OpenedLabel } from './OpenedLabel-CmRdzTXP.js';
9
9
  import { LabelProps as LabelProps$1 } from '@drincs/pixi-vn/canvas';
10
10
  import 'microdiff';
11
11
 
12
+ interface ChoiceOptionInterface extends Omit<ChoiceInterface$1, "label" | "type" | "closeCurrentLabel"> {
13
+ /**
14
+ * Label Id to be opened when the option is selected
15
+ */
16
+ label: LabelIdType;
17
+ /**
18
+ * Type of the label to be opened
19
+ */
20
+ type: LabelRunModeType;
21
+ }
22
+ interface CloseChoiceOptionInterface extends Omit<ChoiceInterface$1, "label" | "type" | "closeCurrentLabel"> {
23
+ /**
24
+ * Type of the label to be opened
25
+ */
26
+ type: CloseType;
27
+ /**
28
+ * If true, the current label will be closed
29
+ */
30
+ closeCurrentLabel?: boolean;
31
+ }
32
+ type StoredChoiceInterface = ChoiceOptionInterface | CloseChoiceOptionInterface;
33
+ type StoredIndexedChoiceInterface = StoredChoiceInterface & {
34
+ /**
35
+ * Is the index of the choice in the menu. It is used to identify the choice when it is selected.
36
+ */
37
+ choiceIndex: number;
38
+ };
39
+
40
+ interface NarrationChoicesInterface {
41
+ /**
42
+ * The choices to be shown in the game.
43
+ */
44
+ get list(): StoredIndexedChoiceInterface[] | undefined;
45
+ /**
46
+ * The choices to be shown in the game.
47
+ * @throws {PixiError} when a choice contains functions or class instances that cannot be serialized to JSON.
48
+ */
49
+ set list(data: StoredChoiceInterface[] | undefined);
50
+ /**
51
+ * Select a choice from the choice menu, and close the choice menu.
52
+ * @param item The choice item selected by the player.
53
+ * @param props The props to pass to the label.
54
+ * @returns StepLabelResultType or undefined.
55
+ * @throws {PixiError} when the choice type is not `"call"`, `"jump"`, or `"close"`.
56
+ * @example
57
+ * ```ts
58
+ * narration.choices.select(item, {
59
+ * navigate: navigate,
60
+ * // your props
61
+ * ...item.props
62
+ * })
63
+ * .then(() => {
64
+ * // your code
65
+ * })
66
+ * .catch((e) => {
67
+ * // your code
68
+ * })
69
+ * ```
70
+ */
71
+ select<T extends {}>(item: StoredIndexedChoiceInterface, props: StepLabelPropsType<T>): Promise<StepLabelResultType>;
72
+ }
73
+
74
+ type InputInfo = {
75
+ isRequired?: boolean;
76
+ type?: string;
77
+ };
78
+
79
+ interface NarrationInputInterface {
80
+ /**
81
+ * The input value to be inserted by the player.
82
+ */
83
+ value: StorageElementType;
84
+ /**
85
+ * If true, the player must enter a value.
86
+ */
87
+ readonly isRequired: boolean;
88
+ /**
89
+ * Returns the type of input prompt requested.
90
+ */
91
+ readonly type: string | undefined;
92
+ /**
93
+ * Returns `true` if the player must enter a value.
94
+ * @param info The input value to be inserted by the player.
95
+ * @param defaultValue The default value to be inserted.
96
+ */
97
+ request(info?: Omit<InputInfo, "isRequired">, defaultValue?: StorageElementType): void;
98
+ /**
99
+ * Remove the input request.
100
+ */
101
+ removeRequest(): void;
102
+ }
103
+
104
+ interface NarrationLabelsInterface {
105
+ /**
106
+ * The stack of the opened labels.
107
+ */
108
+ readonly opened: OpenedLabel[];
109
+ /**
110
+ * currentLabel is the current label that occurred during the progression of the steps.
111
+ */
112
+ readonly current: LabelAbstract<any> | undefined;
113
+ /**
114
+ * Close the current label and add it to the history.
115
+ */
116
+ closeCurrent(): void;
117
+ /**
118
+ * Close all labels and add them to the history. **Attention: This method can cause an unhandled game ending.**
119
+ */
120
+ closeAll(): void;
121
+ }
122
+
123
+ interface NarrationQueriesInterface {
124
+ /**
125
+ * Check if the label is already completed.
126
+ * @param label The label to check.
127
+ * @returns True if the label is already completed.
128
+ */
129
+ isLabelAlreadyCompleted(label: LabelIdType | LabelAbstract<any>): boolean;
130
+ /**
131
+ * Get the choices already made in the current step. **Attention**: if the choice step index is edited or the code of choice step is edited, the result will be wrong.
132
+ * @returns The choices already made in the current step. If there are no choices, it will return undefined.
133
+ */
134
+ readonly alreadyCurrentStepMadeChoices: number[] | undefined;
135
+ /**
136
+ * Check if the current step is already completed.
137
+ * @returns True if the current step is already completed.
138
+ */
139
+ readonly isCurrentStepAlreadyOpened: boolean;
140
+ /**
141
+ * Get times a label has been opened.
142
+ * @param label The label to check.
143
+ * @returns times a label has been opened.
144
+ */
145
+ timesLabelOpened(label: LabelIdType): number;
146
+ /**
147
+ * Get times a choice has been made in the current step.
148
+ * @param index The index of the choice.
149
+ * @returns The number of times the choice has been made.
150
+ */
151
+ timesChoiceMade(index: number): number;
152
+ }
153
+
12
154
  interface NarrationManagerInterface {
13
155
  /**
14
156
  * Counter of execution times of the current step. Current execution is also included. Starts from 1.
@@ -43,52 +185,73 @@ interface NarrationManagerInterface {
43
185
  readonly stepCounter: number;
44
186
  /**
45
187
  * The stack of the opened labels.
188
+ * @deprecated Use {@link labels}.opened instead.
46
189
  */
47
190
  readonly openedLabels: OpenedLabel[];
48
191
  /**
49
192
  * currentLabel is the current label that occurred during the progression of the steps.
193
+ * @deprecated Use {@link labels}.current instead.
50
194
  */
51
195
  readonly currentLabel: LabelAbstract<any> | undefined;
52
196
  /**
53
197
  * Close the current label and add it to the history.
54
198
  * @returns
199
+ * @deprecated Use {@link labels}.closeCurrent instead.
55
200
  */
56
201
  closeCurrentLabel(): void;
57
202
  /**
58
203
  * Close all labels and add them to the history. **Attention: This method can cause an unhandled game ending.**
204
+ * @deprecated Use {@link labels}.closeAll instead.
59
205
  */
60
206
  closeAllLabels(): void;
61
207
  /**
62
208
  * Check if the label is already completed.
63
209
  * @param label The label to check.
64
210
  * @returns True if the label is already completed.
211
+ * @deprecated Use {@link queries}.isLabelAlreadyCompleted instead.
65
212
  */
66
213
  isLabelAlreadyCompleted(label: LabelIdType | LabelAbstract<any>): boolean;
67
214
  /**
68
215
  * Get the choices already made in the current step. **Attention**: if the choice step index is edited or the code of choice step is edited, the result will be wrong.
69
216
  * @returns The choices already made in the current step. If there are no choices, it will return undefined.
217
+ * @deprecated Use {@link queries}.alreadyCurrentStepMadeChoices instead.
70
218
  */
71
219
  readonly alreadyCurrentStepMadeChoices: number[] | undefined;
72
220
  /**
73
221
  * Check if the current step is already completed.
74
222
  * @returns True if the current step is already completed.
223
+ * @deprecated Use {@link queries}.isCurrentStepAlreadyOpened instead.
75
224
  */
76
225
  readonly isCurrentStepAlreadyOpened: boolean;
77
226
  /**
78
227
  * Get times a label has been opened
79
228
  * @returns times a label has been opened
229
+ * @deprecated Use {@link queries}.timesLabelOpened instead.
80
230
  */
81
231
  getTimesLabelOpened(label: LabelIdType): number;
82
232
  /**
83
233
  * Get times a choice has been made in the current step.
84
234
  * @param index The index of the choice.
85
235
  * @returns The number of times the choice has been made.
236
+ * @deprecated Use {@link queries}.timesChoiceMade instead.
86
237
  */
87
238
  getTimesChoiceMade(index: number): number;
88
239
  /**
89
240
  * Save the current step to the history.
90
241
  */
91
242
  addCurrentStepToHistory(): void;
243
+ /**
244
+ * Namespace for operations on the input requested to the player.
245
+ */
246
+ readonly input: NarrationInputInterface;
247
+ /**
248
+ * Namespace for operations on the opened labels.
249
+ */
250
+ readonly labels: NarrationLabelsInterface;
251
+ /**
252
+ * Namespace for queries about the current state of the narration.
253
+ */
254
+ readonly queries: NarrationQueriesInterface;
92
255
  /**
93
256
  * Return if can go to the next step. It's `false` when:
94
257
  * - A `step` is running
@@ -200,6 +363,7 @@ interface NarrationManagerInterface {
200
363
  * // your code
201
364
  * })
202
365
  * ```
366
+ * @deprecated Use {@link choices}.select instead.
203
367
  */
204
368
  selectChoice<T extends {}>(item: StoredIndexedChoiceInterface, props: StepLabelPropsType<T>): Promise<StepLabelResultType>;
205
369
  /** Old Step Methods */
@@ -213,21 +377,11 @@ interface NarrationManagerInterface {
213
377
  */
214
378
  set dialogue(props: DialogueInterface | string | string[] | undefined);
215
379
  /**
216
- * The options to be shown in the game
217
- * @example
218
- * ```ts
219
- * narration.choices = [
220
- * newChoiceOption("Events Test", EventsTestLabel, {}),
221
- * newChoiceOption("Show Image Test", ShowImageTest, { image: "imageId" }, "call"),
222
- * newChoiceOption("Ticker Test", TickerTestLabel, {}),
223
- * newChoiceOption("Tinting Test", TintingTestLabel, {}, "jump"),
224
- * newChoiceOption("Base Canvas Element Test", BaseCanvasElementTestLabel, {})
225
- * ]
226
- * ```
380
+ * Namespace for operations on the choices to be shown in the game.
227
381
  */
228
- get choices(): StoredIndexedChoiceInterface[] | undefined;
382
+ get choices(): NarrationChoicesInterface;
229
383
  /**
230
- * The options to be shown in the game
384
+ * Shortcut for {@link NarrationChoicesInterface.list}.
231
385
  * @throws {PixiError} when a choice contains functions or class instances that cannot be serialized to JSON.
232
386
  * @example
233
387
  * ```ts
@@ -247,24 +401,29 @@ interface NarrationManagerInterface {
247
401
  dialogGlue: boolean;
248
402
  /**
249
403
  * The input value to be inserted by the player.
404
+ * @deprecated Use {@link input}.value instead.
250
405
  */
251
406
  inputValue: StorageElementType;
252
407
  /**
253
408
  * If true, the player must enter a value.
409
+ * @deprecated Use {@link input}.isRequired instead.
254
410
  */
255
411
  readonly isRequiredInput: boolean;
256
412
  /**
257
413
  * Returns the type of input prompt requested.
414
+ * @deprecated Use {@link input}.type instead.
258
415
  */
259
416
  readonly inputType: string | undefined;
260
417
  /**
261
418
  * Returns `true` if the player must enter a value.
262
419
  * @param info The input value to be inserted by the player.
263
420
  * @param defaultValue The default value to be inserted.
421
+ * @deprecated Use {@link input}.request instead.
264
422
  */
265
423
  requestInput(info?: Omit<InputInfo, "isRequired">, defaultValue?: StorageElementType): void;
266
424
  /**
267
425
  * Remove the input request.
426
+ * @deprecated Use {@link input}.removeRequest instead.
268
427
  */
269
428
  removeInputRequest(): void;
270
429
  /**
@@ -283,34 +442,6 @@ interface NarrationManagerInterface {
283
442
  restore(data: object, lastHistoryStep: Omit<HistoryStep, "diff"> | null): Promise<void>;
284
443
  }
285
444
 
286
- interface ChoiceOptionInterface extends Omit<ChoiceInterface$1, "label" | "type" | "closeCurrentLabel"> {
287
- /**
288
- * Label Id to be opened when the option is selected
289
- */
290
- label: LabelIdType;
291
- /**
292
- * Type of the label to be opened
293
- */
294
- type: LabelRunModeType;
295
- }
296
- interface CloseChoiceOptionInterface extends Omit<ChoiceInterface$1, "label" | "type" | "closeCurrentLabel"> {
297
- /**
298
- * Type of the label to be opened
299
- */
300
- type: CloseType;
301
- /**
302
- * If true, the current label will be closed
303
- */
304
- closeCurrentLabel?: boolean;
305
- }
306
- type StoredChoiceInterface = ChoiceOptionInterface | CloseChoiceOptionInterface;
307
- type StoredIndexedChoiceInterface = StoredChoiceInterface & {
308
- /**
309
- * Is the index of the choice in the menu. It is used to identify the choice when it is selected.
310
- */
311
- choiceIndex: number;
312
- };
313
-
314
445
  interface LabelProps<T, StepIdType = number> {
315
446
  /**
316
447
  * A function executed before each `step`.
@@ -729,13 +860,26 @@ declare class NarrationManagerStatic {
729
860
  closeCurrentLabel?: boolean;
730
861
  type: string;
731
862
  }, defaultStart: () => Promise<StepLabelResultType>) => StepLabelResultType | Promise<StepLabelResultType>;
863
+ /**
864
+ * Is a function that will be executed every time the current label is about to close because it
865
+ * naturally ran out of steps - either control is returning to the label that called it, or, if
866
+ * there's no parent label left on the stack, the game is about to end (see {@link Game.onEnd}).
867
+ *
868
+ * By default (when this is not set), the label is closed immediately, exactly like before this
869
+ * hook existed. If you set it, you take control: call `defaultClose()` yourself whenever you want
870
+ * the label to actually close (right away, or later, e.g. from a subsequent `next()`-like action in
871
+ * your template). Until `defaultClose()` is called, the label stays open: it is not popped off the
872
+ * opened labels stack, narration does not continue into the parent label, and the game does not end
873
+ * even if this was the last label - this is what lets an app show the final paragraph of a story
874
+ * before actually ending it, instead of both happening within the same `continue()` call.
875
+ *
876
+ * This does not fire for a `jump` or a choice's `closeCurrentLabel` option - those close the
877
+ * current label explicitly as part of starting a new one, so {@link onLabelStarting} already
878
+ * covers deferring them.
879
+ */
880
+ static onLabelClosing?: (labelId: LabelIdType, props: StepLabelPropsType, defaultClose: () => Promise<StepLabelResultType>) => StepLabelResultType | Promise<StepLabelResultType>;
732
881
  }
733
882
 
734
- type InputInfo = {
735
- isRequired?: boolean;
736
- type?: string;
737
- };
738
-
739
883
  declare const narration: NarrationManagerInterface;
740
884
 
741
- export { type ChoiceInterface, type ChoiceOptionInterface, type CloseChoiceOptionInterface, DialogueInterface, HistoryStep, type InputInfo, Label, LabelAbstract, LabelIdType, type LabelProps, LabelRunModeType, type LabelSteps, type NarrationGameState, type NarrationManagerInterface, NarrationManagerStatic, OpenedLabel, RegisteredLabels, type StepLabelProps, StepLabelPropsType, type StepLabelResult, StepLabelResultType, StepLabelType, type StoredChoiceInterface, type StoredIndexedChoiceInterface, narration, newChoiceOption, newCloseChoiceOption, newLabel };
885
+ export { type ChoiceInterface, type ChoiceOptionInterface, type CloseChoiceOptionInterface, DialogueInterface, HistoryStep, type InputInfo, Label, LabelAbstract, LabelIdType, type LabelProps, LabelRunModeType, type LabelSteps, type NarrationChoicesInterface, type NarrationGameState, type NarrationInputInterface, type NarrationLabelsInterface, type NarrationManagerInterface, NarrationManagerStatic, type NarrationQueriesInterface, OpenedLabel, RegisteredLabels, type StepLabelProps, StepLabelPropsType, type StepLabelResult, StepLabelResultType, StepLabelType, type StoredChoiceInterface, type StoredIndexedChoiceInterface, narration, newChoiceOption, newCloseChoiceOption, newLabel };
@@ -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'@drincs/pixi-vn/core';var h=new d({cacheSize:10}),R;(d=>{function i(c){let f=h.get(c);if(!f){e.error(`Label "${c}" not found`);return}return f}d.get=i;function e$1(...c){for(let f of c)h.set(f.id,f);}d.add=e$1;function t(){return Array.from(h.values())}d.values=t;function r(c){return h.has(c)}d.has=r;function n(){return Array.from(h.keys())}d.keys=n;function a(){h.clear();}d.clear=a;})(R||={});var S=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",c=GameUnifier.getVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY)||{};return c[n$1]||(c[n$1]={}),(!c[n$1][r]||c[n$1][r].stepSha1!==d)&&(c[n$1][r]={stepSha1:d}),c[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 c=d.usedRandomNumbers||{},f=Array.from({length:t-e+1},(E,N)=>N+e).filter(E=>!c[`${e}-${t}`]?.includes(E));if(f.length===0)return;let L=Math.floor(Math.random()*f.length),b=f[L];return c[`${e}-${t}`]||(c[`${e}-${t}`]=[]),c[`${e}-${t}`].push(b),d.usedRandomNumbers=c,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 S.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(c=>c.labelId===e&&c.stepIndex===t&&c.choiceIndex===n&&c.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(!S.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;static onLabelStarting};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,c,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&&(c=GameUnifier.getVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY));let L=o.openedLabels,b={currentLabel:o.currentLabelId,dialogue:a,choices:d,stepSha1:e,index:this.stepCounter,labelStepIndex:o.currentLabelStepIndex,choiceIndexMade:r,inputValue:c,alreadyMadeChoices:this.getAlreadyMadeChoicesForSha(e),isGlued:f,openedLabels:L};o.originalOpenedLabels=L,GameUnifier.addHistoryItem(b,{ignoreSameStep:n$1}),o.lastHistoryStep=b,o.increaseStepCounter();}getAlreadyMadeChoicesForSha(e){let t=o.currentLabelStepIndex,r=this.currentLabel;if(!(t===null||!r))return o.allChoicesMade.filter(n=>n.labelId===r.id&&n.stepIndex===t&&n.stepSha1===e).map(n=>n.choiceIndex)}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=S.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 c=a.getStepSha(n);c||(e.warn("stepSha not found, setting to ERROR"),c="error");let f,L;try{f=await d(e$1,{labelId:a.id});}catch(b){e.error("Error running step",b),L=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),L||(L=b);}try{let b=o.lastHistoryStep;r!==void 0&&b&&(c=b.stepSha1,c||(e.warn("stepSha not found, setting to ERROR"),c="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(c,{...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 L&&this.onStepError&&await this.onStepError(L,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 startLabel(e$1,t,r){let n=async()=>{let{choiceMade:a,closeCurrentLabel:d,type:c}=r;d&&this.openedLabels.length>0&&this.closeCurrentLabel(),GameUnifier.runningStepsCount++;let f;try{let L=S.get(e$1);if(!L)throw new PixiError("unregistered_element",`Label ${e$1} not found`);o.pushNewLabel(L.id),f=await this.runCurrentStep(t,{choiceMade:a});}catch(L){throw e.error(`Error ${c} label`,L),L}return GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(t)||f};return o.onLabelStarting?await o.onLabelStarting(e$1,t,r,n):await n()}async call(e,t,r){let{choiceMade:n}=r||{},a;return typeof e=="string"?a=e:a=e.id,await this.startLabel(a,t,{choiceMade:n,type:"calling"})}async jump(e,t,r){if(this.stepCounter===0)return await this.call(e,t,r);let{choiceMade:n}=r||{},a;return typeof e=="string"?a=e:a=e.id,await this.startLabel(a,t,{choiceMade:n,closeCurrentLabel:true,type:"jumping to"})}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=S.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 T=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 g=class extends T{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){let t=this.steps;if(e$1<0||e$1>=t.length)return typeof this._steps!="function"&&e.warn("stepSha not found, setting to ERROR"),"error";try{return (0,M.default)(t[e$1].toString().toLocaleLowerCase()).toString()}catch(r){return e.warn("stepSha not found, setting to ERROR",r),"error"}}};function x(i,e,t){let r=new g(i,e,t);return S.add(r),r}var fe=new C;
2
- export{g as Label,T as LabelAbstract,o as NarrationManagerStatic,S as RegisteredLabels,fe as narration,D as newChoiceOption,U as newCloseChoiceOption,x as newLabel};
1
+ import {a}from'./chunk-6GLWL3NH.mjs';import {k,m}from'./chunk-HD353M4B.mjs';import {d,c,e,f}from'./chunk-HQQ5WH6C.mjs';import {GameUnifier,PixiError}from'@drincs/pixi-vn/core';var h=new d({cacheSize:10}),_;(d=>{function i(c){let f=h.get(c);if(!f){e.error(`Label "${c}" not found`);return}return f}d.get=i;function e$1(...c){for(let f of c)h.set(f.id,f);}d.add=e$1;function t(){return Array.from(h.values())}d.values=t;function r(c){return h.has(c)}d.has=r;function n(){return Array.from(h.keys())}d.keys=n;function a(){h.clear();}d.clear=a;})(_||={});var y=_;var o=class i{constructor(){}static choiceMadeTemp=void 0;static lastHistoryStep=null;static get allOpenedLabels(){return GameUnifier.getVariable(k,m.OPENED_LABELS_COUNTER_KEY)||{}}static set allOpenedLabels(e){GameUnifier.setVariable(k,m.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=i.currentLabelId,a=i._currentLabel;if(!n||t===null||!a)return e.error("currentLabelId or currentLabelStepIndex is null or currentLabel not found"),null;let d=a.getStepSha(t)||"error",c=GameUnifier.getVariable(k,m.CURRENT_STEP_TIMES_COUNTER_KEY)||{};return c[n]||(c[n]={}),(!c[n][r]||c[n][r].stepSha1!==d)&&(c[n][r]={stepSha1:d}),c[n][r]}static setCurrentStepTimesCounterData(e$1="",t){let r=i.currentLabelStepIndex,n=r+e$1,a=i.currentLabelId;if(!a||r===null){e.error("currentLabelId or currentLabelStepIndex is null");return}let d=GameUnifier.getVariable(k,m.CURRENT_STEP_TIMES_COUNTER_KEY)||{};d[a]||(d[a]={}),d[a][n]=t,GameUnifier.setVariable(k,m.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 c=d.usedRandomNumbers||{},f=Array.from({length:t-e+1},(E,N)=>N+e).filter(E=>!c[`${e}-${t}`]?.includes(E));if(f.length===0)return;let L=Math.floor(Math.random()*f.length),b=f[L];return c[`${e}-${t}`]||(c[`${e}-${t}`]=[]),c[`${e}-${t}`].push(b),d.usedRandomNumbers=c,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=i.currentLabelId;if(!n||t===null){e.error("currentLabelId or currentLabelStepIndex is null");return}let a=GameUnifier.getVariable(k,m.CURRENT_STEP_TIMES_COUNTER_KEY)||{};a[n]||(a[n]={}),a[n][r]={stepCounters:[],stepSha1:""},GameUnifier.setVariable(k,m.CURRENT_STEP_TIMES_COUNTER_KEY,a);}static get allChoicesMade(){return GameUnifier.getVariable(k,m.ALL_CHOICES_MADE_KEY)||[]}static set allChoicesMade(e){GameUnifier.setVariable(k,m.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 y.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(c=>c.labelId===e&&c.stepIndex===t&&c.choiceIndex===n&&c.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(!y.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;static onLabelStarting;static onLabelClosing};var g=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}=t,a,d,c,f=GameUnifier.getVariable(k,m.LAST_STEP_GLUED)===this.stepCounter;GameUnifier.getVariable(k,m.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(a=GameUnifier.getVariable(k,m.CURRENT_DIALOGUE_MEMORY_KEY)),GameUnifier.getVariable(k,m.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(d=GameUnifier.getVariable(k,m.CURRENT_MENU_OPTIONS_MEMORY_KEY)),GameUnifier.getVariable(k,m.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(c=GameUnifier.getVariable(k,m.CURRENT_INPUT_VALUE_MEMORY_KEY));let L=o.openedLabels,b={currentLabel:o.currentLabelId,dialogue:a,choices:d,stepSha1:e,index:this.stepCounter,labelStepIndex:o.currentLabelStepIndex,choiceIndexMade:r,inputValue:c,...this.isRequiredInput?{isRequiredInput:true}:{},alreadyMadeChoices:this.getAlreadyMadeChoicesForSha(e),isGlued:f,openedLabels:L};o.originalOpenedLabels=L,GameUnifier.addHistoryItem(b,{ignoreSameStep:n}),o.lastHistoryStep=b,o.increaseStepCounter();}getAlreadyMadeChoicesForSha(e){let t=o.currentLabelStepIndex,r=this.currentLabel;if(!(t===null||!r))return o.allChoicesMade.filter(n=>n.labelId===r.id&&n.stepIndex===t&&n.stepSha1===e).map(n=>n.choiceIndex)}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);}labels={get opened(){return o.openedLabels},get current(){return o._currentLabel},closeCurrent:()=>this.closeCurrentLabel(),closeAll:()=>this.closeAllLabels()};isLabelAlreadyCompleted(e){let t;typeof e=="string"?t=e:t=e.id;let n=o.allOpenedLabels[t]?.biggestStep||0;if(n){let a=y.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}queries=(()=>{let e=this;return {isLabelAlreadyCompleted:t=>e.isLabelAlreadyCompleted(t),get alreadyCurrentStepMadeChoices(){return e.alreadyCurrentStepMadeChoices},get isCurrentStepAlreadyOpened(){return e.isCurrentStepAlreadyOpened},timesLabelOpened:t=>e.getTimesLabelOpened(t),timesChoiceMade:t=>e.getTimesChoiceMade(t)}})();addCurrentStepToHistory(){this.addStepHistory("dev",{ignoreSameStep:true});}getCanContinue(e$1){let t=e$1?.showWarn||false,r=this.choicesValue;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||this.openedLabels.length===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 c=a.getStepSha(n);c||(e.warn("stepSha not found, setting to ERROR"),c="error");let f,L;try{f=await d(e$1,{labelId:a.id});}catch(b){e.error("Error running step",b),L=b;}try{let b=this.choicesValue;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),L||(L=b);}try{let b=o.lastHistoryStep;r!==void 0&&b&&(c=b.stepSha1,c||(e.warn("stepSha not found, setting to ERROR"),c="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(c,{...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 L&&this.onStepError&&await this.onStepError(L,e$1),f}else if(this.openedLabels.length>=1)return await this.closeLabel(a.id,e$1,t)}else {if(this.openedLabels.length===0)return;e.error("currentLabelId not found");}}async closeLabel(e,t,r){let n=async()=>(this.closeCurrentLabel(),await this.continue(t,r));return o.onLabelClosing?await o.onLabelClosing(e,t,n):await n()}async startLabel(e$1,t,r){let n=async()=>{let{choiceMade:a,closeCurrentLabel:d,type:c}=r;d&&this.openedLabels.length>0&&this.closeCurrentLabel(),GameUnifier.runningStepsCount++;let f;try{let L=y.get(e$1);if(!L)throw new PixiError("unregistered_element",`Label ${e$1} not found`);o.pushNewLabel(L.id),f=await this.runCurrentStep(t,{choiceMade:a});}catch(L){throw e.error(`Error ${c} label`,L),L}return GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(t)||f};return o.onLabelStarting?await o.onLabelStarting(e$1,t,r,n):await n()}async call(e,t,r){let{choiceMade:n}=r||{},a;return typeof e=="string"?a=e:a=e.id,await this.startLabel(a,t,{choiceMade:n,type:"calling"})}async jump(e,t,r){if(this.stepCounter===0)return await this.call(e,t,r);let{choiceMade:n}=r||{},a;return typeof e=="string"?a=e:a=e.id,await this.startLabel(a,t,{choiceMade:n,closeCurrentLabel:true,type:"jumping to"})}async selectChoice(e$1,t){this.choicesValue=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(k,m.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(k,m.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(k,m.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(k,m.LAST_STEP_GLUED,this.stepCounter),this.dialogGlue=false;}try{GameUnifier.setVariable(k,m.CURRENT_DIALOGUE_MEMORY_KEY,f({...e$1,character:typeof e$1.character=="string"?e$1.character:e$1.character?.id})),GameUnifier.setVariable(k,m.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 choicesValue(){let e=GameUnifier.getVariable(k,m.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 choicesValue(e$1){if(!e$1||e$1.length===0){GameUnifier.setVariable(k,m.CURRENT_MENU_OPTIONS_MEMORY_KEY,void 0);return}try{GameUnifier.setVariable(k,m.CURRENT_MENU_OPTIONS_MEMORY_KEY,f(e$1)),GameUnifier.setVariable(k,m.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")}}choicesObj=(()=>{let e=this,t={select:(r,n)=>e.selectChoice(r,n)};return Object.defineProperty(t,"list",{get:()=>e.choicesValue,set:r=>{e.choicesValue=r;},enumerable:true}),t})();get choices(){return this.choicesObj}set choices(e){this.choicesValue=e;}get dialogGlue(){return GameUnifier.getFlag(m.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY)}set dialogGlue(e){GameUnifier.setFlag(m.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,e);}get inputValue(){return GameUnifier.getVariable(k,m.CURRENT_INPUT_VALUE_MEMORY_KEY)}set inputValue(e){this.removeInputRequest(),GameUnifier.setVariable(k,m.CURRENT_INPUT_VALUE_MEMORY_KEY,e),GameUnifier.setVariable(k,m.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}get isRequiredInput(){return GameUnifier.getVariable(k,m.CURRENT_INPUT_INFO_MEMORY_KEY)?.isRequired||false}get inputType(){return GameUnifier.getVariable(k,m.CURRENT_INPUT_INFO_MEMORY_KEY)?.type}requestInput(e={},t){e.isRequired=true,GameUnifier.setVariable(k,m.CURRENT_INPUT_INFO_MEMORY_KEY,e),t!==void 0?GameUnifier.setVariable(k,m.CURRENT_INPUT_VALUE_MEMORY_KEY,t):GameUnifier.removeVariable(k,m.CURRENT_INPUT_VALUE_MEMORY_KEY);}removeInputRequest(){GameUnifier.removeVariable(k,m.CURRENT_INPUT_INFO_MEMORY_KEY),GameUnifier.removeVariable(k,m.CURRENT_INPUT_VALUE_MEMORY_KEY);}input=(()=>{let e=this;return {get value(){return e.inputValue},set value(t){e.inputValue=t;},get isRequired(){return e.isRequiredInput},get type(){return e.inputType},request:(t,r)=>e.requestInput(t,r),removeRequest:()=>e.removeInputRequest()}})();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=y.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 T=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 T{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){let t=this.steps;if(e$1<0||e$1>=t.length)return typeof this._steps!="function"&&e.warn("stepSha not found, setting to ERROR"),"error";try{return (0,M.default)(t[e$1].toString().toLocaleLowerCase()).toString()}catch(r){return e.warn("stepSha not found, setting to ERROR",r),"error"}}};function x(i,e,t){let r=new I(i,e,t);return y.add(r),r}var fe=new g;
2
+ export{I as Label,T as LabelAbstract,o as NarrationManagerStatic,y as RegisteredLabels,fe as narration,D as newChoiceOption,U as newCloseChoiceOption,x as newLabel};