Rework generateAll() to not have hardcoded skip of "base" map + moved code around + varaible rename

Made generate() private
This commit is contained in:
Dev 2023-07-15 11:58:35 +01:00
parent 7a1140c229
commit 5e3d3f5bd7

View File

@ -52,7 +52,7 @@ export class LocationController
} }
/* generates a random location preset to use for local session */ /* 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 location: ILocation = this.databaseServer.getTables().locations[name];
const output: ILocationBase = this.jsonUtil.clone(location.base); 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 * Get all maps base location properties without loot data
* @returns ILocationsGenerateAllResponse * @returns ILocationsGenerateAllResponse
*/ */
public generateAll(): ILocationsGenerateAllResponse public generateAll(): ILocationsGenerateAllResponse
{ {
const locations = this.databaseServer.getTables().locations; const locationsFromDb = this.jsonUtil.clone(this.databaseServer.getTables().locations);
const locations: ILocations = {};
const returnResult: ILocationsGenerateAllResponse = { for (const mapName in locationsFromDb)
locations: undefined,
paths: []
};
// use right id's and strip loot
const data: ILocations = {};
for (const name in locations)
{ {
if (name === "base") const mapBase = locationsFromDb[mapName]?.base;
if (!mapBase)
{ {
this.logger.debug(`Map: ${mapName} has no base json file, skipping generation`);
continue; continue;
} }
const map = locations[name].base; // Clear out loot array
mapBase.Loot = [];
map.Loot = []; // Add map base data to dictionary
data[map._Id] = map; locations[mapBase._Id] = mapBase;
} }
returnResult.locations = data; return {
returnResult.paths = locations.base.paths; locations: locations,
return returnResult; paths: locationsFromDb.base.paths
};
} }
/** /**