@drincs/pixi-vn 1.8.10 → 1.8.12

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 (39) hide show
  1. package/dist/{ContainerMemory-BjcfYRU7.d.cts → ContainerMemory-D2HtgX7w.d.cts} +1 -1
  2. package/dist/{ContainerMemory-BjcfYRU7.d.ts → ContainerMemory-D2HtgX7w.d.ts} +1 -1
  3. package/dist/{HistoryChoiceMenuOption-CEmjDDJH.d.cts → HistoryChoiceMenuOption-BMsYentw.d.cts} +1 -1
  4. package/dist/{HistoryChoiceMenuOption-CN7NkcxU.d.ts → HistoryChoiceMenuOption-DQ-pnuPU.d.ts} +1 -1
  5. package/dist/{HistoryGameState-3ztYdv84.d.cts → HistoryGameState-C28NcKKl.d.cts} +1 -1
  6. package/dist/{HistoryGameState-D4t2fY9x.d.ts → HistoryGameState-CmjUtlkV.d.ts} +1 -1
  7. package/dist/{HistoryStep-DtOryKAZ.d.cts → HistoryStep-G9dUn0Lf.d.cts} +36 -4
  8. package/dist/{HistoryStep-DtOryKAZ.d.ts → HistoryStep-G9dUn0Lf.d.ts} +36 -4
  9. package/dist/{OpenedLabel-t6PvSzaL.d.cts → OpenedLabel-BxfL31aQ.d.cts} +1 -1
  10. package/dist/{OpenedLabel-DJby8qPc.d.ts → OpenedLabel-DLfFuZgk.d.ts} +1 -1
  11. package/dist/{SoundManagerInterface-TgOPqm2L.d.cts → SoundManagerInterface-Dd0b88_N.d.cts} +2 -2
  12. package/dist/{SoundManagerInterface-TgOPqm2L.d.ts → SoundManagerInterface-Dd0b88_N.d.ts} +2 -2
  13. package/dist/canvas.d.cts +2 -2
  14. package/dist/canvas.d.ts +2 -2
  15. package/dist/characters.cjs +1 -1
  16. package/dist/characters.d.cts +43 -5
  17. package/dist/characters.d.ts +43 -5
  18. package/dist/characters.mjs +1 -1
  19. package/dist/history.d.cts +3 -3
  20. package/dist/history.d.ts +3 -3
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.d.cts +7 -7
  23. package/dist/index.d.ts +7 -7
  24. package/dist/index.mjs +1 -1
  25. package/dist/narration.cjs +2 -2
  26. package/dist/narration.d.cts +362 -361
  27. package/dist/narration.d.ts +362 -361
  28. package/dist/narration.mjs +2 -2
  29. package/dist/sound.d.cts +2 -2
  30. package/dist/sound.d.ts +2 -2
  31. package/dist/vite-listener.cjs +1 -1
  32. package/dist/vite-listener.d.cts +1 -1
  33. package/dist/vite-listener.d.ts +1 -1
  34. package/dist/vite-listener.mjs +1 -1
  35. package/dist/vite.cjs +2 -1
  36. package/dist/vite.d.cts +47 -2
  37. package/dist/vite.d.ts +47 -2
  38. package/dist/vite.mjs +2 -1
  39. package/package.json +1 -1
@@ -1,129 +1,401 @@
1
- import { LabelProps as LabelProps$1, NarrationManagerInterface as NarrationManagerInterface$1 } from '@drincs/pixi-vn/canvas';
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
4
  import { ChoiceInterface as ChoiceInterface$1 } from '@drincs/pixi-vn';
3
- import { a as StorageObjectType, S as StorageElementType } from './StorageElementType-C7ETezlL.js';
4
- import { L as LabelRunModeType, C as CloseType } from './HistoryChoiceMenuOption-CN7NkcxU.js';
5
- export { H as HistoryChoiceMenuOption, N as NarrationHistory } from './HistoryChoiceMenuOption-CN7NkcxU.js';
6
- import { L as LabelIdType, D as DialogueInterface, H as HistoryStep } from './HistoryStep-DtOryKAZ.js';
7
- import { b as StepLabelType, S as StepLabelPropsType, a as StepLabelResultType } from './StepLabelType-CN97wZzm.js';
8
- import { O as OpenedLabel } from './OpenedLabel-DJby8qPc.js';
5
+ import { L as LabelRunModeType, C as CloseType } from './HistoryChoiceMenuOption-DQ-pnuPU.js';
6
+ export { H as HistoryChoiceMenuOption, N as NarrationHistory } from './HistoryChoiceMenuOption-DQ-pnuPU.js';
7
+ import { S as StepLabelPropsType, a as StepLabelResultType, b as StepLabelType } from './StepLabelType-CN97wZzm.js';
8
+ import { O as OpenedLabel } from './OpenedLabel-DLfFuZgk.js';
9
+ import { LabelProps as LabelProps$1 } from '@drincs/pixi-vn/canvas';
9
10
  import 'microdiff';
