UNPKG

@drincs/pixi-vn-json

Version:

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

97 lines (91 loc) 4.2 kB
import { P as PixiVNJsonLabelStep, a as PixiVNJsonValueSet, b as PixiVNJsonIfElse, c as PixiVNJsonOperation } from './PixiVNJsonLabelStep-C-9WKwTo.cjs'; import { LabelAbstract, LabelProps, StepLabelPropsType, StepLabelType } from '@drincs/pixi-vn/narration'; import '@drincs/pixi-vn'; import '@drincs/pixi-vn/motion'; import 'pixi.js'; /** * Collection of labels to be used in the narrative. */ type PixiVNJsonLabels = { [labelId: string]: PixiVNJsonLabelStep[]; }; /** * PixiVNJson It can be defined as a programming language to write a narrative written in json. */ interface PixiVNJson { /** * The URI of the JSON Schema that describes and validates this document. * * You can point to a specific version of the schema, for example: * - `"https://pixi-vn.web.app/schemas/1.13.0/schema.json"` — pin to a specific version * - `"https://pixi-vn.web.app/schemas/latest/schema.json"` — always use the latest version * * Most editors (VS Code, WebStorm, etc.) use this field to provide * auto-completion, hover documentation, and validation for the document. */ $schema?: string; /** * The operations to be executed before the narrative starts. * For the set storage: They will be set only if there are no variables with the same key already. * For the det tempstorage: if there are variables with the same key already, they will be overwritten. */ initialOperations?: (PixiVNJsonValueSet | PixiVNJsonIfElse<PixiVNJsonValueSet>)[]; /** * The labels to be used in the narrative. They will be added to the system */ labels?: PixiVNJsonLabels; } type LabelJsonOptions = { /** * Function that converts a string to a {@link PixiVNJsonOperation}. * If is a special operation you can return undefined and can run the operation. */ operationStringConvert?: (value: string, step: PixiVNJsonLabelStep, props: StepLabelPropsType | object) => Promise<PixiVNJsonOperation | undefined>; /** * If true and a dialog is empty or has only spaces, {@link PixiVNJsonLabelStep.goNextStep} will be set to true. */ skipEmptyDialogs?: boolean; }; /** * A label whose steps are defined by a plain JSON structure ({@link PixiVNJsonLabelStep}[]). * * `LabelJson` bridges pixi-vn's label system and the JSON script format: each step is * lazily converted to a {@link StepLabelType} closure that resolves dialogues, choices, * operations, and conditional overrides at runtime via {@link JsonUnifier}. * * @template T - The type of the props object passed between steps. */ declare class LabelJson<T extends {} = object> extends LabelAbstract<LabelJson<T>, T> { /** * @param id is the id of the label * @param steps is the list of steps that the label will perform * @param props is the properties of the label */ constructor(id: string, steps: (PixiVNJsonLabelStep | (() => PixiVNJsonLabelStep))[], props?: LabelProps<LabelJson<T>>, options?: LabelJsonOptions); private _steps; get steps(): StepLabelType<T>[]; get stepCount(): number; getStepById(stepId: number): StepLabelType<T> | undefined; private operationStringConvert?; private skipEmptyDialogs; /** * Returns the SHA-1 hash of the raw step at the given index. * Can be used to detect step changes across label reloads. * * @param index - Zero-based index of the step. * @returns The hex SHA-1 string, or `undefined` if the index is out of range. */ getStepSha(index: number): string | undefined; private getDialogueText; private getDialogue; private getChoices; private stepConverter; } /** * Import a Pixi'VN JSON to the system. * This feature was created to give other developers the ability to create tools that can generate Pixi'VN labels or that generate Pixi'VN after extracting information from a programming language designed for writing narratives. * @param values The Pixi'VN JSON to be imported * @returns */ declare function importPixiVNJson(values: PixiVNJson | string | (PixiVNJson | string)[], options?: LabelJsonOptions): Promise<void>; export { LabelJson, importPixiVNJson };