27 lines
821 B
TypeScript
27 lines
821 B
TypeScript
import { BaseEvent } from '#application/base/baseEvent'
|
|
import { MapObject } from '#entities/mapObject'
|
|
import MapObjectRepository from '#repositories/mapObjectRepository'
|
|
|
|
interface IPayload {}
|
|
|
|
export default class MapObjectListEvent extends BaseEvent {
|
|
public listen(): void {
|
|
this.socket.on('gm:mapObject:list', this.handleEvent.bind(this))
|
|
}
|
|
|
|
private async handleEvent(data: IPayload, callback: (response: MapObject[]) => void): Promise<void> {
|
|
try {
|
|
if (!(await this.isCharacterGM())) return
|
|
|
|
// Get all map objects
|
|
const mapObjectRepository = new MapObjectRepository()
|
|
const mapObjects = await mapObjectRepository.getAll()
|
|
|
|
return callback(mapObjects)
|
|
} catch (error) {
|
|
this.logger.error('gm:mapObject:list error', error)
|
|
return callback([])
|
|
}
|
|
}
|
|
}
|