10
11
 
11
- interface ChoiceOptionInterface extends Omit<ChoiceInterface$1, "label" | "type" | "closeCurrentLabel"> {
12
+ interface NarrationManagerInterface {
12
13
  /**
13
- * Label Id to be opened when the option is selected
14
+ * Counter of execution times of the current step. Current execution is also included. Starts from 1.
15
+ *
16
+ * **Attention**: if the step index is edited or the code of step is edited, the counter will be reset.
17
+ *
18
+ * You can restart the counter in this way:
19
+ * ```ts
20
+ * narration.currentStepTimesCounter = 0
21
+ * ```
14
22
  */
15
- label: LabelIdType;
23
+ currentStepTimesCounter: number;
16
24
  /**
17
- * Type of the label to be opened
25
+ * Get a random number between min and max.
26
+ * @param min The minimum number.
27
+ * @param max The maximum number.
28
+ * @param options The options.
29
+ * @returns The random number or undefined. If options.onceonly is true and all numbers between min and max have already been generated, it will return undefined.
18
30
  */
19
- type: LabelRunModeType;
20
- }
21
- interface CloseChoiceOptionInterface extends Omit<ChoiceInterface$1, "label" | "type" | "closeCurrentLabel"> {
31
+ getRandomNumber(min: number, max: number, options?: {
32
+ /**
33
+ * If true, the number will be generated only once on the current step of the label.
34
+ * @default false
35
+ */
36
+ onceOnly?: boolean;
37
+ }): number | undefined;
22
38
  /**
23
- * Type of the label to be opened
39
+ * This counter corresponds to the total number of steps that have been executed so far.
40
+ *
41
+ * **Not is the {@link history.stepsHistory}.length - 1.**
24
42
  */
25
- type: CloseType;
43
+ readonly stepCounter: number;
26
44
  /**
27
- * If true, the current label will be closed
45
+ * The stack of the opened labels.
28
46
  */
29
- closeCurrentLabel?: boolean;
30
- }
31
- type StoredChoiceInterface = ChoiceOptionInterface | CloseChoiceOptionInterface;
32
- type StoredIndexedChoiceInterface = StoredChoiceInterface & {
47
+ readonly openedLabels: OpenedLabel[];
33
48
  /**
34
- * Is the index of the choice in the menu. It is used to identify the choice when it is selected.
49
+ * currentLabel is the current label that occurred during the progression of the steps.
35
50
  */
36
- choiceIndex: number;
37
- };
38
-
39
- interface LabelProps<T, StepIdType = number> {
51
+ readonly currentLabel: LabelAbstract<any> | undefined;
40
52
  /**
41
- * A function executed before each `step`.
42
- * @param stepId The index of the `step` being executed
43
- * @param label The `label` containing the `step`
53
+ * Close the current label and add it to the history.
44
54
  * @returns
55
+ */
56
+ closeCurrentLabel(): void;
57
+ /**
58
+ * Close all labels and add them to the history. **Attention: This method can cause an unhandled game ending.**
59
+ */
60
+ closeAllLabels(): void;
61
+ /**
62
+ * Check if the label is already completed.
63
+ * @param label The label to check.
64
+ * @returns True if the label is already completed.
65
+ */
66
+ isLabelAlreadyCompleted(label: LabelIdType | LabelAbstract<any>): boolean;
67
+ /**
68
+ * 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
+ * @returns The choices already made in the current step. If there are no choices, it will return undefined.
70
+ */
71
+ readonly alreadyCurrentStepMadeChoices: number[] | undefined;
72
+ /**
73
+ * Check if the current step is already completed.
74
+ * @returns True if the current step is already completed.
75
+ */
76
+ readonly isCurrentStepAlreadyOpened: boolean;
77
+ /**
78
+ * Get times a label has been opened
79
+ * @returns times a label has been opened
80
+ */
81
+ getTimesLabelOpened(label: LabelIdType): number;
82
+ /**
83
+ * Get times a choice has been made in the current step.
84
+ * @param index The index of the choice.
85
+ * @returns The number of times the choice has been made.
86
+ */
87
+ getTimesChoiceMade(index: number): number;
88
+ /**
89
+ * Save the current step to the history.
90
+ */
91
+ addCurrentStepToHistory(): void;
92
+ /**
93
+ * Return if can go to the next step. It's `false` when:
94
+ * - A `step` is running
95
+ * - The player must "make a choice"
96
+ * - The player must "enter a value"
97
+ * @returns True if can go to the next step.
98
+ */
99
+ readonly canContinue: boolean;
100
+ /**
101
+ * Execute the next step and add it to the history. If a step is already running, it will put the request in the queue,
102
+ * and when the step is finished, it will execute the next step.
103
+ * @param props The props to pass to the step.
104
+ * @param options The options.
105
+ * @returns StepLabelResultType or undefined.
45
106
  * @example
46
107
  * ```ts
47
- * const startLabel = newLabel("start", [
48
- * () => {
49
- * narration.dialogue = "Step 1"
50
- * },
51
- * () => {
52
- * narration.dialogue = "Step 2"
53
- * }
54
- * ], {
55
- * onStepStart: (stepIndex, label) => {
56
- * console.log(`Step ${stepIndex} started`)
57
- * }
58
- * })
108
+ * function nextOnClick() {
109
+ * setLoading(true)
110
+ * narration.continue(yourParams)
111
+ * .then((result) => {
112
+ * setUpdate((p) => p + 1)
113
+ * setLoading(false)
114
+ * if (result) {
115
+ * // your code
116
+ * }
117
+ * })
118
+ * .catch((e) => {
119
+ * setLoading(false)
120
+ * console.error(e)
121
+ * })
122
+ * }
59
123
  * ```
60
124
  */
61
- onStepStart?: (stepId: StepIdType, label: T) => void | Promise<void>;
125
+ continue: (props: StepLabelPropsType, options?: {
126
+ /**
127
+ * The number of steps to advance. Must be a valid finite number greater than 0.
128
+ * If NaN, Infinity, or a value less than or equal to 0 is provided, the implementation
129
+ * will emit a warning and return early without advancing steps. @default 1
130
+ */
131
+ steps?: number;
132
+ /**
133
+ * If true, ignore the running step, ignore the choice menu/required input and run the next step immediately.
134
+ */
135
+ runNow?: boolean;
136
+ }) => Promise<StepLabelResultType>;
62
137
  /**
63
- * Is a function that will be executed in {@link onStepStart} if the id of the step is 0
64
- * and when the user laods a save file.
65
- * When you load a save file, will be executed all onLoadingLabel functions of the {@link narration.openedLabels}.
66
- * It is useful for example to make sure all images used have been cached
67
- * @param stepId The index of the `step` being executed
68
- * @param label The `label` being executed
69
- * @returns
138
+ * Execute the label, add the label to the history and execute the next step of the label.
139
+ * @param label The label to execute or the id of the label
140
+ * @param props The props to pass to the label.
141
+ * @returns StepLabelResultType or undefined.
142
+ * @throws {PixiError} when the label is not found in the registered labels.
70
143
  * @example
71
- * ```ts title="content/labels/start.label.ts"
72
- * newLabel("start", [], {
73
- * onLoadingLabel: async (stepId, label) => {
74
- * await Assets.load('path/to/image1.png')
75
- * await Assets.load('path/to/image2.png')
144
+ * ```ts
145
+ * narration.call(startLabel, yourParams).then((result) => {
146
+ * if (result) {
147
+ * // your code
76
148
  * }
77
149
  * })
78
150
  * ```
151
+ * @example
152
+ * ```ts
153
+ * // if you use it in a step label you should return the result.
154
+ * return narration.call(startLabel).then((result) => {
155
+ * return result
156
+ * })
157
+ * ```
79
158
  */
80
- onLoadingLabel?: (stepId: StepIdType, label: T) => void | Promise<void>;
159
+ call<T extends {} = {}>(label: LabelAbstract<any, T> | LabelIdType, props: StepLabelPropsType<T>): Promise<StepLabelResultType>;
81
160
  /**
82
- * A function executed after each `step`. See more <DynamicLink href="/start/labels-advanced#onstepend">here</DynamicLink>.
83
- * @param stepId The index of the `step` that ended
84
- * @param label The `label` containing the `step`
85
- * @returns
161
+ * Execute the label, replace the current label in the history with the new label and execute the next step of the label.
162
+ * @param label The label to execute.
163
+ * @param props The props to pass to the label or the id of the label
164
+ * @returns StepLabelResultType or undefined.
165
+ * @throws {PixiError} when the label is not found in the registered labels.
86
166
  * @example
87
167
  * ```ts
88
- * const startLabel = newLabel("start", [
89
- * async () => {
90
- * await showImage("image1", "path/to/image1.png")
91
- * await showImage("image2", "path/to/image2.png")
92
- * }
93
- * ], {
94
- * onLoadingLabel: async (stepIndex, label) => {
95
- * await Assets.load("path/to/image1.png")
96
- * await Assets.load("path/to/image2.png")
168
+ * narration.jump(startLabel, yourParams).then((result) => {
169
+ * if (result) {
170
+ * // your code
97
171
  * }
98
172
  * })
99
173
  * ```
174
+ * @example
175
+ * ```ts
176
+ * // if you use it in a step label you should return the result.
177
+ * return narration.jump(startLabel).then((result) => {
178
+ * return result
179
+ * })
180
+ * ```
100
181
  */
101
- onStepEnd?: (stepId: StepIdType, label: T) => void | Promise<void>;
102
- }
103
-
104
- declare abstract class LabelAbstract<TLabel, TProps extends {} = {}, StepIdType = number> implements LabelProps<TLabel, StepIdType> {
182
+ jump<T extends {}>(label: LabelAbstract<any, T> | LabelIdType, props: StepLabelPropsType<T>): Promise<StepLabelResultType>;
105
183
  /**
106
- * @param id is the id of the label
107
- * @param props is the properties of the label
184
+ * Select a choice from the choice menu. and close the choice menu.
185
+ * @param item
186
+ * @param props
187
+ * @returns
188
+ * @throws {PixiError} when the choice type is not `"call"`, `"jump"`, or `"close"`.
189
+ * @example
190
+ * ```ts
191
+ * narration.selectChoice(item, {
192
+ * navigate: navigate,
193
+ * // your props
194
+ * ...item.props
195
+ * })
196
+ * .then(() => {
197
+ * // your code
198
+ * })
199
+ * .catch((e) => {
200
+ * // your code
201
+ * })
202
+ * ```
108
203
  */
109
- constructor(id: LabelIdType, props?: LabelProps<TLabel, StepIdType>);
204
+ selectChoice<T extends {}>(item: StoredIndexedChoiceInterface, props: StepLabelPropsType<T>): Promise<StepLabelResultType>;
205
+ /** Old Step Methods */
110
206
  /**
111
- * Get the id of the label. This variable is used in the system to get the label by id, {@link RegisteredLabels.get}
207
+ * Dialogue to be shown in the game
112
208
  */
113
- readonly id: LabelIdType;
209
+ get dialogue(): DialogueInterface | undefined;
114
210
  /**
115
- * Get the number of steps in the label. This variable is used in the system to get the number of steps in the label.
116
- * @returns The number of steps in the label
211
+ * Dialogue to be shown in the game
212
+ * @throws {PixiError} when the dialogue contains functions or class instances that cannot be serialized to JSON.
117
213
  */
118
- abstract get stepCount(): number;
214
+ set dialogue(props: DialogueInterface | string | string[] | undefined);
119
215
  /**
120
- * Get the sha of the step
121
- * @param index Index of the step
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
+ * ```
122
227
  */
123
- abstract getStepSha(stepId: StepIdType): string | undefined;
228
+ get choices(): StoredIndexedChoiceInterface[] | undefined;
124
229
  /**
125
- * Get the step by id
126
- * @param stepId Id of the step
230
+ * The options to be shown in the game
231
+ * @throws {PixiError} when a choice contains functions or class instances that cannot be serialized to JSON.
232
+ * @example
233
+ * ```ts
234
+ * narration.choices = [
235
+ * newChoiceOption("Events Test", EventsTestLabel, {}),
236
+ * newChoiceOption("Show Image Test", ShowImageTest, { image: "imageId" }, "call"),
237
+ * newChoiceOption("Ticker Test", TickerTestLabel, {}),
238
+ * newChoiceOption("Tinting Test", TintingTestLabel, {}, "jump"),
239
+ * newChoiceOption("Base Canvas Element Test", BaseCanvasElementTestLabel, {})
240
+ * ]
241
+ * ```
242
+ */
243
+ set choices(data: StoredChoiceInterface[] | undefined);
244
+ /**
245
+ * If true, the next dialogue text will be added to the current dialogue text.
246
+ */
247
+ dialogGlue: boolean;
248
+ /**
249
+ * The input value to be inserted by the player.
250
+ */
251
+ inputValue: StorageElementType;
252
+ /**
253
+ * If true, the player must enter a value.
254
+ */
255
+ readonly isRequiredInput: boolean;
256
+ readonly inputType: string | undefined;
257
+ /**
258
+ * Request input from the player.
259
+ * @param info The input value to be inserted by the player.
260
+ * @param defaultValue The default value to be inserted.
261
+ */
262
+ requestInput(info: Omit<InputInfo, "isRequired">, defaultValue?: StorageElementType): void;
263
+ /**
264
+ * Remove the input request.
265
+ */
266
+ removeInputRequest(): void;
267
+ /**
268
+ * Clear all narration data
269
+ */
270
+ clear(): void;
271
+ /**
272
+ * Export the narration to an object.
273
+ * @returns The narration in an object.
274
+ */
275
+ export(): NarrationGameState;
276
+ /**
277
+ * Restore the narration from an object.
278
+ * @param data The narration in an object.
279
+ */
280
+ restore(data: object, lastHistoryStep: Omit<HistoryStep, "diff"> | null): Promise<void>;
281
+ }
282
+
283
+ interface ChoiceOptionInterface extends Omit<ChoiceInterface$1, "label" | "type" | "closeCurrentLabel"> {
284
+ /**
285
+ * Label Id to be opened when the option is selected
286
+ */
287
+ label: LabelIdType;
288
+ /**
289
+ * Type of the label to be opened
290
+ */
291
+ type: LabelRunModeType;
292
+ }
293
+ interface CloseChoiceOptionInterface extends Omit<ChoiceInterface$1, "label" | "type" | "closeCurrentLabel"> {
294
+ /**
295
+ * Type of the label to be opened
296
+ */
297
+ type: CloseType;
298
+ /**
299
+ * If true, the current label will be closed
300
+ */
301
+ closeCurrentLabel?: boolean;
302
+ }
303
+ type StoredChoiceInterface = ChoiceOptionInterface | CloseChoiceOptionInterface;
304
+ type StoredIndexedChoiceInterface = StoredChoiceInterface & {
305
+ /**
306
+ * Is the index of the choice in the menu. It is used to identify the choice when it is selected.
307
+ */
308
+ choiceIndex: number;
309
+ };
310
+
311
+ interface LabelProps<T, StepIdType = number> {
312
+ /**
313
+ * A function executed before each `step`.
314
+ * @param stepId The index of the `step` being executed
315
+ * @param label The `label` containing the `step`
316
+ * @returns
317
+ * @example
318
+ * ```ts
319
+ * const startLabel = newLabel("start", [
320
+ * () => {
321
+ * narration.dialogue = "Step 1"
322
+ * },
323
+ * () => {
324
+ * narration.dialogue = "Step 2"
325
+ * }
326
+ * ], {
327
+ * onStepStart: (stepIndex, label) => {
328
+ * console.log(`Step ${stepIndex} started`)
329
+ * }
330
+ * })
331
+ * ```
332
+ */
333
+ onStepStart?: (stepId: StepIdType, label: T) => void | Promise<void>;
334
+ /**
335
+ * Is a function that will be executed in {@link onStepStart} if the id of the step is 0
336
+ * and when the user laods a save file.
337
+ * When you load a save file, will be executed all onLoadingLabel functions of the {@link narration.openedLabels}.
338
+ * It is useful for example to make sure all images used have been cached
339
+ * @param stepId The index of the `step` being executed
340
+ * @param label The `label` being executed
341
+ * @returns
342
+ * @example
343
+ * ```ts title="content/labels/start.label.ts"
344
+ * newLabel("start", [], {
345
+ * onLoadingLabel: async (stepId, label) => {
346
+ * await Assets.load('path/to/image1.png')
347
+ * await Assets.load('path/to/image2.png')
348
+ * }
349
+ * })
350
+ * ```
351
+ */
352
+ onLoadingLabel?: (stepId: StepIdType, label: T) => void | Promise<void>;
353
+ /**
354
+ * A function executed after each `step`. See more <DynamicLink href="/start/labels-advanced#onstepend">here</DynamicLink>.
355
+ * @param stepId The index of the `step` that ended
356
+ * @param label The `label` containing the `step`
357
+ * @returns
358
+ * @example
359
+ * ```ts
360
+ * const startLabel = newLabel("start", [
361
+ * async () => {
362
+ * await showImage("image1", "path/to/image1.png")
363
+ * await showImage("image2", "path/to/image2.png")
364
+ * }
365
+ * ], {
366
+ * onLoadingLabel: async (stepIndex, label) => {
367
+ * await Assets.load("path/to/image1.png")
368
+ * await Assets.load("path/to/image2.png")
369
+ * }
370
+ * })
371
+ * ```
372
+ */
373
+ onStepEnd?: (stepId: StepIdType, label: T) => void | Promise<void>;
374
+ }
375
+
376
+ declare abstract class LabelAbstract<TLabel, TProps extends {} = {}, StepIdType = number> implements LabelProps<TLabel, StepIdType> {
377
+ /**
378
+ * @param id is the id of the label
379
+ * @param props is the properties of the label
380
+ */
381
+ constructor(id: string, props?: LabelProps<TLabel, StepIdType>);
382
+ /**
383
+ * Get the id of the label. This variable is used in the system to get the label by id, {@link RegisteredLabels.get}
384
+ */
385
+ readonly id: string;
386
+ /**
387
+ * Get the number of steps in the label. This variable is used in the system to get the number of steps in the label.
388
+ * @returns The number of steps in the label
389
+ */
390
+ abstract get stepCount(): number;
391
+ /**
392
+ * Get the sha of the step
393
+ * @param index Index of the step
394
+ */
395
+ abstract getStepSha(stepId: StepIdType): string | undefined;
396
+ /**
397
+ * Get the step by id
398
+ * @param stepId Id of the step
127
399
  * @return The step or undefined if it does not exist
128
400
  */
129
401
  abstract getStepById(stepId: StepIdType): StepLabelType<TProps> | undefined;
@@ -216,7 +488,7 @@ type LabelSteps<T extends {}> = [StepLabelType<T>, ...StepLabelType<Partial<T>>[
216
488
  * @param props An object with the `label`'s options
217
489
  * @returns The created label
218
490
  */
219
- declare function newLabel<T extends {} = {}>(id: LabelIdType, steps: LabelSteps<T> | (() => LabelSteps<T>), props?: LabelProps<Label<T>>): Label<T>;
491
+ declare function newLabel<T extends {} = {}>(id: string, steps: LabelSteps<T> | (() => LabelSteps<T>), props?: LabelProps<Label<T>>): Label<T>;
220
492
 
221
493
  declare namespace RegisteredLabels {
222
494
  /**
@@ -224,7 +496,7 @@ declare namespace RegisteredLabels {
224
496
  * @param id The id of the label
225
497
  * @returns The label or undefined if it does not exist
226
498
  */
227
- function get<T = LabelAbstract<any>>(id: LabelIdType): T | undefined;
499
+ function get<T = LabelAbstract<any>, T2 extends LabelIdType | string = LabelIdType>(id: T2): T | undefined;
228
500
  /**
229
501
  * Saves a label in the system
230
502
  * @param label The label to be saved
@@ -245,7 +517,7 @@ declare namespace RegisteredLabels {
245
517
  * Get a list of all label ids registered.
246
518
  * @returns An array of label ids.
247
519
  */
248
- function keys(): string[];
520
+ function keys(): LabelIdType[];
249
521
  }
250
522
 
251
523
  interface ChoiceInterface {
@@ -291,277 +563,6 @@ interface NarrationGameState {
291
563
  stepCounter: number;
292
564
  }
293
565
 
294
- interface NarrationManagerInterface {
295
- /**
296
- * Counter of execution times of the current step. Current execution is also included. Starts from 1.
297
- *
298
- * **Attention**: if the step index is edited or the code of step is edited, the counter will be reset.
299
- *
300
- * You can restart the counter in this way:
301
- * ```ts
302
- * narration.currentStepTimesCounter = 0
303
- * ```
304
- */
305
- currentStepTimesCounter: number;
306
- /**
307
- * Get a random number between min and max.
308
- * @param min The minimum number.
309
- * @param max The maximum number.
310
- * @param options The options.
311
- * @returns The random number or undefined. If options.onceonly is true and all numbers between min and max have already been generated, it will return undefined.
312
- */
313
- getRandomNumber(min: number, max: number, options?: {
314
- /**
315
- * If true, the number will be generated only once on the current step of the label.
316
- * @default false
317
- */
318
- onceOnly?: boolean;
319
- }): number | undefined;
320
- /**
321
- * This counter corresponds to the total number of steps that have been executed so far.
322
- *
323
- * **Not is the {@link history.stepsHistory}.length - 1.**
324
- */
325
- readonly stepCounter: number;
326
- /**
327
- * The stack of the opened labels.
328
- */
329
- readonly openedLabels: OpenedLabel[];
330
- /**
331
- * currentLabel is the current label that occurred during the progression of the steps.
332
- */
333
- readonly currentLabel: LabelAbstract<any> | undefined;
334
- /**
335
- * Close the current label and add it to the history.
336
- * @returns
337
- */
338
- closeCurrentLabel(): void;
339
- /**
340
- * Close all labels and add them to the history. **Attention: This method can cause an unhandled game ending.**
341
- */
342
- closeAllLabels(): void;
343
- /**
344
- * Check if the label is already completed.
345
- * @param label The label to check.
346
- * @returns True if the label is already completed.
347
- */
348
- isLabelAlreadyCompleted(label: LabelIdType | LabelAbstract<any>): boolean;
349
- /**
350
- * 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.
351
- * @returns The choices already made in the current step. If there are no choices, it will return undefined.
352
- */
353
- readonly alreadyCurrentStepMadeChoices: number[] | undefined;
354
- /**
355
- * Check if the current step is already completed.
356
- * @returns True if the current step is already completed.
357
- */
358
- readonly isCurrentStepAlreadyOpened: boolean;
359
- /**
360
- * Get times a label has been opened
361
- * @returns times a label has been opened
362
- */
363
- getTimesLabelOpened(label: LabelIdType): number;
364
- /**
365
- * Get times a choice has been made in the current step.
366
- * @param index The index of the choice.
367
- * @returns The number of times the choice has been made.
368
- */
369
- getTimesChoiceMade(index: number): number;
370
- /**
371
- * Save the current step to the history.
372
- */
373
- addCurrentStepToHistory(): void;
374
- /**
375
- * Return if can go to the next step. It's `false` when:
376
- * - A `step` is running
377
- * - The player must "make a choice"
378
- * - The player must "enter a value"
379
- * @returns True if can go to the next step.
380
- */
381
- readonly canContinue: boolean;
382
- /**
383
- * Execute the next step and add it to the history. If a step is already running, it will put the request in the queue,
384
- * and when the step is finished, it will execute the next step.
385
- * @param props The props to pass to the step.
386
- * @param options The options.
387
- * @returns StepLabelResultType or undefined.
388
- * @example
389
- * ```ts
390
- * function nextOnClick() {
391
- * setLoading(true)
392
- * narration.continue(yourParams)
393
- * .then((result) => {
394
- * setUpdate((p) => p + 1)
395
- * setLoading(false)
396
- * if (result) {
397
- * // your code
398
- * }
399
- * })
400
- * .catch((e) => {
401
- * setLoading(false)
402
- * console.error(e)
403
- * })
404
- * }
405
- * ```
406
- */
407
- continue: (props: StepLabelPropsType, options?: {
408
- /**
409
- * The number of steps to advance. Must be a valid finite number greater than 0.
410
- * If NaN, Infinity, or a value less than or equal to 0 is provided, the implementation
411
- * will emit a warning and return early without advancing steps. @default 1
412
- */
413
- steps?: number;
414
- /**
415
- * If true, ignore the running step, ignore the choice menu/required input and run the next step immediately.
416
- */
417
- runNow?: boolean;
418
- }) => Promise<StepLabelResultType>;
419
- /**
420
- * Execute the label, add the label to the history and execute the next step of the label.
421
- * @param label The label to execute or the id of the label
422
- * @param props The props to pass to the label.
423
- * @returns StepLabelResultType or undefined.
424
- * @throws {PixiError} when the label is not found in the registered labels.
425
- * @example
426
- * ```ts
427
- * narration.call(startLabel, yourParams).then((result) => {
428
- * if (result) {
429
- * // your code
430
- * }
431
- * })
432
- * ```
433
- * @example
434
- * ```ts
435
- * // if you use it in a step label you should return the result.
436
- * return narration.call(startLabel).then((result) => {
437
- * return result
438
- * })
439
- * ```
440
- */
441
- call<T extends {} = {}>(label: LabelAbstract<any, T> | LabelIdType, props: StepLabelPropsType<T>): Promise<StepLabelResultType>;
442
- /**
443
- * Execute the label, replace the current label in the history with the new label and execute the next step of the label.
444
- * @param label The label to execute.
445
- * @param props The props to pass to the label or the id of the label
446
- * @returns StepLabelResultType or undefined.
447
- * @throws {PixiError} when the label is not found in the registered labels.
448
- * @example
449
- * ```ts
450
- * narration.jump(startLabel, yourParams).then((result) => {
451
- * if (result) {
452
- * // your code
453
- * }
454
- * })
455
- * ```
456
- * @example
457
- * ```ts
458
- * // if you use it in a step label you should return the result.
459
- * return narration.jump(startLabel).then((result) => {
460
- * return result
461
- * })
462
- * ```
463
- */
464
- jump<T extends {}>(label: LabelAbstract<any, T> | LabelIdType, props: StepLabelPropsType<T>): Promise<StepLabelResultType>;
465
- /**
466
- * Select a choice from the choice menu. and close the choice menu.
467
- * @param item
468
- * @param props
469
- * @returns
470
- * @throws {PixiError} when the choice type is not `"call"`, `"jump"`, or `"close"`.
471
- * @example
472
- * ```ts
473
- * narration.selectChoice(item, {
474
- * navigate: navigate,
475
- * // your props
476
- * ...item.props
477
- * })
478
- * .then(() => {
479
- * // your code
480
- * })
481
- * .catch((e) => {
482
- * // your code
483
- * })
484
- * ```
485
- */
486
- selectChoice<T extends {}>(item: StoredIndexedChoiceInterface, props: StepLabelPropsType<T>): Promise<StepLabelResultType>;
487
- /** Old Step Methods */
488
- /**
489
- * Dialogue to be shown in the game
490
- */
491
- get dialogue(): DialogueInterface | undefined;
492
- /**
493
- * Dialogue to be shown in the game
494
- * @throws {PixiError} when the dialogue contains functions or class instances that cannot be serialized to JSON.
495
- */
496
- set dialogue(props: DialogueInterface | string | string[] | undefined);
497
- /**
498
- * The options to be shown in the game
499
- * @example
500
- * ```ts
501
- * narration.choices = [
502
- * newChoiceOption("Events Test", EventsTestLabel, {}),
503
- * newChoiceOption("Show Image Test", ShowImageTest, { image: "imageId" }, "call"),
504
- * newChoiceOption("Ticker Test", TickerTestLabel, {}),
505
- * newChoiceOption("Tinting Test", TintingTestLabel, {}, "jump"),
506
- * newChoiceOption("Base Canvas Element Test", BaseCanvasElementTestLabel, {})
507
- * ]
508
- * ```
509
- */
510
- get choices(): StoredIndexedChoiceInterface[] | undefined;
511
- /**
512
- * The options to be shown in the game
513
- * @throws {PixiError} when a choice contains functions or class instances that cannot be serialized to JSON.
514
- * @example
515
- * ```ts
516
- * narration.choices = [
517
- * newChoiceOption("Events Test", EventsTestLabel, {}),
518
- * newChoiceOption("Show Image Test", ShowImageTest, { image: "imageId" }, "call"),
519
- * newChoiceOption("Ticker Test", TickerTestLabel, {}),
520
- * newChoiceOption("Tinting Test", TintingTestLabel, {}, "jump"),
521
- * newChoiceOption("Base Canvas Element Test", BaseCanvasElementTestLabel, {})
522
- * ]
523
- * ```
524
- */
525
- set choices(data: StoredChoiceInterface[] | undefined);
526
- /**
527
- * If true, the next dialogue text will be added to the current dialogue text.
528
- */
529
- dialogGlue: boolean;
530
- /**
531
- * The input value to be inserted by the player.
532
- */
533
- inputValue: StorageElementType;
534
- /**
535
- * If true, the player must enter a value.
536
- */
537
- readonly isRequiredInput: boolean;
538
- readonly inputType: string | undefined;
539
- /**
540
- * Request input from the player.
541
- * @param info The input value to be inserted by the player.
542
- * @param defaultValue The default value to be inserted.
543
- */
544
- requestInput(info: Omit<InputInfo, "isRequired">, defaultValue?: StorageElementType): void;
545
- /**
546
- * Remove the input request.
547
- */
548
- removeInputRequest(): void;
549
- /**
550
- * Clear all narration data
551
- */
552
- clear(): void;
553
- /**
554
- * Export the narration to an object.
555
- * @returns The narration in an object.
556
- */
557
- export(): NarrationGameState;
558
- /**
559
- * Restore the narration from an object.
560
- * @param data The narration in an object.
561
- */
562
- restore(data: object, lastHistoryStep: Omit<HistoryStep, "diff"> | null): Promise<void>;
563
- }
564
-
565
566
  /**
566
567
  * StepLabelPropsType is the type of the props that will be passed to the StepLabel.
567
568
  * You can override this interface to add your own props.
@@ -704,6 +705,6 @@ type InputInfo = {
704
705
  type?: string;
705
706
  };
706
707
 
707
- declare const narration: NarrationManagerInterface$1;
708
+ declare const narration: NarrationManagerInterface;
708
709
 
709
- export { type ChoiceInterface, type ChoiceOptionInterface, type CloseChoiceOptionInterface, DialogueInterface, HistoryStep, type InputInfo, Label, LabelAbstract, 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 };
710
+ 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 };