mwg API
    Preparing search index...

    Interface DialogueLine

    The terse @id/- dialogue-text parsing engine behind both two-d/stage.parseDialogueText and rpg.parseDialogueText - the two-speaker alternation state machine lives here once, in core (already the home of parseCSV, another generic text-format parser that other modules build their own typed result around), so a rule change or a bug fix lands in one place instead of two silently-drifting copies. Each module's own wrapper only maps DialogueLine onto its own command shape - StageCommand's as versus EventCommand's speaker is the one real difference between them.

    Three kinds of line:

    • @id text names who is speaking and says text; @id alone (no text) just registers the speaker, without saying anything yet.
    • - text continues the two-speaker exchange the first two @id lines opened, alternating speaker on every line: the first - after the two openers goes to whichever of them did not speak last, and so on.
    • any other non-blank line narrates, with no speaker.
    @alice Hello.
    @bob Hi!
    - How are you?
    - Fine, and you?

    The - shorthand is deliberately capped at two speakers: it exists for the two-character back-and-forth, not as a guess at which of three or more people talks next. A third distinct @id anywhere in the source is a parse error rather than a silent guess.

    import { parseDialogueLines, type DialogueLine } from '@datamoc/mwg/core';

    const lines: DialogueLine[] = parseDialogueLines(`
    @alice Hello.
    @bob Hi!
    - How are you?
    `);
    console.log(lines); // [{ text: 'Hello.', speaker: 'alice' }, ...]
    interface DialogueLine {
        speaker?: string;
        text: string;
    }
    Index
    speaker?: string
    text: string