From fec684b2109f78d22fe70a5b8588a9a1ceed0d9a Mon Sep 17 00:00:00 2001 From: cha0s Date: Mon, 18 Jan 2021 21:41:32 -0600 Subject: [PATCH] refactor: resource loading --- packages/universe/src/resources/universe.js | 37 ++++++++------------- 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/packages/universe/src/resources/universe.js b/packages/universe/src/resources/universe.js index c7801bc..3205407 100644 --- a/packages/universe/src/resources/universe.js +++ b/packages/universe/src/resources/universe.js @@ -37,36 +37,25 @@ export default (latus) => class Universe extends JsonResource { this.#roomsFlat.push(room); } - static async extendJson(json) { - const uri = json.extends; - const extended = await super.extendJson(json); + async load(json = {}) { + super.load(json); + const {tps = 60, uri} = json; const {fromResourceType: {Room}} = resource(latus); if (uri) { const universePath = dirname(uri); - extended.rooms = Object.fromEntries( - await Promise.all( - ( - await pglob( - '**/*.room.json', - { - cwd: join(process.cwd(), this.root, universePath), - }, - ) + await Promise.all( + ( + await pglob( + '**/*.room.json', + { + cwd: join(process.cwd(), this.constructor.root, universePath), + }, ) - .map(async (roomUri) => [ - roomUri, - await Room.load({extends: join(universePath, roomUri)}), - ]), - ), + ).map(async (roomUri) => { + this.addRoom(roomUri, await Room.load({extends: join(universePath, roomUri)})); + }), ); } - return extended; - } - - load({rooms = {}, tps = 60} = {}) { - Object.entries(rooms).forEach(([uri, room]) => { - this.addRoom(uri, room); - }); this.#tps = tps; }