forked from noxious/server
Almost finalised refactoring
This commit is contained in:
@ -5,9 +5,9 @@ import { Map } from '#entities/map'
|
||||
import { MapEffect } from '#entities/mapEffect'
|
||||
import { MapEventTile } from '#entities/mapEventTile'
|
||||
import { MapEventTileTeleport } from '#entities/mapEventTileTeleport'
|
||||
import { MapObject } from '#entities/mapObject'
|
||||
import mapManager from '#managers/mapManager'
|
||||
import MapRepository from '#repositories/mapRepository'
|
||||
import { PlacedMapObject } from '#entities/placedMapObject'
|
||||
|
||||
interface IPayload {
|
||||
mapId: UUID
|
||||
@ -31,12 +31,12 @@ interface IPayload {
|
||||
effect: string
|
||||
strength: number
|
||||
}[]
|
||||
mapObjects: MapObject[]
|
||||
placedMapObjects: PlacedMapObject[]
|
||||
}
|
||||
|
||||
export default class MapUpdateEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('gm:map_editor:map:update', this.handleEvent.bind(this))
|
||||
this.socket.on('gm:map:update', this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: IPayload, callback: (response: Map | null) => void): Promise<void> {
|
||||
@ -70,11 +70,11 @@ export default class MapUpdateEvent extends BaseEvent {
|
||||
|
||||
data.mapEventTiles = data.mapEventTiles.filter((tile) => tile.positionX >= 0 && tile.positionX < data.width && tile.positionY >= 0 && tile.positionY < data.height)
|
||||
|
||||
data.mapObjects = data.mapObjects.filter((obj) => obj.positionX >= 0 && obj.positionX < data.width && obj.positionY >= 0 && obj.positionY < data.height)
|
||||
data.placedMapObjects = data.placedMapObjects.filter((obj) => obj.positionX >= 0 && obj.positionX < data.width && obj.positionY >= 0 && obj.positionY < data.height)
|
||||
|
||||
// Clear existing collections
|
||||
map.mapEventTiles.removeAll()
|
||||
map.mapObjects.removeAll()
|
||||
map.placedMapObjects.removeAll()
|
||||
map.mapEffects.removeAll()
|
||||
|
||||
// Create and add new map event tiles
|
||||
@ -95,16 +95,14 @@ export default class MapUpdateEvent extends BaseEvent {
|
||||
}
|
||||
|
||||
// Create and add new map objects
|
||||
for (const object of data.mapObjects) {
|
||||
const mapObject = new MapObject().setMapObject(object.mapObject).setDepth(object.depth).setIsRotated(object.isRotated).setPositionX(object.positionX).setPositionY(object.positionY).setMap(map)
|
||||
|
||||
map.mapObjects.add(mapObject)
|
||||
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).setMap(map)
|
||||
map.placedMapObjects.add(mapObject)
|
||||
}
|
||||
|
||||
// Create and add new map effects
|
||||
for (const effect of data.mapEffects) {
|
||||
const mapEffect = new MapEffect().setEffect(effect.effect).setStrength(effect.strength).setMap(map)
|
||||
|
||||
map.mapEffects.add(mapEffect)
|
||||
}
|
||||
|
||||
@ -125,7 +123,7 @@ export default class MapUpdateEvent extends BaseEvent {
|
||||
|
||||
return callback(map)
|
||||
} catch (error: any) {
|
||||
this.logger.error(`gm:map_editor:map:update error: ${error instanceof Error ? error.message : String(error)}`)
|
||||
this.logger.error(`gm:mapObject:update error: ${error instanceof Error ? error.message : String(error)}`)
|
||||
return callback(null)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user