48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import type { UUID } from '#application/types'
|
|
|
|
import { BaseEvent } from '#application/base/baseEvent'
|
|
import MapObjectRepository from '#repositories/mapObjectRepository'
|
|
|
|
type Payload = {
|
|
id: UUID
|
|
name: string
|
|
tags: string[]
|
|
originX: number
|
|
originY: number
|
|
frameRate: number
|
|
frameWidth: number
|
|
frameHeight: number
|
|
}
|
|
|
|
export default class MapObjectUpdateEvent extends BaseEvent {
|
|
public listen(): void {
|
|
this.socket.on('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.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('notification', { title: 'Error', message: 'Failed to update mapObject.' })
|
|
return callback(false)
|
|
}
|
|
}
|
|
}
|