import { StorageElementType } from '@drincs/pixi-vn'; /** * A single element that can appear inside a step-switch, which may be a direct value, * a conditional statement, or a result-to-combine. */ type PixiVNJsonStepSwitchElementType = Then | PixiVNJsonConditionalStatements | PixiVNJsonConditionalResultToCombine; /** * The elements collection of a step-switch — either a plain array or a conditional that produces an array. */ type PixiVNJsonStepSwitchElementsType = PixiVNJsonStepSwitchElementType[] | PixiVNJsonConditionalStatements; /** * Picks one element at random each time the step is visited. */ interface PixiVNJsonRandom { type: "stepswitch"; choiceType: "random"; /** * The pool of elements to choose from randomly. */ elements: PixiVNJsonStepSwitchElementsType; } /** * Picks elements in a random order, advancing through the list across visits (no repeats until exhausted). */ interface PixiVNJsonSequentialRandom { type: "stepswitch"; choiceType: "sequentialrandom"; /** * The pool of elements to iterate through in randomised order. */ elements: PixiVNJsonStepSwitchElementsType; /** * When the sequential ends, what should be the value? If undefined, it will return undefined. * If "lastItem", it will return the last item in the array. */ end: undefined | "lastItem"; /** * The subId is used for managing nested switches */ nestedId?: string; } /** * Advances through the elements list one by one on each visit (in order). */ interface PixiVNJsonSequential { type: "stepswitch"; choiceType: "sequential"; /** * The ordered list of elements to iterate through. */ elements: PixiVNJsonStepSwitchElementsType; /** * When the sequential ends, what should be the value? If undefined, it will return undefined. * If "lastItem", it will return the last item in the array. */ end: undefined | "lastItem"; /** * The subId is used for managing nested switches */ nestedId?: string; } /** * Loops through the elements list indefinitely, cycling back to the first element after the last. */ interface PixiVNJsonLoop { type: "stepswitch"; choiceType: "loop"; /** * The list of elements to cycle through. */ elements: PixiVNJsonStepSwitchElementsType; /** * The subId is used for managing nested switches */ nestedId?: string; } /** * A step-switch selects one element from a list using a defined strategy (random, sequential, loop, or sequential-random). */ type PixiVNJsonStepSwitch = PixiVNJsonRandom | PixiVNJsonSequential | PixiVNJsonLoop | PixiVNJsonSequentialRandom; /** * This element is used in case a {@link PixiVNJsonConditionalStatements} gives a result that must be combined with another calculated through other {@link PixiVNJsonConditionalStatements}. * in case this possibility is not managed, it will be taken into consideration {@link PixiVNJsonConditionalResultToCombine.firstItem} */ type PixiVNJsonConditionalResultToCombine = { type: "resulttocombine"; /** * Defines how the two results are combined: * - `"cross"` — cartesian product / pairwise combination of both results * - `"union"` — concatenation / merge of both results into a single collection */ combine: "cross" | "union"; /** * The first (primary) result item, used as a fallback if the second conditional produces no result. */ firstItem?: T; /** * The second conditional item(s) whose result will be combined with {@link firstItem}. */ secondConditionalItem?: PixiVNJsonStepSwitchElementType[]; }; /** * A conditional statement that evaluates to a value of type `Then`. * It can be either: * - a {@link PixiVNJsonStepSwitch} — selects a result from a list based on a strategy (random, sequential, loop) * - a {@link PixiVNJsonIfElse} — evaluates a condition and returns the matching branch result, * which may itself be another conditional or a {@link PixiVNJsonConditionalResultToCombine} */ type PixiVNJsonConditionalStatements = PixiVNJsonStepSwitch | PixiVNJsonIfElse | PixiVNJsonConditionalResultToCombine>; /** * Retrieves a value from the persistent storage, flag storage, or temporary storage. */ type PixiVNJsonStorageGet = { type: "value"; storageOperationType: "get"; /** * Key of the storage */ key: string; /** * Type of the storage, if it is a flagStorage or a storage. * If it is a flagStorage, the value will be get with the function {@link storage.flags.get} */ storageType: "storage" | "flagStorage" | "tempstorage"; }; type PixiVNJsonParamGet = { type: "value"; storageOperationType: "get"; /** * Index of the parameter in the params array. */ key: number; storageType: "params"; }; /** * Retrieves the number of times a label has been opened. */ type PixiVNJsonLabelGet = { type: "value"; storageOperationType: "get"; /** * Id of the label */ label: string; /** * If it is a label, the value will be get with the function {@link narration.queries.timesLabelOpened} */ storageType: "label"; }; /** * Retrieves the number of times a specific choice has been selected. */ type PixiVNJsonChoiceGet = { type: "value"; storageOperationType: "get"; /** * index of the choice */ index: number; /** * If it is a choice, the value will be get with the function {@link narration.queries.timesChoiceMade} */ storageType: "choice"; }; /** * Retrieves a value from the logic/arithmetic layer (result of a computation or condition). */ type PixiVNJsonLogicGet = { type: "value"; storageOperationType: "get"; /** * The arithmetic or conditional operation whose result is the retrieved value. */ operation: PixiVNJsonArithmeticOperations | PixiVNJsonConditions; storageType: "logic"; }; /** * Union of all "get value" operations — reads from storage, params, labels, choices, or a logic expression. */ type PixiVNJsonValueGet = PixiVNJsonStorageGet | PixiVNJsonParamGet | PixiVNJsonLabelGet | PixiVNJsonChoiceGet | PixiVNJsonLogicGet | PixiVNJsonFunction; /** * Invokes a named function and returns its result. * Functions are registered in the Pixi'VN runtime and can receive typed arguments. */ type PixiVNJsonFunction = { type: "function"; /** * The name of the registered function to call. */ functionName: string; /** * Arguments to pass to the function. Each argument can be a condition, a raw value, * a value-get operation, or an arithmetic expression. */ args: (PixiVNJsonConditions | StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations)[]; }; /** * Sets a value in either the persistent storage or the temporary (session) storage. */ type PixiVNJsonOnlyStorageSet = { type: "value"; storageOperationType: "set"; /** * Key of the storage */ key: string; /** * Value to be set in the storage */ value: StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations | PixiVNJsonConditionalStatements; /** * Type of the storage, if it is a flagStorage or a storage. */ storageType: "storage" | "tempstorage"; }; /** * Sets a positional parameter value in the params temporary storage. */ type PixiVNJsonOnlyParamSet = { type: "value"; storageOperationType: "set"; /** * Index of the parameter in the params array to set. */ key: number; /** * Value to be set at the given param index. */ value: StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations | PixiVNJsonConditionalStatements; storageType: "params"; }; /** * Sets a boolean flag in the flag storage. * Flag storage is a dedicated boolean key-value store queried with {@link storage.flags.get}. */ type PixiVNJsonFlagSet = { type: "value"; storageOperationType: "set"; /** * Key of the storage */ key: string; /** * Value to be set in the storage */ value: boolean; /** * Type of the storage, if it is a flagStorage or a storage. */ storageType: "flagStorage"; }; /** * Union of all "set value" operations — writes to storage, flag storage, or params. */ type PixiVNJsonValueSet = PixiVNJsonOnlyStorageSet | PixiVNJsonFlagSet | PixiVNJsonOnlyParamSet; /** * Binary arithmetic operation between two values (left OP right). */ interface PixiVNJsonArithmeticOperationsArithmetic { type: "arithmetic"; /** * Left value of the arithmetic operation */ leftValue: StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations | PixiVNJsonConditionalStatements; /** * Right value of the arithmetic operation */ rightValue: StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations | PixiVNJsonConditionalStatements; /** * Operator of the arithmetic operation: * - `"*"` multiplication * - `"/"` division * - `"+"` addition (concatenation for strings and arrays) * - `"-"` subtraction (removal of elements for arrays) * - `"%"` modulo * - `"POW"` exponentiation * - `"RANDOM"` random integer between leftValue and rightValue (inclusive) * - `"INTERSECTION"` intersection of two arrays (only elements present in both arrays are included in the result) */ operator: "*" | "/" | "+" | "-" | "%" | "POW" | "RANDOM" | "INTERSECTION"; } /** * Unary arithmetic operation applied to a single value (e.g. INT, FLOOR, FLOAT). */ interface PixiVNJsonArithmeticOperationsArithmeticSingle { type: "arithmeticsingle"; /** * Left value of the arithmetic operation */ leftValue: StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations | PixiVNJsonConditionalStatements; /** * Operator of the arithmetic operation: * - `"INT"` truncates the value to an integer (removes the decimal part) * - `"FLOOR"` rounds down to the nearest integer * - `"FLOAT"` converts the value to a floating-point number */ operator: "INT" | "FLOOR" | "FLOAT"; } /** * Arithmetic operations for the PixiVNJson */ type PixiVNJsonArithmeticOperations = PixiVNJsonArithmeticOperationsArithmeticSingle | PixiVNJsonArithmeticOperationsArithmetic; /** * Combines multiple conditions with a logical AND or OR. */ type PixiVNJsonUnionConditionAndOr = { type: "union"; /** * The list of conditions to combine. */ conditions: PixiVNJsonConditions[]; /** * - `"and"` — all conditions must be true * - `"or"` — at least one condition must be true */ unionType: "and" | "or"; }; /** * Negates a single condition with a logical NOT. */ type PixiVNJsonUnionConditionNot = { type: "union"; /** * The condition to negate. */ condition: PixiVNJsonConditions; unionType: "not"; }; /** * Union of AND/OR and NOT logical operators over conditions. */ type PixiVNJsonUnionCondition = PixiVNJsonUnionConditionAndOr | PixiVNJsonUnionConditionNot; /** * Supported comparison operators. * - `"=="` equal * - `"!="` not equal * - `"<"` less than * - `"<="` less than or equal * - `">"` greater than * - `">="` greater than or equal * - `"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 */ type PixiVNJsonComparationOperatorsType = "==" | "!=" | "<" | "<=" | ">" | ">=" | "CONTAINS"; /** * Comparation for PixiVNJson. * In this comparation, the values to be converted to string and compared. */ type PixiVNJsonComparation = { type: "compare"; /** * Left value of the comparation */ leftValue: StorageElementType | PixiVNJsonValueGet | PixiVNJsonConditions; /** * Right value of the comparation */ rightValue: StorageElementType | PixiVNJsonValueGet | PixiVNJsonConditions; /** * Operator of the comparation */ operator: PixiVNJsonComparationOperatorsType; }; /** * A plain value condition — truthy/falsy evaluation of a raw value or a value-get result. */ type PixiVNJsonValueCondition = StorageElementType | PixiVNJsonValueGet; /** * Union of all condition types supported by PixiVNJson: * - {@link PixiVNJsonComparation} — binary comparison between two values * - {@link PixiVNJsonValueCondition} — truthy/falsy check on a plain value * - {@link PixiVNJsonUnionCondition} — logical AND, OR, or NOT of other conditions * - {@link PixiVNJsonArithmeticOperations} — arithmetic result used as a boolean (non-zero = true) */ type PixiVNJsonConditions = PixiVNJsonComparation | PixiVNJsonValueCondition | PixiVNJsonUnionCondition | PixiVNJsonArithmeticOperations; /** * If-Else condition for PixiVNJson */ interface PixiVNJsonIfElse { type: "ifelse"; /** * The list of conditions to be checked. * * if is a {@link StorageElementType} or a {@link PixiVNJsonValueGet}: * - if is a array or object, the condition is true if not empty * - if is a string, the condition is true if not empty * - if is a number, the condition is true if not zero * - if is a boolean, the condition is true if true * - if is null or undefined, the condition is false */ condition: PixiVNJsonConditions; /** * The value to be returned if the condition is true. */ then: Then | PixiVNJsonIfElse; /** * The value to be returned if the condition is false. */ else?: Then | PixiVNJsonIfElse; } 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 };