Set up various event callbacks. On 'init', load space.
StaticloadStaticloadLoad a map. If no name is provided, defaults to the first map of the
space. If no space is provided, defaults to currently loaded space.
/
async #loadMap_old(space?: WaytaleSpace, mapName?: string): Promise
if(space === undefined) { throw new WaytaleError("Cannot load map, no space provided."); }
// TODO do not default // 'maps' info should be moved out of 'info' mapName ??= (space.config as {info: {maps: string[]}}).info.maps[0];
try { if (!mapName) { throw new WaytaleError("Cannot load map, no map name specified."); }
const urlBase = ${space.url}${mapName}/;
// always bypass cache
// TODO make this configurable in the settings
const urlFull = ${urlBase}map.json?t=${+this.getTimestamp()};
logger.log(Loading map "${mapName}" of space at: ${space.url});
// TODO handle broken space/map config
// FUTURE try foreign domain proxy on fail
const response = await fetch(urlFull);
if (!response.ok) {
let message = Fetching remote file failed with HTTP error ${response.status}.;
if (response.status == 404) {
message = ${message} Could not find <code>map.json</code> file +
for map "${mapName}". Is the map name spelled correctly in the +
URL or <code>space.json</code>? Does map directory and file +
exist?;
}
throw new WaytaleError(message);
}
const mapConfig = await response.json() as unknown; const map = new WaytaleMap(urlBase, mapConfig); // this.setMap(map);
} catch (error) { this.#loadingJsonErrorHandler(error as {message: string}); } }
/** Load a map. If no name is provided, defaults to the first map of the space.
StaticloadLoad a space. Defaults to the current web "directory", that is anything
until and including the first slash in the URL path.
/
async #loadSpace_old(url?: string): Promise${urlBase}space.json?t=${+this.getTimestamp()};
// FUTURE try foreign domain proxy on fail
try {
logger.log(Loading space at: ${url});
const response = await fetch(urlFull);
if (!response.ok) {
let message = Fetching remote file failed with HTTP error ${response.status}.;
if (response.status == 404) {
message = ${message} Could not find <code>space.json</code> +
"file. Does it exist? Is it in the correct directory? Have you " +
"edited a space.template.json file and forgot to " +
"rename it?";
}
throw new WaytaleError(message);
}
const spaceConfig = await response.json() as unknown; const space = new WaytaleSpace(urlBase, spaceConfig) // this.setSpace(space);
} catch (error) { this.#loadingJsonErrorHandler(error as {message: string}); } }
/** Load a space. Defaults to the current web "directory", that is anything until and including the first slash in the URL path.
General space and map management. Deals with events related to loading and unloading of space and maps, including subsequent addition and removal of avatars and gadgets. Load resources like
space.jsonandmap.json.The responsibilities of this class are currently quite broad and might be split up in the future.