forked from noxious/server
Map editor teleport enhancements
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import type { UUID } from '@/application/types'
|
||||
import { Map } from '@/entities/map'
|
||||
import { type MapEditorMapT } from '@/entities/map'
|
||||
import MapRepository from '@/repositories/mapRepository'
|
||||
|
||||
interface IPayload {
|
||||
@ -13,7 +13,7 @@ export default class MapRequestEvent extends BaseEvent {
|
||||
this.socket.on(SocketEvent.GM_MAP_REQUEST, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: IPayload, callback: (response: Map | null) => void): Promise<void> {
|
||||
private async handleEvent(data: IPayload, callback: (response: MapEditorMapT | null) => void): Promise<void> {
|
||||
try {
|
||||
if (!(await this.isCharacterGM())) return
|
||||
|
||||
@ -34,9 +34,7 @@ export default class MapRequestEvent extends BaseEvent {
|
||||
|
||||
await mapRepository.getEntityManager().populate(map, mapRepository.POPULATE_MAP_EDITOR as any)
|
||||
|
||||
// Remove map.mapEventTiles.teleport.toMap and add map.mapEventTiles.teleport.toMapId
|
||||
|
||||
return callback(map)
|
||||
return callback(await map.mapEditorObject())
|
||||
} catch (error: any) {
|
||||
this.logger.error('gm:map:request error', error.message)
|
||||
return callback(null)
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { MapEventTileType, SocketEvent } from '@/application/enums'
|
||||
import type { UUID } from '@/application/types'
|
||||
import { Map } from '@/entities/map'
|
||||
import { type MapEditorMapT } from '@/entities/map'
|
||||
import { MapEffect } from '@/entities/mapEffect'
|
||||
import { MapEventTile } from '@/entities/mapEventTile'
|
||||
import { MapEventTileTeleport } from '@/entities/mapEventTileTeleport'
|
||||
@ -21,7 +21,7 @@ interface IPayload {
|
||||
positionX: number
|
||||
positionY: number
|
||||
teleport?: {
|
||||
toMapId: string
|
||||
toMap: string
|
||||
toPositionX: number
|
||||
toPositionY: number
|
||||
toRotation: number
|
||||
@ -36,7 +36,7 @@ export default class MapUpdateEvent extends BaseEvent {
|
||||
this.socket.on(SocketEvent.GM_MAP_UPDATE, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: IPayload, callback: (response: Map | null) => void): Promise<void> {
|
||||
private async handleEvent(data: IPayload, callback: (response: MapEditorMapT | null) => void): Promise<void> {
|
||||
try {
|
||||
if (!(await this.isCharacterGM())) return
|
||||
|
||||
@ -80,17 +80,17 @@ export default class MapUpdateEvent extends BaseEvent {
|
||||
map.getMapEffects().removeAll()
|
||||
|
||||
// Create and add new map event tiles
|
||||
for (const tile of data.mapEventTiles) {
|
||||
const mapEventTile = new MapEventTile().setType(tile.type).setPositionX(tile.positionX).setPositionY(tile.positionY).setMap(map)
|
||||
if (tile.teleport) {
|
||||
const toMap = await mapRepository.getById(tile.teleport.toMapId as UUID)
|
||||
for (const eventTile of data.mapEventTiles) {
|
||||
const mapEventTile = new MapEventTile().setMap(map).setType(eventTile.type).setPositionX(eventTile.positionX).setPositionY(eventTile.positionY)
|
||||
if (eventTile.teleport) {
|
||||
const toMap = await mapRepository.getById(eventTile.teleport.toMap as UUID)
|
||||
if (!toMap) continue
|
||||
const teleport = new MapEventTileTeleport()
|
||||
.setMapEventTile(mapEventTile)
|
||||
.setToMap(toMap)
|
||||
.setToPositionX(tile.teleport.toPositionX)
|
||||
.setToPositionY(tile.teleport.toPositionY)
|
||||
.setToRotation(tile.teleport.toRotation)
|
||||
.setToPositionX(eventTile.teleport.toPositionX)
|
||||
.setToPositionY(eventTile.teleport.toPositionY)
|
||||
.setToRotation(eventTile.teleport.toRotation)
|
||||
|
||||
mapEventTile.setTeleport(teleport)
|
||||
}
|
||||
@ -128,7 +128,7 @@ export default class MapUpdateEvent extends BaseEvent {
|
||||
mapManager.unloadMap(data.mapId)
|
||||
await mapManager.loadMap(map)
|
||||
|
||||
return callback(map)
|
||||
return callback(await map.mapEditorObject())
|
||||
} catch (error: any) {
|
||||
this.emitError(`gm:map:update error: ${error instanceof Error ? error.message + error.stack : String(error)}`)
|
||||
return callback(null)
|
||||
|
Reference in New Issue
Block a user