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
Hands
resolve/has/pathsa game's own path-to-URI map, in place oftools/compile-resources'swindow.__MWG_ASSETS__convention.A game bundled by its own tool (Vite, say) that compiles its assets into
data:URIs a different way still wantsresolve's single lookup andisCompiled's dev/build branch, without also adoptingwindow.__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 shapewindow.__MWG_ASSETS__already is.undefinedreverts to readingwindow.__MWG_ASSETS__(or dev-server mode, if that is unset too).A value is one of three things:
data:orblob:), which works everywhere a path does,resolveincluded;{ bytes, type }, whichload()turns into ablob:URL and gives the MIME type to the texture loader, so the host need not know the format rules;load()first asks, so a packed archive can decode one file at a time with no base64 copy.Bytes are only readable through
load():resolveis synchronous and throws for them until the path has been loaded, namingload()as the fix. A key missing from the map throws too, so a host whoseProxy.getreturns nothing for a path gets a loud error, not a silent skip.setAssetMaprevokes the URLs it minted for the old map;releaserevokes one path's.