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

@ -19,9 +19,6 @@ export class BasePlacedMapObject extends BaseEntity {
@ManyToOne({ deleteRule: 'cascade', eager: true })
mapObject!: MapObject
@Property()
depth = 0
@Property()
isRotated = false
@ -58,15 +55,6 @@ export class BasePlacedMapObject extends BaseEntity {
return this.mapObject
}
setDepth(depth: number) {
this.depth = depth
return this
}
getDepth() {
return this.depth
}
setIsRotated(isRotated: boolean) {
this.isRotated = isRotated
return this

View File

@ -2,6 +2,8 @@ import { Entity } from '@mikro-orm/core'
import { BaseMap } from '#entities/base/map'
export type MapCacheT = ReturnType<Map['cache']> | {}
@Entity()
export class Map extends BaseMap {
public async cache() {
@ -20,7 +22,6 @@ export class Map extends BaseMap {
placedMapObjects: this.getPlacedMapObjects().map((placedMapObject) => ({
id: placedMapObject.getId(),
mapObject: placedMapObject.getMapObject().getId(),
depth: placedMapObject.getDepth(),
isRotated: placedMapObject.getIsRotated(),
positionX: placedMapObject.getPositionX(),
positionY: placedMapObject.getPositionY()

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)