From 5e3d3f5bd7758a13ec45eaf4b967da6cee6d3b3a Mon Sep 17 00:00:00 2001 From: Dev Date: Sat, 15 Jul 2023 11:58:35 +0100 Subject: [PATCH] Rework generateAll() to not have hardcoded skip of "base" map + moved code around + varaible rename Made generate() private --- project/src/controllers/LocationController.ts | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/project/src/controllers/LocationController.ts b/project/src/controllers/LocationController.ts index 6a291748..6f679b7f 100644 --- a/project/src/controllers/LocationController.ts +++ b/project/src/controllers/LocationController.ts @@ -52,7 +52,7 @@ export class LocationController } /* generates a random location preset to use for local session */ - public generate(name: string): ILocationBase + private generate(name: string): ILocationBase { const location: ILocation = this.databaseServer.getTables().locations[name]; const output: ILocationBase = this.jsonUtil.clone(location.base); @@ -110,35 +110,33 @@ export class LocationController } /** + * Handle client/locations * Get all maps base location properties without loot data * @returns ILocationsGenerateAllResponse */ public generateAll(): ILocationsGenerateAllResponse { - const locations = this.databaseServer.getTables().locations; - - const returnResult: ILocationsGenerateAllResponse = { - locations: undefined, - paths: [] - }; - // use right id's and strip loot - const data: ILocations = {}; - for (const name in locations) + const locationsFromDb = this.jsonUtil.clone(this.databaseServer.getTables().locations); + const locations: ILocations = {}; + for (const mapName in locationsFromDb) { - if (name === "base") + const mapBase = locationsFromDb[mapName]?.base; + if (!mapBase) { + this.logger.debug(`Map: ${mapName} has no base json file, skipping generation`); continue; } - const map = locations[name].base; - - map.Loot = []; - data[map._Id] = map; + // Clear out loot array + mapBase.Loot = []; + // Add map base data to dictionary + locations[mapBase._Id] = mapBase; } - returnResult.locations = data; - returnResult.paths = locations.base.paths; - return returnResult; + return { + locations: locations, + paths: locationsFromDb.base.paths + }; } /**