Renamed zone > map
This commit is contained in:
@ -33,7 +33,7 @@ class HttpManager {
|
||||
|
||||
// Assets routes
|
||||
app.get('/assets/list_tiles', (req, res) => this.assetsController.listTiles(req, res))
|
||||
app.get('/assets/list_tiles/:zoneId', (req, res) => this.assetsController.listTilesByZone(req, res))
|
||||
app.get('/assets/list_tiles/:mapId', (req, res) => this.assetsController.listTilesByMap(req, res))
|
||||
app.get('/assets/list_sprite_actions/:spriteId', (req, res) => this.assetsController.listSpriteActions(req, res))
|
||||
app.get('/assets/:type/:spriteId?/:file', (req, res) => this.assetsController.downloadAsset(req, res))
|
||||
}
|
||||
|
50
src/managers/mapManager.ts
Normal file
50
src/managers/mapManager.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import Logger, { LoggerType } from '#application/logger'
|
||||
import { UUID } from '#application/types'
|
||||
import { Map } from '#entities/map'
|
||||
import LoadedMap from '#models/loadedMap'
|
||||
import MapCharacter from '#models/mapCharacter'
|
||||
import MapRepository from '#repositories/mapRepository'
|
||||
|
||||
class MapManager {
|
||||
private readonly maps: Record<UUID, LoadedMap> = {}
|
||||
private logger = Logger.type(LoggerType.GAME)
|
||||
|
||||
public async boot(): Promise<void> {
|
||||
const maps = await MapRepository.getAll()
|
||||
await Promise.all(maps.map((map) => this.loadMap(map)))
|
||||
|
||||
this.logger.info(`Map manager loaded with ${Object.keys(this.maps).length} maps`)
|
||||
}
|
||||
|
||||
public async loadMap(map: Map): Promise<void> {
|
||||
this.maps[map.id] = new LoadedMap(map)
|
||||
this.logger.info(`Map ID ${map.id} loaded`)
|
||||
}
|
||||
|
||||
public unloadMap(mapId: UUID): void {
|
||||
delete this.maps[mapId]
|
||||
this.logger.info(`Map ID ${mapId} unloaded`)
|
||||
}
|
||||
|
||||
public getLoadedMaps(): LoadedMap[] {
|
||||
return Object.values(this.maps)
|
||||
}
|
||||
|
||||
public getMapById(mapId: UUID): LoadedMap | undefined {
|
||||
return this.maps[mapId]
|
||||
}
|
||||
|
||||
public getCharacterById(characterId: UUID): MapCharacter | undefined {
|
||||
for (const map of Object.values(this.maps)) {
|
||||
const character = map.getCharactersInMap().find((char) => char.character.id === characterId)
|
||||
if (character) return character
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
public removeCharacter(characterId: UUID): void {
|
||||
Object.values(this.maps).forEach((map) => map.removeCharacter(characterId))
|
||||
}
|
||||
}
|
||||
|
||||
export default new MapManager()
|
@ -1,51 +0,0 @@
|
||||
import Logger, { LoggerType } from '#application/logger'
|
||||
import { UUID } from '#application/types'
|
||||
import { Zone } from '#entities/zone'
|
||||
import LoadedZone from '#models/loadedZone'
|
||||
import ZoneCharacter from '#models/zoneCharacter'
|
||||
import ZoneRepository from '#repositories/zoneRepository'
|
||||
|
||||
class ZoneManager {
|
||||
private readonly zones = new Map<UUID, LoadedZone>()
|
||||
private logger = Logger.type(LoggerType.GAME)
|
||||
|
||||
public async boot(): Promise<void> {
|
||||
const zones = await ZoneRepository.getAll()
|
||||
await Promise.all(zones.map((zone) => this.loadZone(zone)))
|
||||
|
||||
this.logger.info(`Zone manager loaded with ${this.zones.size} zones`)
|
||||
}
|
||||
|
||||
public async loadZone(zone: Zone): Promise<void> {
|
||||
const loadedZone = new LoadedZone(zone)
|
||||
this.zones.set(zone.id, loadedZone)
|
||||
this.logger.info(`Zone ID ${zone.id} loaded`)
|
||||
}
|
||||
|
||||
public unloadZone(zoneId: UUID): void {
|
||||
this.zones.delete(zoneId)
|
||||
this.logger.info(`Zone ID ${zoneId} unloaded`)
|
||||
}
|
||||
|
||||
public getLoadedZones(): LoadedZone[] {
|
||||
return Array.from(this.zones.values())
|
||||
}
|
||||
|
||||
public getZoneById(zoneId: UUID): LoadedZone | undefined {
|
||||
return this.zones.get(zoneId)
|
||||
}
|
||||
|
||||
public getCharacterById(characterId: UUID): ZoneCharacter | undefined {
|
||||
for (const zone of this.zones.values()) {
|
||||
const character = zone.getCharactersInZone().find((char) => char.character.id === characterId)
|
||||
if (character) return character
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
public removeCharacter(characterId: UUID): void {
|
||||
this.zones.forEach((zone) => zone.removeCharacter(characterId))
|
||||
}
|
||||
}
|
||||
|
||||
export default new ZoneManager()
|
Reference in New Issue
Block a user