import registry from 'registry'; import repeat from 'lodash/repeat.js'; import loadMap from 'load-map'; import Location from 'Location'; export default class Map { home = null; constructor(){ } async initialize(){ this.home = new Location(); this.home.root = this.home; this.home.parent = this.home; this.home.id="home", this.home.name="home", this.home.label="Home" // LOAD MAP HERE await this.loadMap(registry.mapFile); } /* An external module is used to load XML based object trees */ async loadMap(xmlFile) { await loadMap({ attachTo: this.home, xmlFile, }); } // load /* Find a location by name */ location(name){ let finding = null; const finder = function(node){ if(node.name == name) { finding = node; return; } if(node.getElements) node.getElements().forEach(function(child){ finder(child) }) } finder(this.home); return finding; } /* Print a debug map use this function as a seed for more complex world maps */ show (){ const show = function(node, indent = -1){ indent++; const className = node.constructor.name; const spaceIndent = repeat(' ', indent); const objectName = node.label||node.name||node.id; console.log(`${spaceIndent}${objectName} (${className})`); if(node.getElements) node.getElements().forEach(function(child){ show(child, indent) }) indent-- } show(this.home); } }