mwg API
    Preparing search index...

    Function setAssetMap

    • Hands resolve/has/paths a game's own path-to-URI map, in place of tools/compile-resources's window.__MWG_ASSETS__ convention.

      A game bundled by its own tool (Vite, say) that compiles its assets into data: URIs a different way still wants resolve's single lookup and isCompiled's dev/build branch, without also adopting window.__MWG_ASSETS__ as the wire format. Passing the map here makes this file agnostic to how the map was built, only to its shape - { path: uri }, the same shape window.__MWG_ASSETS__ already is. undefined reverts to reading window.__MWG_ASSETS__ (or dev-server mode, if that is unset too).

      A value is one of three things:

      • a finished URL (data: or blob:), which works everywhere a path does, resolve included;
      • typed bytes: a Blob, or { bytes, type }, which load() turns into a blob: URL and gives the MIME type to the texture loader, so the host need not know the format rules;
      • a function returning typed bytes (or a promise of them), read once when load() first asks, so a packed archive can decode one file at a time with no base64 copy.

      Bytes are only readable through load(): resolve is synchronous and throws for them until the path has been loaded, naming load() as the fix. A key missing from the map throws too, so a host whose Proxy.get returns nothing for a path gets a loud error, not a silent skip. setAssetMap revokes the URLs it minted for the old map; release revokes one path's.

      Parameters

      Returns void

      import { setAssetMap, isCompiled, resolve } from '@datamoc/mwg/assets/paths';

      setAssetMap({ 'tiles.png': 'data:image/png;base64,...' });
      console.log(isCompiled()); // true
      console.log(resolve('tiles.png')); // the data: URI handed in above

      setAssetMap(undefined); // back to window.__MWG_ASSETS__ / dev-server mode