Converted more events
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import { MapObject } from '#entities/mapObject'
|
||||
import ObjectRepository from '#repositories/mapObjectRepository'
|
||||
import MapObjectRepository from '#repositories/mapObjectRepository'
|
||||
|
||||
interface IPayload {}
|
||||
|
||||
@ -10,10 +11,17 @@ export default class MapObjectListEvent extends BaseEvent {
|
||||
}
|
||||
|
||||
private async handleEvent(data: IPayload, callback: (response: MapObject[]) => void): Promise<void> {
|
||||
if (!(await this.isCharacterGM())) return
|
||||
try {
|
||||
if (!(await this.isCharacterGM())) return
|
||||
|
||||
// get all objects
|
||||
const objects = await ObjectRepository.getAll()
|
||||
return callback(objects)
|
||||
// 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([])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,8 @@ export default class MapObjectRemoveEvent extends BaseEvent {
|
||||
}
|
||||
|
||||
private async handleEvent(data: IPayload, callback: (response: boolean) => void): Promise<void> {
|
||||
if (!(await this.isCharacterGM())) return
|
||||
|
||||
try {
|
||||
if (!(await this.isCharacterGM())) return
|
||||
// remove the tile from the disk
|
||||
const finalFilePath = Storage.getPublicPath('map_objects', data.mapObjectId + '.png')
|
||||
fs.unlink(finalFilePath, async (err) => {
|
||||
@ -27,7 +26,8 @@ export default class MapObjectRemoveEvent extends BaseEvent {
|
||||
return
|
||||
}
|
||||
|
||||
await (await MapObjectRepository.getById(data.mapObjectId))?.delete()
|
||||
const mapObjectRepository = new MapObjectRepository()
|
||||
await (await mapObjectRepository.getById(data.mapObjectId))?.delete()
|
||||
|
||||
return callback(true)
|
||||
})
|
||||
|
@ -23,10 +23,12 @@ export default class MapObjectUpdateEvent extends BaseEvent {
|
||||
try {
|
||||
if (!(await this.isCharacterGM())) return
|
||||
|
||||
const mapObject = await MapObjectRepository.getById(data.id)
|
||||
const mapObjectRepository = new MapObjectRepository()
|
||||
|
||||
const mapObject = await mapObjectRepository.getById(data.id)
|
||||
if (!mapObject) return callback(false)
|
||||
|
||||
await mapObject.setName(data.name).setTags(data.tags).setOriginX(data.originX).setOriginY(data.originY).setIsAnimated(data.isAnimated).setFrameRate(data.frameRate).setFrameWidth(data.frameWidth).setFrameHeight(data.frameHeight).update()
|
||||
await mapObject.setName(data.name).setTags(data.tags).setOriginX(data.originX).setOriginY(data.originY).setIsAnimated(data.isAnimated).setFrameRate(data.frameRate).setFrameWidth(data.frameWidth).setFrameHeight(data.frameHeight).save()
|
||||
|
||||
return callback(true)
|
||||
} catch (error) {
|
||||
|
@ -33,7 +33,7 @@ export default class MapObjectUploadEvent extends BaseEvent {
|
||||
|
||||
// Create new map object and save it to database
|
||||
const mapObject = new MapObject()
|
||||
await mapObject.setName(key).setTags([]).setOriginX(0).setOriginY(0).setFrameWidth(width).setFrameHeight(height).save()
|
||||
await mapObject.setName('New map object').setTags([]).setOriginX(0).setOriginY(0).setFrameWidth(width).setFrameHeight(height).save()
|
||||
|
||||
// Save image to disk
|
||||
const uuid = mapObject.getId()
|
||||
|
Reference in New Issue
Block a user