mwg API
    Preparing search index...

    Function parsePackageDocument

    • Reads a package document: the MWL tags package, asset, character, animation, sound_effect, music, script and import, into plain typed data. Macros and #includes are expanded first, as for any MWL file. Nothing is executed: a script's when is only checked for syntax and its do only for membership of the safe vocabulary.

      character is a macro, not a compiled type of its own: it stays one record here and expands into a unit_type (plus the animations, effects and scripts it names) when merged. A new compiled table would need its own schema, validator and loader beside the one unit_type already has; the macro reuses all of them, and the fields only a renderer or a player of sound reads (portrait, sprite, theme) have no consumer in the rules core anyway.

      Parameters

      Returns PackageDocument

      import { parsePackageDocument } from '@datamoc/mwg/mwl';

      const document = parsePackageDocument(
      "[{ tag: 'package', id: 'marta', version: '1.0.0' }, { tag: 'character', id: 'marta', hitpoints: 28 }]",
      );
      console.log(document.characters[0]?.stats.hitpoints); // 28