UNPKG

@robingamedev/visual-novel-dialogue

Version:

A minimal, JSON-driven dialogue plugin for Phaser 3 games with support for branching choices, typewriter effects, and simple inline formatting.

159 lines 4.05 kB
import { Scene } from 'phaser'; export interface DialogueConfig { fontFamily?: string; typeSpeed?: number; boxStyle?: string; autoForward?: boolean; boxAnimationSpeed?: number; boxPosition?: 'bottom' | 'top' | 'center'; styles?: Record<string, TextStyle>; audio?: Record<string, string>; debug?: boolean; } export interface TextStyle { color?: string; bold?: boolean; italic?: boolean; fontSize?: number; } export interface ParsedStyle extends TextStyle { content: string; } export interface DialogueSettings { characters: Record<string, Character>; } export interface Character { name: string; color: string; } export interface DialogueScript { [label: string]: (string | ChoiceCommand)[]; } export interface ChoiceCommand { Choice: Record<string, string>; } export interface DialogueData { settings: DialogueSettings; script: DialogueScript; } export default class VisualNovelDialogue { private scene; private config; private data; private currentLabel; private currentLineIndex; private isActive; private isPaused; private dialogueBox?; private choiceBox?; private typewriterTimer?; private currentTypewriterText; private typewriterIndex; private isTypewriting; private isShowingChoices; private currentStyle?; onLineEnd?: (line: string) => void; onChoice?: (label: string, choiceText: string) => void; onEnd?: () => void; onShow?: (characterId: string, emotion: string) => void; onHide?: (characterId: string) => void; constructor(scene: Scene, config?: DialogueConfig); /** * Load dialogue data from JSON file or object * @param dataOrPath - Dialogue data object or file path (file loading not yet implemented) */ load(dataOrPath: string | DialogueData): void; /** * Start dialogue at the specified label * @param label - The label to start from (defaults to 'Start') */ start(label?: string): void; /** * Jump to a specific label in the dialogue script * @param label - The label to jump to */ jumpTo(label: string): void; /** * Pause the dialogue (prevents advancement) */ pause(): void; /** * Resume the dialogue (allows advancement to continue) */ resume(): void; /** * Process the next line in the current script */ private processNextLine; /** * Process a single line or command */ private processLine; /** * Process a string line (dialogue or command) */ private processStringLine; /** * Process a choice command */ private processChoice; /** * Display dialogue text in the dialogue box with typewriter effect */ private displayDialogue; /** * Start typewriter effect for text */ private startTypewriter; /** * Parse inline formatting tags */ private parseInlineFormatting; /** * Play audio file */ private playAudio; /** * Apply text styling to dialogue box */ private applyTextStyle; /** * Handle typewriter tick */ private onTypewriterTick; /** * Stop typewriter effect */ private stopTypewriter; /** * Skip the current typewriter effect (show full text immediately) */ skipTypewriter(): void; /** * Check if typewriter is currently active * @returns true if typewriter is running */ isTypewriterActive(): boolean; /** * Check if choices are currently being displayed * @returns true if choice UI is active */ isChoicesActive(): boolean; /** * Advance to the next line in the current script (manual progression) */ nextLine(): void; /** * End the dialogue sequence */ private endDialogue; /** * Show the dialogue box */ show(): void; /** * Hide the dialogue box */ hide(): void; } //# sourceMappingURL=VisualNovelDialogue.d.ts.map