@drincs/pixi-vn-json 1.13.14 → 1.13.16

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.
@@ -0,0 +1,409 @@
1
+ import { StorageElementType } from '@drincs/pixi-vn';
2
+
3
+ /**
4
+ * A single element that can appear inside a step-switch, which may be a direct value,
5
+ * a conditional statement, or a result-to-combine.
6
+ */
7
+ type PixiVNJsonStepSwitchElementType<Then> = Then | PixiVNJsonConditionalStatements<Then> | PixiVNJsonConditionalResultToCombine<Then>;
8
+ /**
9
+ * The elements collection of a step-switch — either a plain array or a conditional that produces an array.
10
+ */
11
+ type PixiVNJsonStepSwitchElementsType<Then> = PixiVNJsonStepSwitchElementType<Then>[] | PixiVNJsonConditionalStatements<Then[]>;
12
+ /**
13
+ * Picks one element at random each time the step is visited.
14
+ */
15
+ interface PixiVNJsonRandom<Then> {
16
+ type: "stepswitch";
17
+ choiceType: "random";
18
+ /**
19
+ * The pool of elements to choose from randomly.
20
+ */
21
+ elements: PixiVNJsonStepSwitchElementsType<Then>;
22
+ }
23
+ /**
24
+ * Picks elements in a random order, advancing through the list across visits (no repeats until exhausted).
25
+ */
26
+ interface PixiVNJsonSequentialRandom<Then> {
27
+ type: "stepswitch";
28
+ choiceType: "sequentialrandom";
29
+ /**
30
+ * The pool of elements to iterate through in randomised order.
31
+ */
32
+ elements: PixiVNJsonStepSwitchElementsType<Then>;
33
+ /**
34
+ * When the sequential ends, what should be the value? If undefined, it will return undefined.
35
+ * If "lastItem", it will return the last item in the array.
36
+ */
37
+ end: undefined | "lastItem";
38
+ /**
39
+ * The subId is used for managing nested switches
40
+ */
41
+ nestedId?: string;
42
+ }
43
+ /**
44
+ * Advances through the elements list one by one on each visit (in order).
45
+ */
46
+ interface PixiVNJsonSequential<Then> {
47
+ type: "stepswitch";
48
+ choiceType: "sequential";
49
+ /**
50
+ * The ordered list of elements to iterate through.
51
+ */
52
+ elements: PixiVNJsonStepSwitchElementsType<Then>;
53
+ /**
54
+ * When the sequential ends, what should be the value? If undefined, it will return undefined.
55
+ * If "lastItem", it will return the last item in the array.
56
+ */
57
+ end: undefined | "lastItem";
58
+ /**
59
+ * The subId is used for managing nested switches
60
+ */
61
+ nestedId?: string;
62
+ }
63
+ /**
64
+ * Loops through the elements list indefinitely, cycling back to the first element after the last.
65
+ */
66
+ interface PixiVNJsonLoop<Then> {
67
+ type: "stepswitch";
68
+ choiceType: "loop";
69
+ /**
70
+ * The list of elements to cycle through.
71
+ */
72
+ elements: PixiVNJsonStepSwitchElementsType<Then>;
73
+ /**
74
+ * The subId is used for managing nested switches
75
+ */
76
+ nestedId?: string;
77
+ }
78
+ /**
79
+ * A step-switch selects one element from a list using a defined strategy (random, sequential, loop, or sequential-random).
80
+ */
81
+ type PixiVNJsonStepSwitch<Then> = PixiVNJsonRandom<Then> | PixiVNJsonSequential<Then> | PixiVNJsonLoop<Then> | PixiVNJsonSequentialRandom<Then>;
82
+
83
+ /**
84
+ * This element is used in case a {@link PixiVNJsonConditionalStatements} gives a result that must be combined with another calculated through other {@link PixiVNJsonConditionalStatements}.
85
+ * in case this possibility is not managed, it will be taken into consideration {@link PixiVNJsonConditionalResultToCombine.firstItem}
86
+ */
87
+ type PixiVNJsonConditionalResultToCombine<T> = {
88
+ type: "resulttocombine";
89
+ /**
90
+ * Defines how the two results are combined:
91
+ * - `"cross"` — cartesian product / pairwise combination of both results
92
+ * - `"union"` — concatenation / merge of both results into a single collection
93
+ */
94
+ combine: "cross" | "union";
95
+ /**
96
+ * The first (primary) result item, used as a fallback if the second conditional produces no result.
97
+ */
98
+ firstItem?: T;
99
+ /**
100
+ * The second conditional item(s) whose result will be combined with {@link firstItem}.
101
+ */
102
+ secondConditionalItem?: PixiVNJsonStepSwitchElementType<T>[];
103
+ };
104
+
105
+ /**
106
+ * A conditional statement that evaluates to a value of type `Then`.
107
+ * It can be either:
108
+ * - a {@link PixiVNJsonStepSwitch} — selects a result from a list based on a strategy (random, sequential, loop)
109
+ * - a {@link PixiVNJsonIfElse} — evaluates a condition and returns the matching branch result,
110
+ * which may itself be another conditional or a {@link PixiVNJsonConditionalResultToCombine}
111
+ */
112
+ type PixiVNJsonConditionalStatements<Then> = PixiVNJsonStepSwitch<Then> | PixiVNJsonIfElse<Then | PixiVNJsonConditionalStatements<Then> | PixiVNJsonConditionalResultToCombine<Then>>;
113
+
114
+ /**
115
+ * Retrieves a value from the persistent storage, flag storage, or temporary storage.
116
+ */
117
+ type PixiVNJsonStorageGet = {
118
+ type: "value";
119
+ storageOperationType: "get";
120
+ /**
121
+ * Key of the storage
122
+ */
123
+ key: string;
124
+ /**
125
+ * Type of the storage, if it is a flagStorage or a storage.
126
+ * If it is a flagStorage, the value will be get with the function {@link getFlag}
127
+ */
128
+ storageType: "storage" | "flagStorage" | "tempstorage";
129
+ };
130
+ type PixiVNJsonParamGet = {
131
+ type: "value";
132
+ storageOperationType: "get";
133
+ /**
134
+ * Index of the parameter in the params array.
135
+ */
136
+ key: number;
137
+ storageType: "params";
138
+ };
139
+ /**
140
+ * Retrieves the number of times a label has been opened.
141
+ */
142
+ type PixiVNJsonLabelGet = {
143
+ type: "value";
144
+ storageOperationType: "get";
145
+ /**
146
+ * Id of the label
147
+ */
148
+ label: string;
149
+ /**
150
+ * If it is a label, the value will be get with the function {@link narration.getTimesLabelOpened}
151
+ */
152
+ storageType: "label";
153
+ };
154
+ /**
155
+ * Retrieves the number of times a specific choice has been selected.
156
+ */
157
+ type PixiVNJsonChoiceGet = {
158
+ type: "value";
159
+ storageOperationType: "get";
160
+ /**
161
+ * index of the choice
162
+ */
163
+ index: number;
164
+ /**
165
+ * If it is a choice, the value will be get with the function {@link narration.getTimesChoiceOpened}
166
+ */
167
+ storageType: "choice";
168
+ };
169
+ /**
170
+ * Retrieves a value from the logic/arithmetic layer (result of a computation or condition).
171
+ */
172
+ type PixiVNJsonLogicGet = {
173
+ type: "value";
174
+ storageOperationType: "get";
175
+ /**
176
+ * The arithmetic or conditional operation whose result is the retrieved value.
177
+ */
178
+ operation: PixiVNJsonArithmeticOperations | PixiVNJsonConditions;
179
+ storageType: "logic";
180
+ };
181
+ /**
182
+ * Union of all "get value" operations — reads from storage, params, labels, choices, or a logic expression.
183
+ */
184
+ type PixiVNJsonValueGet = PixiVNJsonStorageGet | PixiVNJsonParamGet | PixiVNJsonLabelGet | PixiVNJsonChoiceGet | PixiVNJsonLogicGet | PixiVNJsonFunction;
185
+ /**
186
+ * Invokes a named function and returns its result.
187
+ * Functions are registered in the Pixi'VN runtime and can receive typed arguments.
188
+ */
189
+ type PixiVNJsonFunction = {
190
+ type: "function";
191
+ /**
192
+ * The name of the registered function to call.
193
+ */
194
+ functionName: string;
195
+ /**
196
+ * Arguments to pass to the function. Each argument can be a condition, a raw value,
197
+ * a value-get operation, or an arithmetic expression.
198
+ */
199
+ args: (PixiVNJsonConditions | StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations)[];
200
+ };
201
+ /**
202
+ * Sets a value in either the persistent storage or the temporary (session) storage.
203
+ */
204
+ type PixiVNJsonOnlyStorageSet = {
205
+ type: "value";
206
+ storageOperationType: "set";
207
+ /**
208
+ * Key of the storage
209
+ */
210
+ key: string;
211
+ /**
212
+ * Value to be set in the storage
213
+ */
214
+ value: StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations | PixiVNJsonConditionalStatements<StorageElementType>;
215
+ /**
216
+ * Type of the storage, if it is a flagStorage or a storage.
217
+ */
218
+ storageType: "storage" | "tempstorage";
219
+ };
220
+ /**
221
+ * Sets a positional parameter value in the params temporary storage.
222
+ */
223
+ type PixiVNJsonOnlyParamSet = {
224
+ type: "value";
225
+ storageOperationType: "set";
226
+ /**
227
+ * Index of the parameter in the params array to set.
228
+ */
229
+ key: number;
230
+ /**
231
+ * Value to be set at the given param index.
232
+ */
233
+ value: StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations | PixiVNJsonConditionalStatements<StorageElementType>;
234
+ storageType: "params";
235
+ };
236
+ /**
237
+ * Sets a boolean flag in the flag storage.
238
+ * Flag storage is a dedicated boolean key-value store queried with {@link getFlag}.
239
+ */
240
+ type PixiVNJsonFlagSet = {
241
+ type: "value";
242
+ storageOperationType: "set";
243
+ /**
244
+ * Key of the storage
245
+ */
246
+ key: string;
247
+ /**
248
+ * Value to be set in the storage
249
+ */
250
+ value: boolean;
251
+ /**
252
+ * Type of the storage, if it is a flagStorage or a storage.
253
+ */
254
+ storageType: "flagStorage";
255
+ };
256
+ /**
257
+ * Union of all "set value" operations — writes to storage, flag storage, or params.
258
+ */
259
+ type PixiVNJsonValueSet = PixiVNJsonOnlyStorageSet | PixiVNJsonFlagSet | PixiVNJsonOnlyParamSet;
260
+
261
+ /**
262
+ * Binary arithmetic operation between two values (left OP right).
263
+ */
264
+ interface PixiVNJsonArithmeticOperationsArithmetic {
265
+ type: "arithmetic";
266
+ /**
267
+ * Left value of the arithmetic operation
268
+ */
269
+ leftValue: StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations | PixiVNJsonConditionalStatements<StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations>;
270
+ /**
271
+ * Right value of the arithmetic operation
272
+ */
273
+ rightValue: StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations | PixiVNJsonConditionalStatements<StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations>;
274
+ /**
275
+ * Operator of the arithmetic operation:
276
+ * - `"*"` multiplication
277
+ * - `"/"` division
278
+ * - `"+"` addition (concatenation for strings and arrays)
279
+ * - `"-"` subtraction (removal of elements for arrays)
280
+ * - `"%"` modulo
281
+ * - `"POW"` exponentiation
282
+ * - `"RANDOM"` random integer between leftValue and rightValue (inclusive)
283
+ * - `"INTERSECTION"` intersection of two arrays (only elements present in both arrays are included in the result)
284
+ */
285
+ operator: "*" | "/" | "+" | "-" | "%" | "POW" | "RANDOM" | "INTERSECTION";
286
+ }
287
+ /**
288
+ * Unary arithmetic operation applied to a single value (e.g. INT, FLOOR, FLOAT).
289
+ */
290
+ interface PixiVNJsonArithmeticOperationsArithmeticSingle {
291
+ type: "arithmeticsingle";
292
+ /**
293
+ * Left value of the arithmetic operation
294
+ */
295
+ leftValue: StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations | PixiVNJsonConditionalStatements<StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations>;
296
+ /**
297
+ * Operator of the arithmetic operation:
298
+ * - `"INT"` truncates the value to an integer (removes the decimal part)
299
+ * - `"FLOOR"` rounds down to the nearest integer
300
+ * - `"FLOAT"` converts the value to a floating-point number
301
+ */
302
+ operator: "INT" | "FLOOR" | "FLOAT";
303
+ }
304
+ /**
305
+ * Arithmetic operations for the PixiVNJson
306
+ */
307
+ type PixiVNJsonArithmeticOperations = PixiVNJsonArithmeticOperationsArithmeticSingle | PixiVNJsonArithmeticOperationsArithmetic;
308
+
309
+ /**
310
+ * Combines multiple conditions with a logical AND or OR.
311
+ */
312
+ type PixiVNJsonUnionConditionAndOr = {
313
+ type: "union";
314
+ /**
315
+ * The list of conditions to combine.
316
+ */
317
+ conditions: PixiVNJsonConditions[];
318
+ /**
319
+ * - `"and"` — all conditions must be true
320
+ * - `"or"` — at least one condition must be true
321
+ */
322
+ unionType: "and" | "or";
323
+ };
324
+ /**
325
+ * Negates a single condition with a logical NOT.
326
+ */
327
+ type PixiVNJsonUnionConditionNot = {
328
+ type: "union";
329
+ /**
330
+ * The condition to negate.
331
+ */
332
+ condition: PixiVNJsonConditions;
333
+ unionType: "not";
334
+ };
335
+ /**
336
+ * Union of AND/OR and NOT logical operators over conditions.
337
+ */
338
+ type PixiVNJsonUnionCondition = PixiVNJsonUnionConditionAndOr | PixiVNJsonUnionConditionNot;
339
+
340
+ /**
341
+ * Supported comparison operators.
342
+ * - `"=="` equal
343
+ * - `"!="` not equal
344
+ * - `"<"` less than
345
+ * - `"<="` less than or equal
346
+ * - `">"` greater than
347
+ * - `">="` greater than or equal
348
+ * - `"CONTAINS"` checks whether the left string/array contains the right value, if left and right are arrays, checks if all items in right are included in left
349
+ */
350
+ type PixiVNJsonComparationOperatorsType = "==" | "!=" | "<" | "<=" | ">" | ">=" | "CONTAINS";
351
+ /**
352
+ * Comparation for PixiVNJson.
353
+ * In this comparation, the values to be converted to string and compared.
354
+ */
355
+ type PixiVNJsonComparation = {
356
+ type: "compare";
357
+ /**
358
+ * Left value of the comparation
359
+ */
360
+ leftValue: StorageElementType | PixiVNJsonValueGet | PixiVNJsonConditions;
361
+ /**
362
+ * Right value of the comparation
363
+ */
364
+ rightValue: StorageElementType | PixiVNJsonValueGet | PixiVNJsonConditions;
365
+ /**
366
+ * Operator of the comparation
367
+ */
368
+ operator: PixiVNJsonComparationOperatorsType;
369
+ };
370
+ /**
371
+ * A plain value condition — truthy/falsy evaluation of a raw value or a value-get result.
372
+ */
373
+ type PixiVNJsonValueCondition = StorageElementType | PixiVNJsonValueGet;
374
+ /**
375
+ * Union of all condition types supported by PixiVNJson:
376
+ * - {@link PixiVNJsonComparation} — binary comparison between two values
377
+ * - {@link PixiVNJsonValueCondition} — truthy/falsy check on a plain value
378
+ * - {@link PixiVNJsonUnionCondition} — logical AND, OR, or NOT of other conditions
379
+ * - {@link PixiVNJsonArithmeticOperations} — arithmetic result used as a boolean (non-zero = true)
380
+ */
381
+ type PixiVNJsonConditions = PixiVNJsonComparation | PixiVNJsonValueCondition | PixiVNJsonUnionCondition | PixiVNJsonArithmeticOperations;
382
+
383
+ /**
384
+ * If-Else condition for PixiVNJson
385
+ */
386
+ interface PixiVNJsonIfElse<Then> {
387
+ type: "ifelse";
388
+ /**
389
+ * The list of conditions to be checked.
390
+ *
391
+ * if is a {@link StorageElementType} or a {@link PixiVNJsonValueGet}:
392
+ * - if is a array or object, the condition is true if not empty
393
+ * - if is a string, the condition is true if not empty
394
+ * - if is a number, the condition is true if not zero
395
+ * - if is a boolean, the condition is true if true
396
+ * - if is null or undefined, the condition is false
397
+ */
398
+ condition: PixiVNJsonConditions;
399
+ /**
400
+ * The value to be returned if the condition is true.
401
+ */
402
+ then: Then | PixiVNJsonIfElse<Then>;
403
+ /**
404
+ * The value to be returned if the condition is false.
405
+ */
406
+ else?: Then | PixiVNJsonIfElse<Then>;
407
+ }
408
+
409
+ export type { PixiVNJsonIfElse as P, PixiVNJsonValueSet as a, PixiVNJsonOnlyStorageSet as b, PixiVNJsonValueGet as c, PixiVNJsonArithmeticOperations as d, PixiVNJsonConditions as e, PixiVNJsonConditionalStatements as f, PixiVNJsonArithmeticOperationsArithmetic as g, PixiVNJsonArithmeticOperationsArithmeticSingle as h, PixiVNJsonChoiceGet as i, PixiVNJsonComparation as j, PixiVNJsonComparationOperatorsType as k, PixiVNJsonConditionalResultToCombine as l, PixiVNJsonFunction as m, PixiVNJsonLabelGet as n, PixiVNJsonLogicGet as o, PixiVNJsonParamGet as p, PixiVNJsonStepSwitch as q, PixiVNJsonStepSwitchElementType as r, PixiVNJsonStepSwitchElementsType as s, PixiVNJsonStorageGet as t, PixiVNJsonUnionCondition as u };