@drincs/pixi-vn-json 1.7.2 → 1.7.4

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.
@@ -1,552 +1,6 @@
1
- import { StorageElementType, CanvasBaseInterface, ImageSprite, KeyframesType, AnimationOptions, UPDATE_PRIORITY, ObjectSegment, ObjectSegmentWithTransition, SequenceOptions, ShakeEffectProps, FadeAlphaTickerProps, MoveTickerProps, RotateTickerProps, ZoomTickerProps, ShowWithDissolveTransitionProps, ShowWithFadeTransitionProps, MoveInOutProps, ZoomInOutProps, PushInOutProps, ImageContainerOptions, ImageSpriteOptions, ImageSpriteMemory, VideoSpriteMemory, ImageContainerMemory, ContainerOptions, ContainerMemory, SoundPlayOptions, LabelRunModeType, StorageObjectType, StepLabelPropsType } from '@drincs/pixi-vn';
2
- import { StepLabelPropsType as StepLabelPropsType$1, LabelAbstract, LabelProps, StepLabelType } from '@drincs/pixi-vn/narration';
3
-
4
- type PixiVNJsonStepSwitchElementType<Then> = Then | PixiVNJsonConditionalStatements<Then> | PixiVNJsonConditionalResultToCombine<Then>;
5
- type PixiVNJsonStepSwitchElementsType<Then> = PixiVNJsonStepSwitchElementType<Then>[] | PixiVNJsonConditionalStatements<Then[]>;
6
- interface PixiVNJsonRandom<Then> {
7
- type: "stepswitch";
8
- choiceType: "random";
9
- elements: PixiVNJsonStepSwitchElementsType<Then>;
10
- }
11
- interface PixiVNJsonSequentialRandom<Then> {
12
- type: "stepswitch";
13
- choiceType: "sequentialrandom";
14
- elements: PixiVNJsonStepSwitchElementsType<Then>;
15
- /**
16
- * When the sequential ends, what should be the value? If undefined, it will return undefined.
17
- * If "lastItem", it will return the last item in the array.
18
- */
19
- end: undefined | "lastItem";
20
- /**
21
- * The subId is used for manager nested switches
22
- */
23
- nestedId?: string;
24
- }
25
- interface PixiVNJsonSequential<Then> {
26
- type: "stepswitch";
27
- choiceType: "sequential";
28
- elements: PixiVNJsonStepSwitchElementsType<Then>;
29
- /**
30
- * When the sequential ends, what should be the value? If undefined, it will return undefined.
31
- * If "lastItem", it will return the last item in the array.
32
- */
33
- end: undefined | "lastItem";
34
- /**
35
- * The subId is used for manager nested switches
36
- */
37
- nestedId?: string;
38
- }
39
- interface PixiVNJsonLoop<Then> {
40
- type: "stepswitch";
41
- choiceType: "loop";
42
- elements: PixiVNJsonStepSwitchElementsType<Then>;
43
- nestedId?: string;
44
- }
45
- type PixiVNJsonStepSwitch<Then> = PixiVNJsonRandom<Then> | PixiVNJsonSequential<Then> | PixiVNJsonLoop<Then> | PixiVNJsonSequentialRandom<Then>;
46
-
47
- /**
48
- * This element is used in case a {@link PixiVNJsonConditionalStatements} gives a result that must be combined with another calculated through other {@link PixiVNJsonConditionalStatements}.
49
- * in case this possibility is not managed, it will be taken into consideration {@link PixiVNJsonConditionalResultToCombine.firstItem}
50
- */
51
- type PixiVNJsonConditionalResultToCombine<T> = {
52
- type: "resulttocombine";
53
- /**
54
- * This variable is interpreted differently by Pixi'VN depending on the value
55
- */
56
- combine: "cross" | "union";
57
- firstItem?: T;
58
- secondConditionalItem?: PixiVNJsonStepSwitchElementType<T>[];
59
- };
60
-
61
- type PixiVNJsonStorageGet = {
62
- type: "value";
63
- storageOperationType: "get";
64
- /**
65
- * Key of the storage
66
- */
67
- key: string;
68
- /**
69
- * Type of the storage, if it is a flagStorage or a storage.
70
- * If it is a flagStorage, the value will be get with the function {@link getFlag}
71
- */
72
- storageType: "storage" | "flagStorage" | "tempstorage";
73
- };
74
- type PixiVNJsonParamGet = {
75
- type: "value";
76
- storageOperationType: "get";
77
- /**
78
- * Key of the storage
79
- */
80
- key: number;
81
- storageType: "params";
82
- };
83
- type PixiVNJsonLabelGet = {
84
- type: "value";
85
- storageOperationType: "get";
86
- /**
87
- * Id of the label
88
- */
89
- label: string;
90
- /**
91
- * If it is a label, the value will be get with the function {@link narration.getTimesLabelOpened}
92
- */
93
- storageType: "label";
94
- };
95
- type PixiVNJsonChoiceGet = {
96
- type: "value";
97
- storageOperationType: "get";
98
- /**
99
- * index of the choice
100
- */
101
- index: number;
102
- /**
103
- * If it is a choice, the value will be get with the function {@link narration.getTimesChoiceOpened}
104
- */
105
- storageType: "choice";
106
- };
107
- type PixiVNJsonLogicGet = {
108
- type: "value";
109
- storageOperationType: "get";
110
- operation: PixiVNJsonArithmeticOperations | PixiVNJsonConditions;
111
- storageType: "logic";
112
- };
113
- type PixiVNJsonValueGet = PixiVNJsonStorageGet | PixiVNJsonParamGet | PixiVNJsonLabelGet | PixiVNJsonChoiceGet | PixiVNJsonLogicGet;
114
- type PixiVNJsonOnlyStorageSet = {
115
- type: "value";
116
- storageOperationType: "set";
117
- /**
118
- * Key of the storage
119
- */
120
- key: string;
121
- /**
122
- * Value to be set in the storage
123
- */
124
- value: StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations | PixiVNJsonConditionalStatements<StorageElementType>;
125
- /**
126
- * Type of the storage, if it is a flagStorage or a storage.
127
- */
128
- storageType: "storage" | "tempstorage";
129
- };
130
- type PixiVNJsonOnlyParamSet = {
131
- type: "value";
132
- storageOperationType: "set";
133
- /**
134
- * Key of the storage
135
- */
136
- key: number;
137
- /**
138
- * Value to be set in the storage
139
- */
140
- value: StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations | PixiVNJsonConditionalStatements<StorageElementType>;
141
- storageType: "params";
142
- };
143
- type PixiVNJsonFlagSet = {
144
- type: "value";
145
- storageOperationType: "set";
146
- /**
147
- * Key of the storage
148
- */
149
- key: string;
150
- /**
151
- * Value to be set in the storage
152
- */
153
- value: boolean;
154
- /**
155
- * Type of the storage, if it is a flagStorage or a storage.
156
- */
157
- storageType: "flagStorage";
158
- };
159
- type PixiVNJsonValueSet = PixiVNJsonOnlyStorageSet | PixiVNJsonFlagSet | PixiVNJsonOnlyParamSet;
160
-
161
- interface PixiVNJsonArithmeticOperationsArithmetic {
162
- type: "arithmetic";
163
- /**
164
- * Left value of the arithmetic operation
165
- */
166
- leftValue: StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations | PixiVNJsonConditionalStatements<StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations>;
167
- /**
168
- * Right value of the arithmetic operation
169
- */
170
- rightValue: StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations | PixiVNJsonConditionalStatements<StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations>;
171
- /**
172
- * Operator of the arithmetic operation
173
- */
174
- operator: "*" | "/" | "+" | "-" | "%" | "POW" | "RANDOM";
175
- }
176
- interface PixiVNJsonArithmeticOperationsArithmeticSingle {
177
- type: "arithmeticsingle";
178
- /**
179
- * Left value of the arithmetic operation
180
- */
181
- leftValue: StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations | PixiVNJsonConditionalStatements<StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations>;
182
- /**
183
- * Operator of the arithmetic operation
184
- */
185
- operator: "INT" | "FLOOR" | "FLOAT";
186
- }
187
- /**
188
- * Arithmetic operations for the PixiVNJson
189
- */
190
- type PixiVNJsonArithmeticOperations = PixiVNJsonArithmeticOperationsArithmeticSingle | PixiVNJsonArithmeticOperationsArithmetic;
191
-
192
- type PixiVNJsonUnionConditionAndOr = {
193
- type: "union";
194
- conditions: PixiVNJsonConditions[];
195
- unionType: "and" | "or";
196
- };
197
- type PixiVNJsonUnionConditionNot = {
198
- type: "union";
199
- condition: PixiVNJsonConditions;
200
- unionType: "not";
201
- };
202
- type PixiVNJsonUnionCondition = PixiVNJsonUnionConditionAndOr | PixiVNJsonUnionConditionNot;
203
-
204
- /**
205
- * Comparation for PixiVNJson.
206
- * In this comparation, the values to be converted to string and compared.
207
- */
208
- type PixiVNJsonComparation = {
209
- type: "compare";
210
- /**
211
- * Left value of the comparation
212
- */
213
- leftValue: StorageElementType | PixiVNJsonValueGet | PixiVNJsonConditions;
214
- /**
215
- * Right value of the comparation
216
- */
217
- rightValue: StorageElementType | PixiVNJsonValueGet | PixiVNJsonConditions;
218
- /**
219
- * Operator of the comparation
220
- */
221
- operator: "==" | "!=" | "<" | "<=" | ">" | ">=" | "CONTAINS";
222
- };
223
- type PixiVNJsonValueCondition = StorageElementType | PixiVNJsonValueGet;
224
- /**
225
- * Conditions for PixiVNJson
226
- */
227
- type PixiVNJsonConditions = PixiVNJsonComparation | PixiVNJsonValueCondition | PixiVNJsonUnionCondition | PixiVNJsonArithmeticOperations;
228
-
229
- /**
230
- * If-Else condition for PixiVNJson
231
- */
232
- interface PixiVNJsonIfElse<Then> {
233
- type: "ifelse";
234
- /**
235
- * The list of conditions to be checked.
236
- */
237
- condition: PixiVNJsonConditions;
238
- /**
239
- * The value to be returned if the condition is true.
240
- */
241
- then: Then | PixiVNJsonIfElse<Then>;
242
- /**
243
- * The value to be returned if the condition is false.
244
- */
245
- else?: Then | PixiVNJsonIfElse<Then>;
246
- }
247
-
248
- type PixiVNJsonConditionalStatements<Then> = PixiVNJsonStepSwitch<Then> | PixiVNJsonIfElse<Then | PixiVNJsonConditionalStatements<Then> | PixiVNJsonConditionalResultToCombine<Then>>;
249
-
250
- type PixiVNJsonAnimateBase<T extends CanvasBaseInterface<any>> = {
251
- type: "animate";
252
- alias: string | string[];
253
- keyframes: KeyframesType<T>;
254
- options?: AnimationOptions;
255
- priority?: UPDATE_PRIORITY;
256
- };
257
- type PixiVNJsonAnimateSequence<T extends CanvasBaseInterface<any>> = {
258
- type: "animate-sequence";
259
- alias: string;
260
- sequence: (ObjectSegment<T> | ObjectSegmentWithTransition<T>)[];
261
- options?: SequenceOptions;
262
- priority?: UPDATE_PRIORITY;
263
- };
264
- type PixiVNJsonCanvasAnimate<T extends CanvasBaseInterface<any> = ImageSprite> = PixiVNJsonAnimateBase<T> | PixiVNJsonAnimateSequence<T>;
265
-
266
- type PixiVNJsonEffectShake = {
267
- type: "shake";
268
- alias: string;
269
- props: ShakeEffectProps;
270
- priority?: UPDATE_PRIORITY;
271
- };
272
- type PixiVNJsonCanvasEffect = PixiVNJsonEffectShake;
273
-
274
- /**
275
- * @deprecated
276
- */
277
- type PixiVNJsonTickerFade = {
278
- type: "fade";
279
- alias: string | string[];
280
- duration?: number;
281
- props: FadeAlphaTickerProps;
282
- priority?: UPDATE_PRIORITY;
283
- };
284
- /**
285
- * @deprecated
286
- */
287
- type PixiVNJsonTickerMove = {
288
- type: "move";
289
- alias: string | string[];
290
- duration?: number;
291
- props: MoveTickerProps;
292
- priority?: UPDATE_PRIORITY;
293
- };
294
- /**
295
- * @deprecated
296
- */
297
- type PixiVNJsonTickerRotate = {
298
- type: "rotate";
299
- alias: string | string[];
300
- duration?: number;
301
- props: RotateTickerProps;
302
- priority?: UPDATE_PRIORITY;
303
- };
304
- /**
305
- * @deprecated
306
- */
307
- type PixiVNJsonTickerZoom = {
308
- type: "zoom";
309
- alias: string | string[];
310
- duration?: number;
311
- props: ZoomTickerProps;
312
- priority?: UPDATE_PRIORITY;
313
- };
314
- /**
315
- * @deprecated
316
- */
317
- type PixiVNJsonCanvasTicker = PixiVNJsonTickerFade | PixiVNJsonTickerMove | PixiVNJsonTickerRotate | PixiVNJsonTickerZoom;
318
-
319
- type DissolveTransition = {
320
- type: "dissolve";
321
- props?: ShowWithDissolveTransitionProps;
322
- priority?: UPDATE_PRIORITY;
323
- };
324
- type FadeTransition = {
325
- type: "fade";
326
- props?: ShowWithFadeTransitionProps;
327
- priority?: UPDATE_PRIORITY;
328
- };
329
- type MoveInOutTransition = {
330
- type: "movein" | "moveout";
331
- props?: MoveInOutProps;
332
- priority?: UPDATE_PRIORITY;
333
- };
334
- type ZoomInOutTransition = {
335
- type: "zoomin" | "zoomout";
336
- props?: ZoomInOutProps;
337
- priority?: UPDATE_PRIORITY;
338
- };
339
- type PushInOutTransition = {
340
- type: "pushin" | "pushout";
341
- props?: PushInOutProps;
342
- priority?: UPDATE_PRIORITY;
343
- };
344
- type PixiVNJsonMediaTransiotions = DissolveTransition | FadeTransition | MoveInOutTransition | ZoomInOutTransition | PushInOutTransition;
345
-
346
- type PixiVNJsonCanvasImageVideoShow = {
347
- type: "image" | "video";
348
- operationType: "show";
349
- alias: string;
350
- /**
351
- * The url of the image or video.
352
- * If the url is not provided, the url will be set to the alias.
353
- */
354
- url?: string;
355
- props?: ImageSpriteOptions;
356
- transition?: PixiVNJsonMediaTransiotions;
357
- };
358
- type PixiVNJsonCanvasImageContainerShow = {
359
- type: "imagecontainer";
360
- operationType: "show";
361
- alias: string;
362
- urls: string[];
363
- props?: ImageContainerOptions<ImageSprite>;
364
- transition?: PixiVNJsonMediaTransiotions;
365
- };
366
- type PixiVNJsonImageEdit = {
367
- type: "image";
368
- operationType: "edit";
369
- alias: string;
370
- props?: Partial<ImageSpriteMemory>;
371
- };
372
- type PixiVNJsonVideoEdit = {
373
- type: "video";
374
- operationType: "edit";
375
- alias: string;
376
- props?: Partial<VideoSpriteMemory>;
377
- };
378
- type PixiVNJsonImageContainerEdit = {
379
- type: "imagecontainer";
380
- operationType: "edit";
381
- alias: string;
382
- props?: Partial<ImageContainerMemory>;
383
- };
384
- type PixiVNJsonUnknownEdit<T extends ContainerOptions> = {
385
- type: "canvaselement";
386
- operationType: "edit";
387
- alias: string;
388
- props?: Partial<T>;
389
- };
390
- type PixiVNJsonCanvasRemove = {
391
- type: "image" | "video" | "imagecontainer" | "canvaselement";
392
- operationType: "remove";
393
- alias: string;
394
- transition?: PixiVNJsonMediaTransiotions;
395
- };
396
- type PixiVNJsonVideoPauseResume = {
397
- type: "video";
398
- operationType: "pause" | "resume";
399
- alias: string;
400
- };
401
- type PixiVNJsonAssetsLoad = {
402
- type: "assets" | "bundle";
403
- operationType: "load" | "lazyload";
404
- aliases: string[];
405
- };
406
- type PixiVNJsonCanvasShow = PixiVNJsonCanvasImageContainerShow | PixiVNJsonCanvasImageVideoShow;
407
- type PixiVNJsonCanvasEdit = PixiVNJsonImageEdit | PixiVNJsonVideoEdit | PixiVNJsonImageContainerEdit | PixiVNJsonUnknownEdit<ImageSpriteMemory | VideoSpriteMemory | ContainerMemory>;
408
- type PixiVNJsonCanvas = PixiVNJsonCanvasShow | PixiVNJsonCanvasEdit | PixiVNJsonCanvasRemove | PixiVNJsonVideoPauseResume | PixiVNJsonAssetsLoad | PixiVNJsonCanvasTicker | PixiVNJsonCanvasAnimate | PixiVNJsonCanvasEffect;
409
-
410
- type PixiVNJsonInputRequest = {
411
- type: "input";
412
- operationType: "request";
413
- valueType?: string;
414
- defaultValue?: any;
415
- };
416
- type PixiVNJsonInput = PixiVNJsonInputRequest;
417
-
418
- type PixiVNJsonSoundPlay = {
419
- type: "sound";
420
- operationType: "play";
421
- alias: string;
422
- props?: SoundPlayOptions;
423
- };
424
- type PixiVNJsonSoundRemove = {
425
- type: "sound";
426
- operationType: "stop";
427
- alias: string;
428
- };
429
- type PixiVNJsonSoundPauseResume = {
430
- type: "sound";
431
- operationType: "pause" | "resume";
432
- alias: string;
433
- };
434
- type PixiVNJsonSoundVolume = {
435
- type: "sound";
436
- operationType: "volume";
437
- alias: string;
438
- value: number;
439
- };
440
- type PixiVNJsonSound = PixiVNJsonSoundPlay | PixiVNJsonSoundRemove | PixiVNJsonSoundPauseResume | PixiVNJsonSoundVolume;
441
-
442
- type PixiVNJsonOperationString = {
443
- type: "operationtoconvert";
444
- values: (string | PixiVNJsonValueGet | PixiVNJsonConditionalStatements<string | PixiVNJsonValueGet>)[];
445
- };
446
- type PixiVNJsonOperation = PixiVNJsonValueSet | PixiVNJsonCanvas | PixiVNJsonSound | PixiVNJsonInput;
447
- type PixiVNJsonConditionalOperation = PixiVNJsonOperation | PixiVNJsonIfElse<PixiVNJsonOperation> | PixiVNJsonOperationString;
448
-
449
- type PixiVNJsonChoice = {
450
- /**
451
- * The text to be displayed.
452
- */
453
- text: PixiVNJsonDialogText;
454
- /**
455
- * The label id to be opened.
456
- */
457
- label: string;
458
- /**
459
- * Label opening mode
460
- */
461
- type: LabelRunModeType;
462
- /**
463
- * The properties to be passed to the label.
464
- */
465
- props: StorageObjectType;
466
- /**
467
- * If this is true, the choice can only be made once.
468
- */
469
- oneTime?: boolean;
470
- /**
471
- * If this is true, the choice can see only if there are no other choices. For example, all choices are one-time choices and they are already selected.
472
- */
473
- onlyHaveNoChoice?: boolean;
474
- /**
475
- * If this is true and if is the only choice, it will be automatically selected, and call/jump to the label.
476
- */
477
- autoSelect?: boolean;
478
- };
479
- type PixiVNJsonChoices = (PixiVNJsonChoice | PixiVNJsonConditionalStatements<PixiVNJsonChoice>)[];
480
- type PixiVNJsonDialogText = string | PixiVNJsonValueGet | PixiVNJsonConditionalStatements<string | PixiVNJsonValueGet | string[]> | (string | PixiVNJsonValueGet | PixiVNJsonConditionalStatements<string | PixiVNJsonValueGet | string[]>)[];
481
- type PixiVNJsonDialog<Text = string> = {
482
- /**
483
- * The character id that will speak.
484
- */
485
- character: string;
486
- /**
487
- * The text to be displayed.
488
- */
489
- text: Text;
490
- } | Text;
491
- type PixiVNJsonLabelToOpen<T extends {} = {}> = {
492
- /**
493
- * The id of the label to open.
494
- */
495
- label: string | PixiVNJsonValueGet;
496
- /**
497
- * Label opening mode
498
- */
499
- type: LabelRunModeType;
500
- /**
501
- * The properties to be passed to the label. if you don't want to pass a object, but a list of parameters, you can use the {@link PixiVNJsonLabelToOpen.params} attribute.
502
- */
503
- props?: StepLabelPropsType<T>;
504
- /**
505
- * **It is not recommended to use it, use it only if necessary**. The parameters to be passed to the label. If you want to pass an object, use the {@link PixiVNJsonLabelToOpen.props} attribute.
506
- * "params" attribute will be stored in the temp storage with the key: {@link PIXIVNJSON_PARAM_ID} + ({@link narration.openedLabels.length} - 1).
507
- */
508
- params?: any[];
509
- };
510
- /**
511
- * Steps of a label.
512
- * Order of operations:
513
- * 1. run all {@link PixiVNJsonLabelStep.operations}
514
- * 2. set {@link PixiVNJsonLabelStep.choices}, {@link PixiVNJsonLabelStep.dialogue}, {@link PixiVNJsonLabelStep.glueEnabled}
515
- * 3. open {@link PixiVNJsonLabelStep.labelToOpen}
516
- * 4. go to next step if {@link PixiVNJsonLabelStep.goNextStep} is true
517
- * 5. end the label if {@link PixiVNJsonLabelStep.end} is "label_end"
518
- */
519
- type PixiVNJsonLabelStep = {
520
- operations?: PixiVNJsonConditionalOperation[];
521
- /**
522
- * Variable used to display a choice menu.
523
- */
524
- choices?: PixiVNJsonChoices | PixiVNJsonConditionalStatements<PixiVNJsonChoices>;
525
- /**
526
- * Variable used to display a dialog.
527
- */
528
- dialogue?: PixiVNJsonDialog<PixiVNJsonDialogText> | PixiVNJsonConditionalStatements<PixiVNJsonDialog<PixiVNJsonDialogText>>;
529
- /**
530
- * This variable is used to add the next dialog text into the current dialog memory.
531
- * This value was added to introduce Ink Glue functionality https://github.com/inkle/ink/blob/master/Documentation/WritingWithInk.md#glue
532
- */
533
- glueEnabled?: boolean | PixiVNJsonConditionalStatements<boolean>;
534
- /**
535
- * Variable used to open a label.
536
- */
537
- labelToOpen?: PixiVNJsonLabelToOpen | PixiVNJsonConditionalStatements<PixiVNJsonLabelToOpen> | (PixiVNJsonLabelToOpen | PixiVNJsonConditionalStatements<PixiVNJsonLabelToOpen>)[];
538
- /**
539
- * If is true, the next step will be executed automatically.
540
- */
541
- goNextStep?: boolean | PixiVNJsonConditionalStatements<boolean>;
542
- /**
543
- * Variable used to end some elements of the narrative.
544
- * - game_end: ends the game
545
- * - label_end: ends the label
546
- */
547
- end?: "game_end" | "label_end" | PixiVNJsonConditionalStatements<"game_end" | "label_end">;
548
- conditionalStep?: PixiVNJsonConditionalStatements<PixiVNJsonLabelStep | PixiVNJsonLabelStep[]>;
549
- };
1
+ import { P as PixiVNJsonLabelStep, a as PixiVNJsonConditionalOperation, b as PixiVNJsonOperation } from './PixiVNJsonLabelStep-CNFnTNr1.js';
2
+ import { StepLabelPropsType, LabelAbstract, LabelProps, StepLabelType } from '@drincs/pixi-vn/narration';
3
+ import '@drincs/pixi-vn';
550
4
 
