UNPKG

@drincs/pixi-vn-json

Version:

Pixi'VN can be integrated with JSON files to create a visual novel.

250 lines (240 loc) 8.75 kB
import { StorageElementType } from '@drincs/pixi-vn'; type PixiVNJsonStepSwitchElementType<Then> = Then | PixiVNJsonConditionalStatements<Then> | PixiVNJsonConditionalResultToCombine<Then>; type PixiVNJsonStepSwitchElementsType<Then> = (PixiVNJsonStepSwitchElementType<Then>)[] | PixiVNJsonConditionalStatements<Then[]>; interface PixiVNJsonRandom<Then> { type: "stepswitch"; choiceType: "random"; elements: PixiVNJsonStepSwitchElementsType<Then>; } interface PixiVNJsonSequentialRandom<Then> { type: "stepswitch"; choiceType: "sequentialrandom"; elements: PixiVNJsonStepSwitchElementsType<Then>; /** * 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 manager nested switches */ nestedId?: string; } interface PixiVNJsonSequential<Then> { type: "stepswitch"; choiceType: "sequential"; elements: PixiVNJsonStepSwitchElementsType<Then>; /** * 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 manager nested switches */ nestedId?: string; } interface PixiVNJsonLoop<Then> { type: "stepswitch"; choiceType: "loop"; elements: PixiVNJsonStepSwitchElementsType<Then>; nestedId?: string; } type PixiVNJsonStepSwitch<Then> = PixiVNJsonRandom<Then> | PixiVNJsonSequential<Then> | PixiVNJsonLoop<Then> | PixiVNJsonSequentialRandom<Then>; /** * 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<T> = { type: "resulttocombine"; /** * This variable is interpreted differently by Pixi'VN depending on the value */ combine: "cross" | "union"; firstItem?: T; secondConditionalItem?: PixiVNJsonStepSwitchElementType<T>[]; }; 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 getFlag} */ storageType: "storage" | "flagStorage" | "tempstorage"; }; type PixiVNJsonParamGet = { type: "value"; storageOperationType: "get"; /** * Key of the storage */ key: number; storageType: "params"; }; 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.getTimesLabelOpened} */ storageType: "label"; }; 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.getTimesChoiceOpened} */ storageType: "choice"; }; type PixiVNJsonLogicGet = { type: "value"; storageOperationType: "get"; operation: PixiVNJsonArithmeticOperations | PixiVNJsonConditions; storageType: "logic"; }; type PixiVNJsonValueGet = PixiVNJsonStorageGet | PixiVNJsonParamGet | PixiVNJsonLabelGet | PixiVNJsonChoiceGet | PixiVNJsonLogicGet; type PixiVNJsonOnlyStorageSet = { type: "value"; storageOperationType: "set"; /** * Key of the storage */ key: string; /** * Value to be set in the storage */ value: StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations | PixiVNJsonConditionalStatements<StorageElementType>; /** * Type of the storage, if it is a flagStorage or a storage. */ storageType: "storage" | "tempstorage"; }; type PixiVNJsonOnlyParamSet = { type: "value"; storageOperationType: "set"; /** * Key of the storage */ key: number; /** * Value to be set in the storage */ value: StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations | PixiVNJsonConditionalStatements<StorageElementType>; storageType: "params"; }; 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"; }; type PixiVNJsonValueSet = PixiVNJsonOnlyStorageSet | PixiVNJsonFlagSet | PixiVNJsonOnlyParamSet; interface PixiVNJsonArithmeticOperationsArithmetic { type: "arithmetic"; /** * Left value of the arithmetic operation */ leftValue: StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations | PixiVNJsonConditionalStatements<StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations>; /** * Right value of the arithmetic operation */ rightValue: StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations | PixiVNJsonConditionalStatements<StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations>; /** * Operator of the arithmetic operation */ operator: "*" | "/" | "+" | "-" | "%" | "POW" | "RANDOM"; } interface PixiVNJsonArithmeticOperationsArithmeticSingle { type: "arithmeticsingle"; /** * Left value of the arithmetic operation */ leftValue: StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations | PixiVNJsonConditionalStatements<StorageElementType | PixiVNJsonValueGet | PixiVNJsonArithmeticOperations>; /** * Operator of the arithmetic operation */ operator: "INT" | "FLOOR" | "FLOAT"; } /** * Arithmetic operations for the PixiVNJson */ type PixiVNJsonArithmeticOperations = PixiVNJsonArithmeticOperationsArithmeticSingle | PixiVNJsonArithmeticOperationsArithmetic; type PixiVNJsonUnionConditionAndOr = { type: "union"; conditions: PixiVNJsonConditions[]; unionType: "and" | "or"; }; type PixiVNJsonUnionConditionNot = { type: "union"; condition: PixiVNJsonConditions; unionType: "not"; }; type PixiVNJsonUnionCondition = PixiVNJsonUnionConditionAndOr | PixiVNJsonUnionConditionNot; /** * 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: "==" | "!=" | "<" | "<=" | ">" | ">=" | "CONTAINS"; }; type PixiVNJsonValueCondition = StorageElementType | PixiVNJsonValueGet; /** * Conditions for PixiVNJson */ type PixiVNJsonConditions = PixiVNJsonComparation | PixiVNJsonValueCondition | PixiVNJsonUnionCondition | PixiVNJsonArithmeticOperations; /** * If-Else condition for PixiVNJson */ interface PixiVNJsonIfElse<Then> { type: "ifelse"; /** * The list of conditions to be checked. */ condition: PixiVNJsonConditions; /** * The value to be returned if the condition is true. */ then: Then | PixiVNJsonIfElse<Then>; /** * The value to be returned if the condition is false. */ else?: Then | PixiVNJsonIfElse<Then>; } type PixiVNJsonConditionalStatements<Then> = PixiVNJsonStepSwitch<Then> | PixiVNJsonIfElse<Then | PixiVNJsonConditionalStatements<Then> | PixiVNJsonConditionalResultToCombine<Then>>; export type { PixiVNJsonArithmeticOperations as P, PixiVNJsonArithmeticOperationsArithmetic as a, PixiVNJsonArithmeticOperationsArithmeticSingle as b, PixiVNJsonConditionalResultToCombine as c, PixiVNJsonConditionalStatements as d, PixiVNJsonComparation as e, PixiVNJsonConditions as f, PixiVNJsonIfElse as g, PixiVNJsonStepSwitch as h, PixiVNJsonStepSwitchElementsType as i, PixiVNJsonStepSwitchElementType as j, PixiVNJsonUnionCondition as k, PixiVNJsonChoiceGet as l, PixiVNJsonLabelGet as m, PixiVNJsonLogicGet as n, PixiVNJsonParamGet as o, PixiVNJsonStorageGet as p, PixiVNJsonValueGet as q, PixiVNJsonValueSet as r };