Removed depth field from placedMapObject as this is calculated automatically

This commit is contained in:
2025-01-23 19:47:33 +01:00
parent 189fd39377
commit 1546deb811
6 changed files with 44 additions and 83 deletions

View File

@ -1,6 +1,5 @@
import { BaseEvent } from '#application/base/baseEvent'
import { Map } from '#entities/map'
import MapRepository from '#repositories/mapRepository'
import { Map, MapCacheT } from '#entities/map'
type Payload = {
name: string
@ -13,11 +12,11 @@ export default class MapCreateEvent extends BaseEvent {
this.socket.on('gm:map:create', this.handleEvent.bind(this))
}
private async handleEvent(data: Payload, callback: (response: Map[]) => void): Promise<void> {
private async handleEvent(data: Payload, callback: (response: MapCacheT | false) => void): Promise<void> {
try {
if (!(await this.isCharacterGM())) return
this.logger.info(`User ${(await this.getCharacter())!.getId()} has created a new map via map editor.`)
this.logger.info(`GM ${(await this.getCharacter())!.getId()} has created a new map via map editor.`)
const map = new Map()
await map
@ -27,14 +26,11 @@ export default class MapCreateEvent extends BaseEvent {
.setTiles(Array.from({ length: data.height }, () => Array.from({ length: data.width }, () => 'blank_tile')))
.save()
const mapRepository = new MapRepository()
const mapList = await mapRepository.getAll()
return callback(mapList)
return callback(await map.cache())
} catch (error: any) {
this.logger.error('gm:map:create error', error.message)
this.socket.emit('notification', { message: 'Failed to create map.' })
return callback([])
return callback(false)
}
}
}

View File

@ -1,27 +0,0 @@
import { BaseEvent } from '#application/base/baseEvent'
import { Map } from '#entities/map'
import MapRepository from '#repositories/mapRepository'
interface IPayload {}
export default class MapListEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:map:list', this.handleEvent.bind(this))
}
private async handleEvent(data: IPayload, callback: (response: Map[]) => void): Promise<void> {
try {
if (!(await this.isCharacterGM())) return
this.logger.info(`User ${(await this.getCharacter())!.getId()} has listed maps via map editor.`)
const mapRepository = new MapRepository()
const maps = await mapRepository.getAll()
return callback(maps)
} catch (error: any) {
this.logger.error('gm:map:list error', error.message)
return callback([])
}
}
}

View File

@ -97,7 +97,6 @@ export default class MapUpdateEvent extends BaseEvent {
for (const object of data.placedMapObjects) {
const mapObject = new PlacedMapObject()
.setMapObject(object.mapObject)
.setDepth(object.depth)
.setIsRotated(object.isRotated)
.setPositionX(object.positionX)
.setPositionY(object.positionY)