551
5
  /**
552
6
  * Collection of labels to be used in the narrative.
@@ -576,7 +30,7 @@ type LabelJsonOptions = {
576
30
  * Function that converts a string to a {@link PixiVNJsonOperation}.
577
31
  * If is a special operation you can return undefined and can run the operation.
578
32
  */
579
- operationStringConvert?: (value: string, step: PixiVNJsonLabelStep, props: StepLabelPropsType$1 | {}) => Promise<PixiVNJsonOperation | undefined>;
33
+ operationStringConvert?: (value: string, step: PixiVNJsonLabelStep, props: StepLabelPropsType | {}) => Promise<PixiVNJsonOperation | undefined>;
580
34
  /**
581
35
  * If true and a dialog is empty or has only spaces, {@link PixiVNJsonLabelStep.goNextStep} will be set to true.
582
36
  */
package/dist/importer.mjs CHANGED
@@ -1 +1 @@
1
- import {RegisteredLabels,LabelAbstract,narration}from'@drincs/pixi-vn/narration';import {storage,SYSTEM_RESERVED_STORAGE_KEYS}from'@drincs/pixi-vn/storage';var Y=Object.create;var B=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var U=Object.getPrototypeOf,ee=Object.prototype.hasOwnProperty;var ie=(a,e,i)=>e in a?B(a,e,{enumerable:true,configurable:true,writable:true,value:i}):a[e]=i;var R=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(e,i)=>(typeof require<"u"?require:e)[i]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var K=(a,e)=>()=>(e||a((e={exports:{}}).exports,e),e.exports);var te=(a,e,i,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Z(e))!ee.call(a,n)&&n!==i&&B(a,n,{get:()=>e[n],enumerable:!(o=Q(e,n))||o.enumerable});return a};var ne=(a,e,i)=>(i=a!=null?Y(U(a)):{},te(B(i,"default",{value:a,enumerable:true}),a));var N=(a,e,i)=>ie(a,typeof e!="symbol"?e+"":e,i);var M=K((L,G)=>{(function(a,e){typeof L=="object"?G.exports=L=e():typeof define=="function"&&define.amd?define([],e):a.CryptoJS=e();})(L,function(){var a=a||(function(e,i){var o;if(typeof window<"u"&&window.crypto&&(o=window.crypto),typeof self<"u"&&self.crypto&&(o=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(o=globalThis.crypto),!o&&typeof window<"u"&&window.msCrypto&&(o=window.msCrypto),!o&&typeof global<"u"&&global.crypto&&(o=global.crypto),!o&&typeof R=="function")try{o=R("crypto");}catch{}var n=function(){if(o){if(typeof o.getRandomValues=="function")try{return o.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof o.randomBytes=="function")try{return o.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},s=Object.create||(function(){function t(){}return function(r){var x;return t.prototype=r,x=new t,t.prototype=null,x}})(),c={},f=c.lib={},g=f.Base=(function(){return {extend:function(t){var r=s(this);return t&&r.mixIn(t),(!r.hasOwnProperty("init")||this.init===r.init)&&(r.init=function(){r.$super.init.apply(this,arguments);}),r.init.prototype=r,r.$super=this,r},create:function(){var t=this.extend();return t.init.apply(t,arguments),t},init:function(){},mixIn:function(t){for(var r in t)t.hasOwnProperty(r)&&(this[r]=t[r]);t.hasOwnProperty("toString")&&(this.toString=t.toString);},clone:function(){return this.init.prototype.extend(this)}}})(),m=f.WordArray=g.extend({init:function(t,r){t=this.words=t||[],r!=i?this.sigBytes=r:this.sigBytes=t.length*4;},toString:function(t){return (t||h).stringify(this)},concat:function(t){var r=this.words,x=t.words,d=this.sigBytes,C=t.sigBytes;if(this.clamp(),d%4)for(var b=0;b<C;b++){var D=x[b>>>2]>>>24-b%4*8&255;r[d+b>>>2]|=D<<24-(d+b)%4*8;}else for(var T=0;T<C;T+=4)r[d+T>>>2]=x[T>>>2];return this.sigBytes+=C,this},clamp:function(){var t=this.words,r=this.sigBytes;t[r>>>2]&=4294967295<<32-r%4*8,t.length=e.ceil(r/4);},clone:function(){var t=g.clone.call(this);return t.words=this.words.slice(0),t},random:function(t){for(var r=[],x=0;x<t;x+=4)r.push(n());return new m.init(r,t)}}),u=c.enc={},h=u.Hex={stringify:function(t){for(var r=t.words,x=t.sigBytes,d=[],C=0;C<x;C++){var b=r[C>>>2]>>>24-C%4*8&255;d.push((b>>>4).toString(16)),d.push((b&15).toString(16));}return d.join("")},parse:function(t){for(var r=t.length,x=[],d=0;d<r;d+=2)x[d>>>3]|=parseInt(t.substr(d,2),16)<<24-d%8*4;return new m.init(x,r/2)}},P=u.Latin1={stringify:function(t){for(var r=t.words,x=t.sigBytes,d=[],C=0;C<x;C++){var b=r[C>>>2]>>>24-C%4*8&255;d.push(String.fromCharCode(b));}return d.join("")},parse:function(t){for(var r=t.length,x=[],d=0;d<r;d++)x[d>>>2]|=(t.charCodeAt(d)&255)<<24-d%4*8;return new m.init(x,r)}},S=u.Utf8={stringify:function(t){try{return decodeURIComponent(escape(P.stringify(t)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(t){return P.parse(unescape(encodeURIComponent(t)))}},V=f.BufferedBlockAlgorithm=g.extend({reset:function(){this._data=new m.init,this._nDataBytes=0;},_append:function(t){typeof t=="string"&&(t=S.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes;},_process:function(t){var r,x=this._data,d=x.words,C=x.sigBytes,b=this.blockSize,D=b*4,T=C/D;t?T=e.ceil(T):T=e.max((T|0)-this._minBufferSize,0);var _=T*b,$=e.min(_*4,C);if(_){for(var z=0;z<_;z+=b)this._doProcessBlock(d,z);r=d.splice(0,_),x.sigBytes-=$;}return new m.init(r,$)},clone:function(){var t=g.clone.call(this);return t._data=this._data.clone(),t},_minBufferSize:0});f.Hasher=V.extend({cfg:g.extend(),init:function(t){this.cfg=this.cfg.extend(t),this.reset();},reset:function(){V.reset.call(this),this._doReset();},update:function(t){return this._append(t),this._process(),this},finalize:function(t){t&&this._append(t);var r=this._doFinalize();return r},blockSize:512/32,_createHelper:function(t){return function(r,x){return new t.init(x).finalize(r)}},_createHmacHelper:function(t){return function(r,x){return new v.HMAC.init(t,x).finalize(r)}}});var v=c.algo={};return c})(Math);return a});});var F=K((I,W)=>{(function(a,e){typeof I=="object"?W.exports=I=e(M()):typeof define=="function"&&define.amd?define(["./core"],e):e(a.CryptoJS);})(I,function(a){return (function(){var e=a,i=e.lib,o=i.WordArray,n=i.Hasher,s=e.algo,c=[],f=s.SHA1=n.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(g,m){for(var u=this._hash.words,h=u[0],P=u[1],S=u[2],V=u[3],y=u[4],v=0;v<80;v++){if(v<16)c[v]=g[m+v]|0;else {var t=c[v-3]^c[v-8]^c[v-14]^c[v-16];c[v]=t<<1|t>>>31;}var r=(h<<5|h>>>27)+y+c[v];v<20?r+=(P&S|~P&V)+1518500249:v<40?r+=(P^S^V)+1859775393:v<60?r+=(P&S|P&V|S&V)-1894007588:r+=(P^S^V)-899497514,y=V,V=S,S=P<<30|P>>>2,P=h,h=r;}u[0]=u[0]+h|0,u[1]=u[1]+P|0,u[2]=u[2]+S|0,u[3]=u[3]+V|0,u[4]=u[4]+y|0;},_doFinalize:function(){var g=this._data,m=g.words,u=this._nDataBytes*8,h=g.sigBytes*8;return m[h>>>5]|=128<<24-h%32,m[(h+64>>>9<<4)+14]=Math.floor(u/4294967296),m[(h+64>>>9<<4)+15]=u,g.sigBytes=m.length*4,this._process(),this._hash},clone:function(){var g=n.clone.call(this);return g._hash=this._hash.clone(),g}});e.SHA1=n._createHelper(f),e.HmacSHA1=n._createHmacHelper(f);})(),a.SHA1});});var J;(n=>(n.log=(s,...c)=>console.log(`[Pixi\u2019VN Json] ${s}`,...c),n.warn=(s,...c)=>console.warn(`[Pixi\u2019VN Json] ${s}`,...c),n.error=(s,...c)=>console.error(`[Pixi\u2019VN Json] ${s}`,...c),n.info=(s,...c)=>console.info(`[Pixi\u2019VN Json] ${s}`,...c)))(J||(J={}));var l=class{static init(e){this._loadAssets=e.loadAssets,this._soundOperation=e.soundOperation,this._imageOperation=e.imageOperation,this._videoOperation=e.videoOperation,this._imageContainerOperation=e.imageContainerOperation,this._canvasElementOperation=e.canvasElementOperation,this._setStorageValue=e.setStorageValue,this._inputOperation=e.inputOperation,this._tickerOperation=e.tickerOperation,this._effectOperation=e.effectOperation,this._animateOperation=e.animateOperation,this._getLogichValue=e.getLogichValue,this._getConditionalStep=e.getConditionalStep;}static get loadAssets(){return this._loadAssets}static get soundOperation(){return this._soundOperation}static get imageOperation(){return this._imageOperation}static get videoOperation(){return this._videoOperation}static get imageContainerOperation(){return this._imageContainerOperation}static get canvasElementOperation(){return this._canvasElementOperation}static get setStorageValue(){return this._setStorageValue}static get inputOperation(){return this._inputOperation}static get tickerOperation(){return this._tickerOperation}static get effectOperation(){return this._effectOperation}static get animateOperation(){return this._animateOperation}static get getLogichValue(){return this._getLogichValue}static get getConditionalStep(){return this._getConditionalStep}};N(l,"_loadAssets",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),N(l,"_soundOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),N(l,"_imageOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),N(l,"_videoOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),N(l,"_imageContainerOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),N(l,"_canvasElementOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),N(l,"_setStorageValue",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),N(l,"_inputOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),N(l,"_tickerOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),N(l,"_effectOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),N(l,"_animateOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),N(l,"_getLogichValue",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),N(l,"_getConditionalStep",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")});async function A(a,e){let i=l.getLogichValue(a);if(i)switch(i.type){case "sound":l.soundOperation(i);break;case "assets":case "bundle":await l.loadAssets(i);break;case "image":await l.imageOperation(i);break;case "video":await l.videoOperation(i);break;case "imagecontainer":await l.imageContainerOperation(i);break;case "canvaselement":await l.canvasElementOperation(i);break;case "value":l.setStorageValue(i);break;case "operationtoconvert":if(e){let o="";i.values.forEach(s=>{if(typeof s=="string")o+=s;else {let c=l.getLogichValue(s);o+=`${c}`;}});let n=await e(o);n&&await A(n,e);}break;case "input":l.inputOperation(i);break;case "fade":case "move":case "rotate":case "zoom":l.tickerOperation(i);break;case "shake":await l.effectOperation(i);break;case "animate":case "animate-sequence":l.animateOperation(i);break}}async function re(a,e={}){let{operationStringConvert:i,skipEmptyDialogs:o}=e;if(!Array.isArray(a))if(typeof a=="object"||typeof a=="string")a=[a];else {J.error("Error parsing imported Pixi'VN JSON: data is not an object");return}let n=a.map(async f=>{if(typeof f=="string")try{f=JSON.parse(f);}catch(g){J.error("Error parsing imported Pixi'VN JSON",g),f={};}return f}),c=(await Promise.all(n)).map(async f=>{let g=[];if(f.initialOperations){f.initialOperations.forEach(u=>{let h=A(u,i?P=>i(P,{},{}):void 0);g.push(h);});let m={};[...storage.storage.keys()].forEach((u,h)=>{m[u]=storage.storage.get(u);}),storage.startingStorage=m;}if(f.labels){let m=f.labels;for(let u in m)try{let h=m[u],P=new O(u,h,void 0,e);RegisteredLabels.add(P);}catch(h){J.error(`Error creating JSON label ${u}`,h);}}return Promise.all(g)});await Promise.all(c);}var q=ne(F());var H="___param___";var p=class p{static t(e){return Array.isArray(e)?e.map(i=>p.translate(`${i}`)):p.translate(`${e}`)}static set beforeToTranslate(e){p._beforeToTranslate=e;}static set translate(e){p._translate=e;}static get translate(){return e=>{let i=e;return p._beforeToTranslate&&(i=p._beforeToTranslate(i)),i=p._translate(i),p._afterToTranslate&&(i=p._afterToTranslate(i)),i}}static set afterToTranslate(e){p._afterToTranslate=e;}static addKey(e,i,o){let n=o.defaultValue||"empty_string";typeof i=="string"&&(i=[i]),Array.isArray(i)&&i.forEach(s=>{e[s]===void 0&&(n==="empty_string"?e[s]="":n==="copy_key"&&(p._beforeToTranslate?e[s]=p._beforeToTranslate(s):e[s]=s));});}static getConditionalsThenElse(e,i=[]){if(typeof e=="object"&&e&&"type"in e)if(e.type==="ifelse")e.then&&p.getConditionalsThenElse(e.then,i),e.else&&p.getConditionalsThenElse(e.else,i);else if(e.type==="stepswitch"){if(e.elements)if(Array.isArray(e.elements))e.elements.forEach(o=>{p.getConditionalsThenElse(o,i);});else if(e.elements.type==="ifelse"){let o=[];p.getConditionalsThenElse(e.elements,o),o.forEach(n=>{i.push(...n);});}else if(e.elements.type==="stepswitch"){let o=[];p.getConditionalsThenElse(e.elements,o),o.forEach(n=>{i.push(...n);});}else p.getConditionalsThenElse(e.elements,i);}else e.type==="resulttocombine"?(e.firstItem&&p.getConditionalsThenElse(e.firstItem,i),e.secondConditionalItem&&e.secondConditionalItem.forEach(o=>{p.getConditionalsThenElse(o,i);})):i.push(e);else e&&i.push(e);return i}static generateJsonTranslation(e,i={},o={}){let{defaultValue:n="copy_key"}=o;return e.forEach(s=>{if(s.choices){let c=[];Array.isArray(s.choices)?c=[s.choices]:c=p.getConditionalsThenElse(s.choices),c.forEach(f=>f.forEach(g=>{if("type"in g){let m=[];g.type==="ifelse"||g.type==="stepswitch"?p.getConditionalsThenElse(g,m):m=[g],m.map(h=>p.getConditionalsThenElse(h.text)).forEach(h=>{Array.isArray(h)&&h.forEach(P=>{Array.isArray(P)?P.forEach(S=>{typeof S=="string"?p.addKey(i,S,{defaultValue:n}):p.getConditionalsThenElse(S).forEach(V=>{Array.isArray(V)?V.forEach(y=>{typeof y=="string"&&p.addKey(i,y,{defaultValue:n});}):typeof V=="string"&&p.addKey(i,V,{defaultValue:n});});}):typeof P=="string"&&p.addKey(i,P,{defaultValue:n});});});}}));}if(s.dialogue){let c=[];Array.isArray(s.dialogue)?c=[s.dialogue]:c=p.getConditionalsThenElse(s.dialogue),c.forEach(f=>{if(typeof f=="string")p.addKey(i,f,{defaultValue:n});else if("text"in f){let g=p.getConditionalsThenElse(f.text);typeof g=="string"&&(g=[g]),g.forEach(m=>{typeof m=="string"?p.addKey(i,m,{defaultValue:n}):p.getConditionalsThenElse(m).forEach(h=>{typeof h=="string"?p.addKey(i,h,{defaultValue:n}):Array.isArray(h)&&h.forEach(P=>{typeof P=="string"?p.addKey(i,P,{defaultValue:n}):p.getConditionalsThenElse(P).forEach(S=>{typeof S=="string"&&p.addKey(i,S,{defaultValue:n});});});});});}});}s.conditionalStep&&p.getConditionalsThenElse(s.conditionalStep).forEach(f=>{Array.isArray(f)?p.generateJsonTranslation(f,i,o):p.generateJsonTranslation([f],i,o);});}),i}};N(p,"_beforeToTranslate"),N(p,"_translate",e=>e),N(p,"_afterToTranslate");var E=p;function se(a){try{if(typeof a>"u")return a;let e=JSON.stringify(a);return JSON.parse(e)}catch(e){throw J.error("Error creating exportable element",a,e),new Error("[Pixi\u2019VN] Error creating exportable element")}}var O=class extends LabelAbstract{constructor(i,o,n,s={}){n||(n={}),n.onLoadingLabel=async()=>{for(let c of o){let f;if(typeof c=="function"?f=c():f=c,f=l.getConditionalStep(f),f.operations){let g=f.operations.map(m=>l.loadAssets(m));await Promise.all(g);}}};super(i,n);N(this,"_steps");N(this,"operationStringConvert");N(this,"skipEmptyDialogs",false);this._steps=o,this.operationStringConvert=s.operationStringConvert,this.skipEmptyDialogs=s.skipEmptyDialogs||false;}get steps(){return this._steps.map(i=>this.stepConverter(i))}get stepCount(){return this._steps.length}getStepById(i){if(i<0||i>=this._steps.length)return;let o=this._steps[i];return this.stepConverter(o)}getStepSha(i){if(i<0||i>=this.steps.length)return;let o=this._steps[i];return (0, q.default)(o.toString().toLocaleLowerCase()).toString()}getDialogueText(i){let o="";if(Array.isArray(i)){let n=[];i.forEach(s=>{if(typeof s=="string")n.push(s);else if(s&&typeof s=="object"){let c=l.getLogichValue(s);c?(c&&!Array.isArray(c)&&typeof c=="object"&&(c=l.getLogichValue(c)||""),Array.isArray(c)?n=n.concat(c):n.push(`${c}`)):n.push(`${s}`);}}),o=n;}else {let n=l.getLogichValue(i)||"";n&&!Array.isArray(n)&&typeof n=="object"&&(n=l.getLogichValue(n)||""),o=n;}return `${o}`}getDialogue(i){if(i==null)return;let o=l.getLogichValue(i);return o==null?"":typeof o=="object"&&"character"in o&&"text"in o?{character:o.character,text:E.t(this.getDialogueText(o.text))}:E.t(this.getDialogueText(o))}getChoices(i){return l.getLogichValue(i)?.map(s=>l.getLogichValue(s)).filter(s=>s!==void 0)}stepConverter(i){return async o=>{let n=typeof i=="function"?i():i;n=se(n),n=l.getConditionalStep(n);let s=this.operationStringConvert?V=>this.operationStringConvert(V,n,o):void 0,{operations:c=[]}=n;for(let V of c)await A(V,s);let{labelToOpen:f=[]}=n,g=this.getChoices(n.choices),m=l.getLogichValue(n.glueEnabled),u=this.getDialogue(n.dialogue),h=[];Array.isArray(f)||(f=[f]),f.forEach(V=>{let y=l.getLogichValue(V);y&&h.push(y);});let P=l.getLogichValue(n.goNextStep),S=l.getLogichValue(n.end);if(g){let V=g.map(y=>{let v="";if(Array.isArray(y.text)){let r=[];y.text.forEach(x=>{if(typeof x=="string")r.push(E.t(x));else if(x&&typeof x=="object"){let d=l.getLogichValue(x);d&&!Array.isArray(d)&&typeof d=="object"&&(d=l.getLogichValue(d)||""),d&&(Array.isArray(d)?r=r.concat(E.t(d)):r.push(E.t(d)));}}),v=r;}else typeof y.text=="string"&&(v=E.t(y.text));return {label:y.label,text:v,props:y.props,type:y.type,oneTime:y.oneTime,onlyHaveNoChoice:y.onlyHaveNoChoice,autoSelect:y.autoSelect}});narration.choiceMenuOptions=V;}else narration.choiceMenuOptions=void 0;u!==void 0&&(narration.dialogue=u,this.skipEmptyDialogs&&typeof u=="string"&&(u===""||RegExp(/^\s+$/).test(u))&&(P=true)),m?storage.setFlag(SYSTEM_RESERVED_STORAGE_KEYS.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,true):m===false&&storage.setFlag(SYSTEM_RESERVED_STORAGE_KEYS.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,false);for(let V of h){let y=V.label;typeof y=="object"&&(y=l.getLogichValue(y)||"");let v=V.params?.map(t=>l.getLogichValue(t));o={...o,...V.props},V.type==="jump"?(narration.openedLabels.length>0&&narration.closeCurrentLabel(),storage.setTempVariable(`${H}${narration.openedLabels.length}`,v),await narration.callLabel(y,o)):(storage.setTempVariable(`${H}${narration.openedLabels.length}`,v),await narration.callLabel(y,o));}S==="game_end"?(narration.closeAllLabels(),await narration.goNext(o,{runNow:true})):S==="label_end"&&narration.closeCurrentLabel(),P&&await narration.goNext(o,{runNow:true});}}};export{O as LabelJson,re as importPixiVNJson};
1
+ import {RegisteredLabels,LabelAbstract,narration}from'@drincs/pixi-vn/narration';import {storage,SYSTEM_RESERVED_STORAGE_KEYS}from'@drincs/pixi-vn/storage';import {JsonUnifier}from'@drincs/pixi-vn-json/unifier';var Z=Object.create;var $=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var ie=Object.getPrototypeOf,ne=Object.prototype.hasOwnProperty;var re=(a,t,e)=>t in a?$(a,t,{enumerable:true,configurable:true,writable:true,value:e}):a[t]=e;var K=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var F=(a,t)=>()=>(t||a((t={exports:{}}).exports,t),t.exports);var oe=(a,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of te(t))!ne.call(a,n)&&n!==e&&$(a,n,{get:()=>t[n],enumerable:!(r=ee(t,n))||r.enumerable});return a};var se=(a,t,e)=>(e=a!=null?Z(ie(a)):{},oe($(e,"default",{value:a,enumerable:true}),a));var C=(a,t,e)=>re(a,typeof t!="symbol"?t+"":t,e);var X=F((B,G)=>{(function(a,t){typeof B=="object"?G.exports=B=t():typeof define=="function"&&define.amd?define([],t):a.CryptoJS=t();})(B,function(){var a=a||(function(t,e){var r;if(typeof window<"u"&&window.crypto&&(r=window.crypto),typeof self<"u"&&self.crypto&&(r=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(r=globalThis.crypto),!r&&typeof window<"u"&&window.msCrypto&&(r=window.msCrypto),!r&&typeof global<"u"&&global.crypto&&(r=global.crypto),!r&&typeof K=="function")try{r=K("crypto");}catch{}var n=function(){if(r){if(typeof r.getRandomValues=="function")try{return r.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof r.randomBytes=="function")try{return r.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},s=Object.create||(function(){function i(){}return function(o){var y;return i.prototype=o,y=new i,i.prototype=null,y}})(),l={},c=l.lib={},u=c.Base=(function(){return {extend:function(i){var o=s(this);return i&&o.mixIn(i),(!o.hasOwnProperty("init")||this.init===o.init)&&(o.init=function(){o.$super.init.apply(this,arguments);}),o.init.prototype=o,o.$super=this,o},create:function(){var i=this.extend();return i.init.apply(i,arguments),i},init:function(){},mixIn:function(i){for(var o in i)i.hasOwnProperty(o)&&(this[o]=i[o]);i.hasOwnProperty("toString")&&(this.toString=i.toString);},clone:function(){return this.init.prototype.extend(this)}}})(),d=c.WordArray=u.extend({init:function(i,o){i=this.words=i||[],o!=e?this.sigBytes=o:this.sigBytes=i.length*4;},toString:function(i){return (i||h).stringify(this)},concat:function(i){var o=this.words,y=i.words,g=this.sigBytes,P=i.sigBytes;if(this.clamp(),g%4)for(var N=0;N<P;N++){var R=y[N>>>2]>>>24-N%4*8&255;o[g+N>>>2]|=R<<24-(g+N)%4*8;}else for(var E=0;E<P;E+=4)o[g+E>>>2]=y[E>>>2];return this.sigBytes+=P,this},clamp:function(){var i=this.words,o=this.sigBytes;i[o>>>2]&=4294967295<<32-o%4*8,i.length=t.ceil(o/4);},clone:function(){var i=u.clone.call(this);return i.words=this.words.slice(0),i},random:function(i){for(var o=[],y=0;y<i;y+=4)o.push(n());return new d.init(o,i)}}),p=l.enc={},h=p.Hex={stringify:function(i){for(var o=i.words,y=i.sigBytes,g=[],P=0;P<y;P++){var N=o[P>>>2]>>>24-P%4*8&255;g.push((N>>>4).toString(16)),g.push((N&15).toString(16));}return g.join("")},parse:function(i){for(var o=i.length,y=[],g=0;g<o;g+=2)y[g>>>3]|=parseInt(i.substr(g,2),16)<<24-g%8*4;return new d.init(y,o/2)}},m=p.Latin1={stringify:function(i){for(var o=i.words,y=i.sigBytes,g=[],P=0;P<y;P++){var N=o[P>>>2]>>>24-P%4*8&255;g.push(String.fromCharCode(N));}return g.join("")},parse:function(i){for(var o=i.length,y=[],g=0;g<o;g++)y[g>>>2]|=(i.charCodeAt(g)&255)<<24-g%4*8;return new d.init(y,o)}},v=p.Utf8={stringify:function(i){try{return decodeURIComponent(escape(m.stringify(i)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(i){return m.parse(unescape(encodeURIComponent(i)))}},x=c.BufferedBlockAlgorithm=u.extend({reset:function(){this._data=new d.init,this._nDataBytes=0;},_append:function(i){typeof i=="string"&&(i=v.parse(i)),this._data.concat(i),this._nDataBytes+=i.sigBytes;},_process:function(i){var o,y=this._data,g=y.words,P=y.sigBytes,N=this.blockSize,R=N*4,E=P/R;i?E=t.ceil(E):E=t.max((E|0)-this._minBufferSize,0);var D=E*N,U=t.min(D*4,P);if(D){for(var H=0;H<D;H+=N)this._doProcessBlock(g,H);o=g.splice(0,D),y.sigBytes-=U;}return new d.init(o,U)},clone:function(){var i=u.clone.call(this);return i._data=this._data.clone(),i},_minBufferSize:0});c.Hasher=x.extend({cfg:u.extend(),init:function(i){this.cfg=this.cfg.extend(i),this.reset();},reset:function(){x.reset.call(this),this._doReset();},update:function(i){return this._append(i),this._process(),this},finalize:function(i){i&&this._append(i);var o=this._doFinalize();return o},blockSize:512/32,_createHelper:function(i){return function(o,y){return new i.init(y).finalize(o)}},_createHmacHelper:function(i){return function(o,y){return new T.HMAC.init(i,y).finalize(o)}}});var T=l.algo={};return l})(Math);return a});});var Y=F((k,q)=>{(function(a,t){typeof k=="object"?q.exports=k=t(X()):typeof define=="function"&&define.amd?define(["./core"],t):t(a.CryptoJS);})(k,function(a){return (function(){var t=a,e=t.lib,r=e.WordArray,n=e.Hasher,s=t.algo,l=[],c=s.SHA1=n.extend({_doReset:function(){this._hash=new r.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(u,d){for(var p=this._hash.words,h=p[0],m=p[1],v=p[2],x=p[3],b=p[4],T=0;T<80;T++){if(T<16)l[T]=u[d+T]|0;else {var i=l[T-3]^l[T-8]^l[T-14]^l[T-16];l[T]=i<<1|i>>>31;}var o=(h<<5|h>>>27)+b+l[T];T<20?o+=(m&v|~m&x)+1518500249:T<40?o+=(m^v^x)+1859775393:T<60?o+=(m&v|m&x|v&x)-1894007588:o+=(m^v^x)-899497514,b=x,x=v,v=m<<30|m>>>2,m=h,h=o;}p[0]=p[0]+h|0,p[1]=p[1]+m|0,p[2]=p[2]+v|0,p[3]=p[3]+x|0,p[4]=p[4]+b|0;},_doFinalize:function(){var u=this._data,d=u.words,p=this._nDataBytes*8,h=u.sigBytes*8;return d[h>>>5]|=128<<24-h%32,d[(h+64>>>9<<4)+14]=Math.floor(p/4294967296),d[(h+64>>>9<<4)+15]=p,u.sigBytes=d.length*4,this._process(),this._hash},clone:function(){var u=n.clone.call(this);return u._hash=this._hash.clone(),u}});t.SHA1=n._createHelper(c),t.HmacSHA1=n._createHmacHelper(c);})(),a.SHA1});});var L;(n=>(n.log=(s,...l)=>console.log(`[Pixi\u2019VN Json] ${s}`,...l),n.warn=(s,...l)=>console.warn(`[Pixi\u2019VN Json] ${s}`,...l),n.error=(s,...l)=>console.error(`[Pixi\u2019VN Json] ${s}`,...l),n.info=(s,...l)=>console.info(`[Pixi\u2019VN Json] ${s}`,...l)))(L||(L={}));async function O(a,t){let e=JsonUnifier.getLogichValue(a);if(e)switch(e.type){case "sound":JsonUnifier.soundOperation(e);break;case "assets":case "bundle":await JsonUnifier.loadAssets(e);break;case "image":await JsonUnifier.imageOperation(e);break;case "video":await JsonUnifier.videoOperation(e);break;case "imagecontainer":await JsonUnifier.imageContainerOperation(e);break;case "canvaselement":await JsonUnifier.canvasElementOperation(e);break;case "value":JsonUnifier.setStorageValue(e);break;case "operationtoconvert":if(t){let r="";e.values.forEach(s=>{if(typeof s=="string")r+=s;else {let l=JsonUnifier.getLogichValue(s);r+=`${l}`;}});let n=await t(r);n&&await O(n,t);}break;case "input":JsonUnifier.inputOperation(e);break;case "fade":case "move":case "rotate":case "zoom":JsonUnifier.tickerOperation(e);break;case "shake":await JsonUnifier.effectOperation(e);break;case "animate":case "animate-sequence":JsonUnifier.animateOperation(e);break}}async function le(a,t={}){let{operationStringConvert:e,skipEmptyDialogs:r}=t;if(!Array.isArray(a))if(typeof a=="object"||typeof a=="string")a=[a];else {L.error("Error parsing imported Pixi'VN JSON: data is not an object");return}let n=a.map(async c=>{if(typeof c=="string")try{c=JSON.parse(c);}catch(u){L.error("Error parsing imported Pixi'VN JSON",u),c={};}return c}),l=(await Promise.all(n)).map(async c=>{let u=[];if(c.initialOperations){c.initialOperations.forEach(p=>{let h=O(p,e?m=>e(m,{},{}):void 0);u.push(h);});let d={};[...storage.storage.keys()].forEach((p,h)=>{d[p]=storage.storage.get(p);}),storage.startingStorage=d;}if(c.labels){let d=c.labels;for(let p in d)try{let h=d[p],m=new A(p,h,void 0,t);RegisteredLabels.add(m);}catch(h){L.error(`Error creating JSON label ${p}`,h);}}return Promise.all(u)});await Promise.all(l);}var f=class f{static t(t){return Array.isArray(t)?t.map(e=>f.translate(`${e}`)):f.translate(`${t}`)}static set beforeToTranslate(t){f._beforeToTranslate=t;}static set translate(t){f._translate=t;}static get translate(){return t=>{let e=t;return f._beforeToTranslate&&(e=f._beforeToTranslate(e)),e=f._translate(e),f._afterToTranslate&&(e=f._afterToTranslate(e)),e}}static set afterToTranslate(t){f._afterToTranslate=t;}static addKey(t,e,r){let n=r.defaultValue||"empty_string";typeof e=="string"&&(e=[e]),Array.isArray(e)&&e.forEach(s=>{t[s]===void 0&&(n==="empty_string"?t[s]="":n==="copy_key"&&(f._beforeToTranslate?t[s]=f._beforeToTranslate(s):t[s]=s));});}static getConditionalsThenElse(t,e=[]){if(typeof t=="object"&&t&&"type"in t)if(t.type==="ifelse")t.then&&f.getConditionalsThenElse(t.then,e),t.else&&f.getConditionalsThenElse(t.else,e);else if(t.type==="stepswitch"){if(t.elements)if(Array.isArray(t.elements))t.elements.forEach(r=>{f.getConditionalsThenElse(r,e);});else if(t.elements.type==="ifelse"){let r=[];f.getConditionalsThenElse(t.elements,r),r.forEach(n=>{e.push(...n);});}else if(t.elements.type==="stepswitch"){let r=[];f.getConditionalsThenElse(t.elements,r),r.forEach(n=>{e.push(...n);});}else f.getConditionalsThenElse(t.elements,e);}else t.type==="resulttocombine"?(t.firstItem&&f.getConditionalsThenElse(t.firstItem,e),t.secondConditionalItem&&t.secondConditionalItem.forEach(r=>{f.getConditionalsThenElse(r,e);})):e.push(t);else t&&e.push(t);return e}static generateJsonTranslation(t,e={},r={}){let{defaultValue:n="copy_key"}=r;return t.forEach(s=>{if(s.choices){let l=[];Array.isArray(s.choices)?l=[s.choices]:l=f.getConditionalsThenElse(s.choices),l.forEach(c=>c.forEach(u=>{if("type"in u){let d=[];u.type==="ifelse"||u.type==="stepswitch"?f.getConditionalsThenElse(u,d):d=[u],d.map(h=>f.getConditionalsThenElse(h.text)).forEach(h=>{Array.isArray(h)&&h.forEach(m=>{Array.isArray(m)?m.forEach(v=>{typeof v=="string"?f.addKey(e,v,{defaultValue:n}):f.getConditionalsThenElse(v).forEach(x=>{Array.isArray(x)?x.forEach(b=>{typeof b=="string"&&f.addKey(e,b,{defaultValue:n});}):typeof x=="string"&&f.addKey(e,x,{defaultValue:n});});}):typeof m=="string"&&f.addKey(e,m,{defaultValue:n});});});}}));}if(s.dialogue){let l=[];Array.isArray(s.dialogue)?l=[s.dialogue]:l=f.getConditionalsThenElse(s.dialogue),l.forEach(c=>{if(typeof c=="string")f.addKey(e,c,{defaultValue:n});else if("text"in c){let u=f.getConditionalsThenElse(c.text);typeof u=="string"&&(u=[u]),u.forEach(d=>{typeof d=="string"?f.addKey(e,d,{defaultValue:n}):f.getConditionalsThenElse(d).forEach(h=>{typeof h=="string"?f.addKey(e,h,{defaultValue:n}):Array.isArray(h)&&h.forEach(m=>{typeof m=="string"?f.addKey(e,m,{defaultValue:n}):f.getConditionalsThenElse(m).forEach(v=>{typeof v=="string"&&f.addKey(e,v,{defaultValue:n});});});});});}});}s.conditionalStep&&f.getConditionalsThenElse(s.conditionalStep).forEach(c=>{Array.isArray(c)?f.generateJsonTranslation(c,e,r):f.generateJsonTranslation([c],e,r);});}),e}};C(f,"_beforeToTranslate"),C(f,"_translate",t=>t),C(f,"_afterToTranslate");var _=f;var w=_;var Q=se(Y());var W="___param___";function j(a){try{if(typeof a>"u")return a;let t=JSON.stringify(a);return JSON.parse(t)}catch(t){throw L.error("Error creating exportable element",a,t),new Error("[Pixi\u2019VN] Error creating exportable element")}}var A=class extends LabelAbstract{constructor(e,r,n,s={}){n||(n={}),n.onLoadingLabel=async()=>{for(let l of r){let c;if(typeof l=="function"?c=l():c=l,c=JsonUnifier.getConditionalStep(c),c.operations){let u=c.operations.map(d=>JsonUnifier.loadAssets(d));await Promise.all(u);}}};super(e,n);C(this,"_steps");C(this,"operationStringConvert");C(this,"skipEmptyDialogs",false);this._steps=r,this.operationStringConvert=s.operationStringConvert,this.skipEmptyDialogs=s.skipEmptyDialogs||false;}get steps(){return this._steps.map(e=>this.stepConverter(e))}get stepCount(){return this._steps.length}getStepById(e){if(e<0||e>=this._steps.length)return;let r=this._steps[e];return this.stepConverter(r)}getStepSha(e){if(e<0||e>=this.steps.length)return;let r=this._steps[e];return (0, Q.default)(r.toString().toLocaleLowerCase()).toString()}getDialogueText(e){let r="";if(Array.isArray(e)){let n=[];e.forEach(s=>{if(typeof s=="string")n.push(s);else if(s&&typeof s=="object"){let l=JsonUnifier.getLogichValue(s);l?(l&&!Array.isArray(l)&&typeof l=="object"&&(l=JsonUnifier.getLogichValue(l)||""),Array.isArray(l)?n=n.concat(l):n.push(`${l}`)):n.push(`${s}`);}}),r=n;}else {let n=JsonUnifier.getLogichValue(e)||"";n&&!Array.isArray(n)&&typeof n=="object"&&(n=JsonUnifier.getLogichValue(n)||""),r=n;}return `${r}`}getDialogue(e){if(e==null)return;let r=JsonUnifier.getLogichValue(e);return r==null?"":typeof r=="object"&&"character"in r&&"text"in r?{character:r.character,text:w.t(this.getDialogueText(r.text))}:w.t(this.getDialogueText(r))}getChoices(e){return JsonUnifier.getLogichValue(e)?.map(s=>JsonUnifier.getLogichValue(s)).filter(s=>s!==void 0)}stepConverter(e){return async r=>{let n=typeof e=="function"?e():e;n=j(n),n=JsonUnifier.getConditionalStep(n);let s=this.operationStringConvert?x=>this.operationStringConvert(x,n,r):void 0,{operations:l=[]}=n;for(let x of l)await O(x,s);let{labelToOpen:c=[]}=n,u=this.getChoices(n.choices),d=JsonUnifier.getLogichValue(n.glueEnabled),p=this.getDialogue(n.dialogue),h=[];Array.isArray(c)||(c=[c]),c.forEach(x=>{let b=JsonUnifier.getLogichValue(x);b&&h.push(b);});let m=JsonUnifier.getLogichValue(n.goNextStep),v=JsonUnifier.getLogichValue(n.end);if(u){let x=u.map(b=>{let T="";if(Array.isArray(b.text)){let o=[];b.text.forEach(y=>{if(typeof y=="string")o.push(w.t(y));else if(y&&typeof y=="object"){let g=JsonUnifier.getLogichValue(y);g&&!Array.isArray(g)&&typeof g=="object"&&(g=JsonUnifier.getLogichValue(g)||""),g&&(Array.isArray(g)?o=o.concat(w.t(g)):o.push(w.t(g)));}}),T=o;}else typeof b.text=="string"&&(T=w.t(b.text));return {label:b.label,text:T,props:b.props,type:b.type,oneTime:b.oneTime,onlyHaveNoChoice:b.onlyHaveNoChoice,autoSelect:b.autoSelect}});narration.choiceMenuOptions=x;}else narration.choiceMenuOptions=void 0;p!==void 0&&(narration.dialogue=p,this.skipEmptyDialogs&&typeof p=="string"&&(p===""||RegExp(/^\s+$/).test(p))&&(m=true)),d?storage.setFlag(SYSTEM_RESERVED_STORAGE_KEYS.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,true):d===false&&storage.setFlag(SYSTEM_RESERVED_STORAGE_KEYS.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,false);for(let x of h){let b=x.label;typeof b=="object"&&(b=JsonUnifier.getLogichValue(b)||"");let T=x.params?.map(i=>JsonUnifier.getLogichValue(i));r={...r,...x.props},x.type==="jump"?(narration.openedLabels.length>0&&narration.closeCurrentLabel(),storage.setTempVariable(`${W}${narration.openedLabels.length}`,T),await narration.callLabel(b,r)):(storage.setTempVariable(`${W}${narration.openedLabels.length}`,T),await narration.callLabel(b,r));}v==="game_end"?(narration.closeAllLabels(),await narration.goNext(r,{runNow:true})):v==="label_end"&&narration.closeCurrentLabel(),m&&await narration.goNext(r,{runNow:true});}}};export{A as LabelJson,le as importPixiVNJson};