Skip to content

mapsFrom ​

Function of @v12-engine/engine

ts
export declare function mapsFrom(files: Readonly<Record<string, () => unknown>>): LazyMaps;

The maps of map files, by the name of each file without its folder and .vgmap.json: ./maps/field.vgmap.json is field. The files by their paths, read (parseMap): imported one by one, or Vite's import.meta.glob('./maps/*.vgmap.json', { eager: true, import: 'default' }) where only a page reads them

export const maps = mapsFrom( './maps/field.vgmap.json': field, './maps/hills.vgmap.json': hills )

Given what loads each file in place of the file (import.meta.glob('./maps/*.vgmap.json', { import: 'default' }), not eager; or () => import('./field.vgmap.json')), nothing is fetched or read until a map is asked for: the result is then LazyMaps, each a function giving the map (a promise), and the page carries one chunk a map. appScenes takes both

export const maps = mapsFrom(import.meta.glob('./maps/*.vgmap.json', import: 'default' )) const field = await maps.field()

Throws for two files of one name, for files some given and some loaded, and with the path of a file that cannot be read