mwg API
    Preparing search index...

    Function parseDialogueText

    • A terse, line-based text format for straight (non-branching) dialogue - the format a text-only RPG (core plus rpg, no renderer at all) can use for its own EventCommand scripts without depending on two-d for anything. two-d/stage has its own wrapper around the same parsing engine (core.parseDialogueLines) targeting StageCommand instead - declared separately for the same reason EventChoice is declared separately from two-d/ui's Choice: a Pixi-based visual novel that never touches rpg's map events should not have to pull the whole module in just to parse dialogue text, and a text-only RPG should not have to pull in Pixi either. The actual @id/- parsing logic lives once in core.parseDialogueLines, not copied between the two - only the final command shape (speaker here, as in two-d/stage) differs.

      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; a scene with more than two speakers writes @id on every line instead, same as it does today.

      Lines reach EventCommand.say as plain, untranslated text - a game's own translation step decides how that text reaches a player, the same seam MWL's own _("...")-marked strings use (the source text doubles as the catalog key). extractDialogueCatalog builds that catalog the same way MWL's extractCatalog does, for a game that wants a translator-ready file to start from.

      Parameters

      • source: string

      Returns EventCommand[]

      import { parseDialogueText, EventRunner, GameState } from '@datamoc/mwg/rpg';

      declare const game: GameState;

      const runner = new EventRunner({
      game,
      present: async (request) => {
      console.log(request.speaker ? `${request.speaker}: ${request.text}` : request.text);
      },
      });
      const commands = parseDialogueText(`
      @alice Hello.
      @bob Hi!
      - How are you?
      - Fine, and you?
      `);
      await runner.run(commands);