50 lines
1.7 KiB
TypeScript
50 lines
1.7 KiB
TypeScript
import { BaseEvent } from '@/application/base/baseEvent'
|
|
import { SocketEvent } from '@/application/enums'
|
|
import type { UUID } from '@/application/types'
|
|
import MapObjectRepository from '@/repositories/mapObjectRepository'
|
|
|
|
type Payload = {
|
|
id: UUID
|
|
name: string
|
|
tags: string[]
|
|
depthOffsets: number[]
|
|
originX: number
|
|
originY: number
|
|
frameRate: number
|
|
frameWidth: number
|
|
frameHeight: number
|
|
}
|
|
|
|
export default class MapObjectUpdateEvent extends BaseEvent {
|
|
public listen(): void {
|
|
this.socket.on(SocketEvent.GM_MAPOBJECT_UPDATE, this.handleEvent.bind(this))
|
|
}
|
|
|
|
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
|
|
try {
|
|
if (!(await this.isCharacterGM())) return
|
|
|
|
const mapObjectRepository = new MapObjectRepository()
|
|
|
|
const mapObject = await mapObjectRepository.getById(data.id)
|
|
if (!mapObject) return callback(false)
|
|
|
|
if (data.name !== undefined) mapObject.name = data.name
|
|
if (data.tags !== undefined) mapObject.tags = data.tags
|
|
if (data.depthOffsets !== undefined) mapObject.depthOffsets = data.depthOffsets
|
|
if (data.originX !== undefined) mapObject.originX = data.originX
|
|
if (data.originY !== undefined) mapObject.originY = data.originY
|
|
if (data.frameRate !== undefined) mapObject.frameRate = data.frameRate
|
|
if (data.frameWidth !== undefined) mapObject.frameWidth = data.frameWidth
|
|
if (data.frameHeight !== undefined) mapObject.frameHeight = data.frameHeight
|
|
|
|
await mapObject.save()
|
|
|
|
return callback(true)
|
|
} catch (error) {
|
|
this.socket.emit(SocketEvent.NOTIFICATION, { title: 'Error', message: 'Failed to update mapObject.' })
|
|
return callback(false)
|
|
}
|
|
}
|
|
}
|