forked from noxious/server
npm update, http asset endpoint changes
This commit is contained in:
@ -2,8 +2,7 @@ import { Zone } from '@prisma/client'
|
||||
import ZoneRepository from '../repositories/zoneRepository'
|
||||
import ZoneService from '../services/zoneService'
|
||||
import LoadedZone from '../models/loadedZone'
|
||||
import zoneRepository from '../repositories/zoneRepository'
|
||||
import { gameMasterLogger } from '../utilities/logger'
|
||||
import { gameLogger } from '../utilities/logger'
|
||||
|
||||
class ZoneManager {
|
||||
private loadedZones: LoadedZone[] = []
|
||||
@ -21,36 +20,20 @@ class ZoneManager {
|
||||
await this.loadZone(zone)
|
||||
}
|
||||
|
||||
gameMasterLogger.info('Zone manager loaded')
|
||||
}
|
||||
|
||||
public async getZoneAssets(zone: Zone): Promise<ZoneAssets> {
|
||||
const tiles: string[] = this.getUnique((JSON.parse(JSON.stringify(zone.tiles)) as string[][]).reduce((acc, val) => [...acc, ...val]))
|
||||
const objects = await zoneRepository.getObjects(zone.id)
|
||||
const mappedObjects = this.getUnique(objects.map((x) => x.objectId))
|
||||
|
||||
return {
|
||||
tiles: tiles,
|
||||
objects: mappedObjects
|
||||
} as ZoneAssets
|
||||
}
|
||||
|
||||
private getUnique<T>(array: T[]) {
|
||||
return [...new Set<T>(array)]
|
||||
gameLogger.info('Zone manager loaded')
|
||||
}
|
||||
|
||||
// Method to handle individual zoneEditor loading
|
||||
public async loadZone(zone: Zone) {
|
||||
const loadedZone = new LoadedZone(zone)
|
||||
this.loadedZones.push(loadedZone)
|
||||
await this.getZoneAssets(zone)
|
||||
gameMasterLogger.info(`Zone ID ${zone.id} loaded`)
|
||||
gameLogger.info(`Zone ID ${zone.id} loaded`)
|
||||
}
|
||||
|
||||
// Method to handle individual zoneEditor unloading
|
||||
public unloadZone(zoneId: number) {
|
||||
this.loadedZones = this.loadedZones.filter((loadedZone) => loadedZone.getZone().id !== zoneId)
|
||||
gameMasterLogger.info(`Zone ID ${zoneId} unloaded`)
|
||||
gameLogger.info(`Zone ID ${zoneId} unloaded`)
|
||||
}
|
||||
|
||||
// Getter for loaded zones
|
||||
|
Reference in New Issue
Block a user