import { Difference } from 'microdiff'; import { StoredChoiceInterface, StorageElementType, OpenedLabel } from '@drincs/pixi-vn/canvas'; import { CharacterInterface } from '@drincs/pixi-vn'; /** * An empty interface that can be augmented via `declare module '@drincs/pixi-vn/narration'` * to constrain the set of valid label IDs to a known union of string literals. * * When this interface has no keys (the default), {@link LabelIdType} resolves to `string`, * preserving full backwards compatibility. Once you augment it, {@link LabelIdType} becomes * the union of the declared keys and the compiler will reject any unknown label ID. * * The augmentation is typically written into an auto-generated declaration file by the * Vite plugin (see the `labelTypeFilePath` option of `vitePluginPixivn`), but it can * also be written by hand. * * @example * ```ts * // pixi-vn.gen.d.ts (auto-generated — do not edit manually) * declare module "@drincs/pixi-vn/narration" { * interface PixivnLabelIds { * startLabel: never; * menuLabel: never; * } * } * export {}; * ``` */ interface PixivnLabelIds { } /** * The type used wherever a label ID is expected (e.g. `narration.call`, `narration.jump`, * `newLabel`, choice options, …). * * - **Default** — resolves to `string` so that existing code that passes arbitrary strings * continues to compile without any changes. * - **Augmented** — when {@link PixivnLabelIds} has been extended via * `declare module "@drincs/pixi-vn/narration"`, this type resolves to the union of the * declared keys, giving you compile-time safety against typos and unknown label IDs. */ type LabelIdType = [keyof PixivnLabelIds] extends [never] ? string : keyof PixivnLabelIds; interface DialogueInterface { /** * The text of the dialogue. */ text: string | string[]; /** * The id of the character that is speaking. */ character?: CharacterInterface | string; } type StoredDialogue = Omit & { character: string | undefined; }; interface HistoryStep { /** * The difference between the previous step and the current step. */ diff?: Difference[]; /** * The label id of the current step. */ currentLabel?: LabelIdType; /** * The sha1 of the step function. */ stepSha1: string; /** * Equivalent to the narration.stepCounter */ index: number; /** * The data of the step of the label. */ labelStepIndex: number | null; /** * Dialogue to be shown in the game */ dialogue?: StoredDialogue; /** * List of choices asked of the player */ choices?: StoredChoiceInterface[]; /** * List of choices already made by the player */ alreadyMadeChoices?: number[]; /** * The input value of the player */ inputValue?: StorageElementType; /** * Whether this step requested an input from the player (regardless of whether a * default value was provided, unlike {@link inputValue} which is only set when one is). */ isRequiredInput?: boolean; /** * The choice made by the player */ choiceIndexMade?: number; /** * If true, the current dialogue will be glued to the previous one. */ isGlued?: boolean; /** * Opened Labels in the current step. */ openedLabels?: OpenedLabel[]; } export type { DialogueInterface as D, HistoryStep as H, LabelIdType as L, PixivnLabelIds as P };