@drincs/pixi-vn 1.8.10 → 1.8.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/history.d.cts +1 -1
- package/dist/history.d.ts +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/narration.cjs +2 -2
- package/dist/narration.d.cts +350 -350
- package/dist/narration.d.ts +350 -350
- package/package.json +1 -1
package/dist/narration.d.cts
CHANGED
|
@@ -1,125 +1,396 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as StorageElementType, a as StorageObjectType } from './StorageElementType-C7ETezlL.cjs';
|
|
2
|
+
import { L as LabelIdType, D as DialogueInterface, H as HistoryStep } from './HistoryStep-DtOryKAZ.cjs';
|
|
2
3
|
import { ChoiceInterface as ChoiceInterface$1 } from '@drincs/pixi-vn';
|
|
3
|
-
import { a as StorageObjectType, S as StorageElementType } from './StorageElementType-C7ETezlL.cjs';
|
|
4
4
|
import { L as LabelRunModeType, C as CloseType } from './HistoryChoiceMenuOption-CEmjDDJH.cjs';
|
|
5
5
|
export { H as HistoryChoiceMenuOption, N as NarrationHistory } from './HistoryChoiceMenuOption-CEmjDDJH.cjs';
|
|
6
|
-
import {
|
|
7
|
-
import { b as StepLabelType, S as StepLabelPropsType, a as StepLabelResultType } from './StepLabelType-CN97wZzm.cjs';
|
|
6
|
+
import { S as StepLabelPropsType, a as StepLabelResultType, b as StepLabelType } from './StepLabelType-CN97wZzm.cjs';
|
|
8
7
|
import { O as OpenedLabel } from './OpenedLabel-t6PvSzaL.cjs';
|
|
8
|
+
import { LabelProps as LabelProps$1 } from '@drincs/pixi-vn/canvas';
|
|
9
9
|
import 'microdiff';
|
|
10
10
|
|
|
11
|
-
interface
|
|
11
|
+
interface NarrationManagerInterface {
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Counter of execution times of the current step. Current execution is also included. Starts from 1.
|
|
14
|
+
*
|
|
15
|
+
* **Attention**: if the step index is edited or the code of step is edited, the counter will be reset.
|
|
16
|
+
*
|
|
17
|
+
* You can restart the counter in this way:
|
|
18
|
+
* ```ts
|
|
19
|
+
* narration.currentStepTimesCounter = 0
|
|
20
|
+
* ```
|
|
14
21
|
*/
|
|
15
|
-
|
|
22
|
+
currentStepTimesCounter: number;
|
|
16
23
|
/**
|
|
17
|
-
*
|
|
24
|
+
* Get a random number between min and max.
|
|
25
|
+
* @param min The minimum number.
|
|
26
|
+
* @param max The maximum number.
|
|
27
|
+
* @param options The options.
|
|
28
|
+
* @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
29
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
getRandomNumber(min: number, max: number, options?: {
|
|
31
|
+
/**
|
|
32
|
+
* If true, the number will be generated only once on the current step of the label.
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
onceOnly?: boolean;
|
|
36
|
+
}): number | undefined;
|
|
22
37
|
/**
|
|
23
|
-
*
|
|
38
|
+
* This counter corresponds to the total number of steps that have been executed so far.
|
|
39
|
+
*
|
|
40
|
+
* **Not is the {@link history.stepsHistory}.length - 1.**
|
|
24
41
|
*/
|
|
25
|
-
|
|
42
|
+
readonly stepCounter: number;
|
|
26
43
|
/**
|
|
27
|
-
*
|
|
44
|
+
* The stack of the opened labels.
|
|
28
45
|
*/
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
type StoredChoiceInterface = ChoiceOptionInterface | CloseChoiceOptionInterface;
|
|
32
|
-
type StoredIndexedChoiceInterface = StoredChoiceInterface & {
|
|
46
|
+
readonly openedLabels: OpenedLabel[];
|
|
33
47
|
/**
|
|
34
|
-
*
|
|
48
|
+
* currentLabel is the current label that occurred during the progression of the steps.
|
|
35
49
|
*/
|
|
36
|
-
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
interface LabelProps<T, StepIdType = number> {
|
|
50
|
+
readonly currentLabel: LabelAbstract<any> | undefined;
|
|
40
51
|
/**
|
|
41
|
-
*
|
|
42
|
-
* @param stepId The index of the `step` being executed
|
|
43
|
-
* @param label The `label` containing the `step`
|
|
52
|
+
* Close the current label and add it to the history.
|
|
44
53
|
* @returns
|
|
54
|
+
*/
|
|
55
|
+
closeCurrentLabel(): void;
|
|
56
|
+
/**
|
|
57
|
+
* Close all labels and add them to the history. **Attention: This method can cause an unhandled game ending.**
|
|
58
|
+
*/
|
|
59
|
+
closeAllLabels(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Check if the label is already completed.
|
|
62
|
+
* @param label The label to check.
|
|
63
|
+
* @returns True if the label is already completed.
|
|
64
|
+
*/
|
|
65
|
+
isLabelAlreadyCompleted(label: LabelIdType | LabelAbstract<any>): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* 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.
|
|
68
|
+
* @returns The choices already made in the current step. If there are no choices, it will return undefined.
|
|
69
|
+
*/
|
|
70
|
+
readonly alreadyCurrentStepMadeChoices: number[] | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Check if the current step is already completed.
|
|
73
|
+
* @returns True if the current step is already completed.
|
|
74
|
+
*/
|
|
75
|
+
readonly isCurrentStepAlreadyOpened: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Get times a label has been opened
|
|
78
|
+
* @returns times a label has been opened
|
|
79
|
+
*/
|
|
80
|
+
getTimesLabelOpened(label: LabelIdType): number;
|
|
81
|
+
/**
|
|
82
|
+
* Get times a choice has been made in the current step.
|
|
83
|
+
* @param index The index of the choice.
|
|
84
|
+
* @returns The number of times the choice has been made.
|
|
85
|
+
*/
|
|
86
|
+
getTimesChoiceMade(index: number): number;
|
|
87
|
+
/**
|
|
88
|
+
* Save the current step to the history.
|
|
89
|
+
*/
|
|
90
|
+
addCurrentStepToHistory(): void;
|
|
91
|
+
/**
|
|
92
|
+
* Return if can go to the next step. It's `false` when:
|
|
93
|
+
* - A `step` is running
|
|
94
|
+
* - The player must "make a choice"
|
|
95
|
+
* - The player must "enter a value"
|
|
96
|
+
* @returns True if can go to the next step.
|
|
97
|
+
*/
|
|
98
|
+
readonly canContinue: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Execute the next step and add it to the history. If a step is already running, it will put the request in the queue,
|
|
101
|
+
* and when the step is finished, it will execute the next step.
|
|
102
|
+
* @param props The props to pass to the step.
|
|
103
|
+
* @param options The options.
|
|
104
|
+
* @returns StepLabelResultType or undefined.
|
|
45
105
|
* @example
|
|
46
106
|
* ```ts
|
|
47
|
-
*
|
|
48
|
-
* ()
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
107
|
+
* function nextOnClick() {
|
|
108
|
+
* setLoading(true)
|
|
109
|
+
* narration.continue(yourParams)
|
|
110
|
+
* .then((result) => {
|
|
111
|
+
* setUpdate((p) => p + 1)
|
|
112
|
+
* setLoading(false)
|
|
113
|
+
* if (result) {
|
|
114
|
+
* // your code
|
|
115
|
+
* }
|
|
116
|
+
* })
|
|
117
|
+
* .catch((e) => {
|
|
118
|
+
* setLoading(false)
|
|
119
|
+
* console.error(e)
|
|
120
|
+
* })
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
continue: (props: StepLabelPropsType, options?: {
|
|
125
|
+
/**
|
|
126
|
+
* The number of steps to advance. Must be a valid finite number greater than 0.
|
|
127
|
+
* If NaN, Infinity, or a value less than or equal to 0 is provided, the implementation
|
|
128
|
+
* will emit a warning and return early without advancing steps. @default 1
|
|
129
|
+
*/
|
|
130
|
+
steps?: number;
|
|
131
|
+
/**
|
|
132
|
+
* If true, ignore the running step, ignore the choice menu/required input and run the next step immediately.
|
|
133
|
+
*/
|
|
134
|
+
runNow?: boolean;
|
|
135
|
+
}) => Promise<StepLabelResultType>;
|
|
136
|
+
/**
|
|
137
|
+
* Execute the label, add the label to the history and execute the next step of the label.
|
|
138
|
+
* @param label The label to execute or the id of the label
|
|
139
|
+
* @param props The props to pass to the label.
|
|
140
|
+
* @returns StepLabelResultType or undefined.
|
|
141
|
+
* @throws {PixiError} when the label is not found in the registered labels.
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* narration.call(startLabel, yourParams).then((result) => {
|
|
145
|
+
* if (result) {
|
|
146
|
+
* // your code
|
|
57
147
|
* }
|
|
58
148
|
* })
|
|
59
149
|
* ```
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* // if you use it in a step label you should return the result.
|
|
153
|
+
* return narration.call(startLabel).then((result) => {
|
|
154
|
+
* return result
|
|
155
|
+
* })
|
|
156
|
+
* ```
|
|
60
157
|
*/
|
|
61
|
-
|
|
158
|
+
call<T extends {} = {}>(label: LabelAbstract<any, T> | LabelIdType, props: StepLabelPropsType<T>): Promise<StepLabelResultType>;
|
|
62
159
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* @
|
|
68
|
-
* @param label The `label` being executed
|
|
69
|
-
* @returns
|
|
160
|
+
* Execute the label, replace the current label in the history with the new label and execute the next step of the label.
|
|
161
|
+
* @param label The label to execute.
|
|
162
|
+
* @param props The props to pass to the label or the id of the label
|
|
163
|
+
* @returns StepLabelResultType or undefined.
|
|
164
|
+
* @throws {PixiError} when the label is not found in the registered labels.
|
|
70
165
|
* @example
|
|
71
|
-
* ```ts
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* await Assets.load('path/to/image2.png')
|
|
166
|
+
* ```ts
|
|
167
|
+
* narration.jump(startLabel, yourParams).then((result) => {
|
|
168
|
+
* if (result) {
|
|
169
|
+
* // your code
|
|
76
170
|
* }
|
|
77
171
|
* })
|
|
78
172
|
* ```
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* // if you use it in a step label you should return the result.
|
|
176
|
+
* return narration.jump(startLabel).then((result) => {
|
|
177
|
+
* return result
|
|
178
|
+
* })
|
|
179
|
+
* ```
|
|
79
180
|
*/
|
|
80
|
-
|
|
181
|
+
jump<T extends {}>(label: LabelAbstract<any, T> | LabelIdType, props: StepLabelPropsType<T>): Promise<StepLabelResultType>;
|
|
81
182
|
/**
|
|
82
|
-
*
|
|
83
|
-
* @param
|
|
84
|
-
* @param
|
|
183
|
+
* Select a choice from the choice menu. and close the choice menu.
|
|
184
|
+
* @param item
|
|
185
|
+
* @param props
|
|
85
186
|
* @returns
|
|
187
|
+
* @throws {PixiError} when the choice type is not `"call"`, `"jump"`, or `"close"`.
|
|
86
188
|
* @example
|
|
87
189
|
* ```ts
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* }
|
|
93
|
-
* ], {
|
|
94
|
-
* onLoadingLabel: async (stepIndex, label) => {
|
|
95
|
-
* await Assets.load("path/to/image1.png")
|
|
96
|
-
* await Assets.load("path/to/image2.png")
|
|
97
|
-
* }
|
|
190
|
+
* narration.selectChoice(item, {
|
|
191
|
+
* navigate: navigate,
|
|
192
|
+
* // your props
|
|
193
|
+
* ...item.props
|
|
98
194
|
* })
|
|
195
|
+
* .then(() => {
|
|
196
|
+
* // your code
|
|
197
|
+
* })
|
|
198
|
+
* .catch((e) => {
|
|
199
|
+
* // your code
|
|
200
|
+
* })
|
|
99
201
|
* ```
|
|
100
202
|
*/
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
declare abstract class LabelAbstract<TLabel, TProps extends {} = {}, StepIdType = number> implements LabelProps<TLabel, StepIdType> {
|
|
203
|
+
selectChoice<T extends {}>(item: StoredIndexedChoiceInterface, props: StepLabelPropsType<T>): Promise<StepLabelResultType>;
|
|
204
|
+
/** Old Step Methods */
|
|
105
205
|
/**
|
|
106
|
-
*
|
|
107
|
-
* @param props is the properties of the label
|
|
206
|
+
* Dialogue to be shown in the game
|
|
108
207
|
*/
|
|
109
|
-
|
|
208
|
+
get dialogue(): DialogueInterface | undefined;
|
|
110
209
|
/**
|
|
111
|
-
*
|
|
210
|
+
* Dialogue to be shown in the game
|
|
211
|
+
* @throws {PixiError} when the dialogue contains functions or class instances that cannot be serialized to JSON.
|
|
112
212
|
*/
|
|
113
|
-
|
|
213
|
+
set dialogue(props: DialogueInterface | string | string[] | undefined);
|
|
114
214
|
/**
|
|
115
|
-
*
|
|
116
|
-
* @
|
|
215
|
+
* The options to be shown in the game
|
|
216
|
+
* @example
|
|
217
|
+
* ```ts
|
|
218
|
+
* narration.choices = [
|
|
219
|
+
* newChoiceOption("Events Test", EventsTestLabel, {}),
|
|
220
|
+
* newChoiceOption("Show Image Test", ShowImageTest, { image: "imageId" }, "call"),
|
|
221
|
+
* newChoiceOption("Ticker Test", TickerTestLabel, {}),
|
|
222
|
+
* newChoiceOption("Tinting Test", TintingTestLabel, {}, "jump"),
|
|
223
|
+
* newChoiceOption("Base Canvas Element Test", BaseCanvasElementTestLabel, {})
|
|
224
|
+
* ]
|
|
225
|
+
* ```
|
|
117
226
|
*/
|
|
118
|
-
|
|
227
|
+
get choices(): StoredIndexedChoiceInterface[] | undefined;
|
|
119
228
|
/**
|
|
120
|
-
*
|
|
121
|
-
* @
|
|
122
|
-
|
|
229
|
+
* The options to be shown in the game
|
|
230
|
+
* @throws {PixiError} when a choice contains functions or class instances that cannot be serialized to JSON.
|
|
231
|
+
* @example
|
|
232
|
+
* ```ts
|
|
233
|
+
* narration.choices = [
|
|
234
|
+
* newChoiceOption("Events Test", EventsTestLabel, {}),
|
|
235
|
+
* newChoiceOption("Show Image Test", ShowImageTest, { image: "imageId" }, "call"),
|
|
236
|
+
* newChoiceOption("Ticker Test", TickerTestLabel, {}),
|
|
237
|
+
* newChoiceOption("Tinting Test", TintingTestLabel, {}, "jump"),
|
|
238
|
+
* newChoiceOption("Base Canvas Element Test", BaseCanvasElementTestLabel, {})
|
|
239
|
+
* ]
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
set choices(data: StoredChoiceInterface[] | undefined);
|
|
243
|
+
/**
|
|
244
|
+
* If true, the next dialogue text will be added to the current dialogue text.
|
|
245
|
+
*/
|
|
246
|
+
dialogGlue: boolean;
|
|
247
|
+
/**
|
|
248
|
+
* The input value to be inserted by the player.
|
|
249
|
+
*/
|
|
250
|
+
inputValue: StorageElementType;
|
|
251
|
+
/**
|
|
252
|
+
* If true, the player must enter a value.
|
|
253
|
+
*/
|
|
254
|
+
readonly isRequiredInput: boolean;
|
|
255
|
+
readonly inputType: string | undefined;
|
|
256
|
+
/**
|
|
257
|
+
* Request input from the player.
|
|
258
|
+
* @param info The input value to be inserted by the player.
|
|
259
|
+
* @param defaultValue The default value to be inserted.
|
|
260
|
+
*/
|
|
261
|
+
requestInput(info: Omit<InputInfo, "isRequired">, defaultValue?: StorageElementType): void;
|
|
262
|
+
/**
|
|
263
|
+
* Remove the input request.
|
|
264
|
+
*/
|
|
265
|
+
removeInputRequest(): void;
|
|
266
|
+
/**
|
|
267
|
+
* Clear all narration data
|
|
268
|
+
*/
|
|
269
|
+
clear(): void;
|
|
270
|
+
/**
|
|
271
|
+
* Export the narration to an object.
|
|
272
|
+
* @returns The narration in an object.
|
|
273
|
+
*/
|
|
274
|
+
export(): NarrationGameState;
|
|
275
|
+
/**
|
|
276
|
+
* Restore the narration from an object.
|
|
277
|
+
* @param data The narration in an object.
|
|
278
|
+
*/
|
|
279
|
+
restore(data: object, lastHistoryStep: Omit<HistoryStep, "diff"> | null): Promise<void>;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
interface ChoiceOptionInterface extends Omit<ChoiceInterface$1, "label" | "type" | "closeCurrentLabel"> {
|
|
283
|
+
/**
|
|
284
|
+
* Label Id to be opened when the option is selected
|
|
285
|
+
*/
|
|
286
|
+
label: LabelIdType;
|
|
287
|
+
/**
|
|
288
|
+
* Type of the label to be opened
|
|
289
|
+
*/
|
|
290
|
+
type: LabelRunModeType;
|
|
291
|
+
}
|
|
292
|
+
interface CloseChoiceOptionInterface extends Omit<ChoiceInterface$1, "label" | "type" | "closeCurrentLabel"> {
|
|
293
|
+
/**
|
|
294
|
+
* Type of the label to be opened
|
|
295
|
+
*/
|
|
296
|
+
type: CloseType;
|
|
297
|
+
/**
|
|
298
|
+
* If true, the current label will be closed
|
|
299
|
+
*/
|
|
300
|
+
closeCurrentLabel?: boolean;
|
|
301
|
+
}
|
|
302
|
+
type StoredChoiceInterface = ChoiceOptionInterface | CloseChoiceOptionInterface;
|
|
303
|
+
type StoredIndexedChoiceInterface = StoredChoiceInterface & {
|
|
304
|
+
/**
|
|
305
|
+
* Is the index of the choice in the menu. It is used to identify the choice when it is selected.
|
|
306
|
+
*/
|
|
307
|
+
choiceIndex: number;
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
interface LabelProps<T, StepIdType = number> {
|
|
311
|
+
/**
|
|
312
|
+
* A function executed before each `step`.
|
|
313
|
+
* @param stepId The index of the `step` being executed
|
|
314
|
+
* @param label The `label` containing the `step`
|
|
315
|
+
* @returns
|
|
316
|
+
* @example
|
|
317
|
+
* ```ts
|
|
318
|
+
* const startLabel = newLabel("start", [
|
|
319
|
+
* () => {
|
|
320
|
+
* narration.dialogue = "Step 1"
|
|
321
|
+
* },
|
|
322
|
+
* () => {
|
|
323
|
+
* narration.dialogue = "Step 2"
|
|
324
|
+
* }
|
|
325
|
+
* ], {
|
|
326
|
+
* onStepStart: (stepIndex, label) => {
|
|
327
|
+
* console.log(`Step ${stepIndex} started`)
|
|
328
|
+
* }
|
|
329
|
+
* })
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
332
|
+
onStepStart?: (stepId: StepIdType, label: T) => void | Promise<void>;
|
|
333
|
+
/**
|
|
334
|
+
* Is a function that will be executed in {@link onStepStart} if the id of the step is 0
|
|
335
|
+
* and when the user laods a save file.
|
|
336
|
+
* When you load a save file, will be executed all onLoadingLabel functions of the {@link narration.openedLabels}.
|
|
337
|
+
* It is useful for example to make sure all images used have been cached
|
|
338
|
+
* @param stepId The index of the `step` being executed
|
|
339
|
+
* @param label The `label` being executed
|
|
340
|
+
* @returns
|
|
341
|
+
* @example
|
|
342
|
+
* ```ts title="content/labels/start.label.ts"
|
|
343
|
+
* newLabel("start", [], {
|
|
344
|
+
* onLoadingLabel: async (stepId, label) => {
|
|
345
|
+
* await Assets.load('path/to/image1.png')
|
|
346
|
+
* await Assets.load('path/to/image2.png')
|
|
347
|
+
* }
|
|
348
|
+
* })
|
|
349
|
+
* ```
|
|
350
|
+
*/
|
|
351
|
+
onLoadingLabel?: (stepId: StepIdType, label: T) => void | Promise<void>;
|
|
352
|
+
/**
|
|
353
|
+
* A function executed after each `step`. See more <DynamicLink href="/start/labels-advanced#onstepend">here</DynamicLink>.
|
|
354
|
+
* @param stepId The index of the `step` that ended
|
|
355
|
+
* @param label The `label` containing the `step`
|
|
356
|
+
* @returns
|
|
357
|
+
* @example
|
|
358
|
+
* ```ts
|
|
359
|
+
* const startLabel = newLabel("start", [
|
|
360
|
+
* async () => {
|
|
361
|
+
* await showImage("image1", "path/to/image1.png")
|
|
362
|
+
* await showImage("image2", "path/to/image2.png")
|
|
363
|
+
* }
|
|
364
|
+
* ], {
|
|
365
|
+
* onLoadingLabel: async (stepIndex, label) => {
|
|
366
|
+
* await Assets.load("path/to/image1.png")
|
|
367
|
+
* await Assets.load("path/to/image2.png")
|
|
368
|
+
* }
|
|
369
|
+
* })
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
onStepEnd?: (stepId: StepIdType, label: T) => void | Promise<void>;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
declare abstract class LabelAbstract<TLabel, TProps extends {} = {}, StepIdType = number> implements LabelProps<TLabel, StepIdType> {
|
|
376
|
+
/**
|
|
377
|
+
* @param id is the id of the label
|
|
378
|
+
* @param props is the properties of the label
|
|
379
|
+
*/
|
|
380
|
+
constructor(id: LabelIdType, props?: LabelProps<TLabel, StepIdType>);
|
|
381
|
+
/**
|
|
382
|
+
* Get the id of the label. This variable is used in the system to get the label by id, {@link RegisteredLabels.get}
|
|
383
|
+
*/
|
|
384
|
+
readonly id: LabelIdType;
|
|
385
|
+
/**
|
|
386
|
+
* Get the number of steps in the label. This variable is used in the system to get the number of steps in the label.
|
|
387
|
+
* @returns The number of steps in the label
|
|
388
|
+
*/
|
|
389
|
+
abstract get stepCount(): number;
|
|
390
|
+
/**
|
|
391
|
+
* Get the sha of the step
|
|
392
|
+
* @param index Index of the step
|
|
393
|
+
*/
|
|
123
394
|
abstract getStepSha(stepId: StepIdType): string | undefined;
|
|
124
395
|
/**
|
|
125
396
|
* Get the step by id
|
|
@@ -291,277 +562,6 @@ interface NarrationGameState {
|
|
|
291
562
|
stepCounter: number;
|
|
292
563
|
}
|
|
293
564
|
|
|
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
565
|
/**
|
|
566
566
|
* StepLabelPropsType is the type of the props that will be passed to the StepLabel.
|
|
567
567
|
* You can override this interface to add your own props.
|
|
@@ -704,6 +704,6 @@ type InputInfo = {
|
|
|
704
704
|
type?: string;
|
|
705
705
|
};
|
|
706
706
|
|
|
707
|
-
declare const narration: NarrationManagerInterface
|
|
707
|
+
declare const narration: NarrationManagerInterface;
|
|
708
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 };
|