Map editor teleport enhancements
This commit is contained in:
parent
f3e0d6e03a
commit
b173a993f7
@ -11,7 +11,7 @@ export class BaseMap extends BaseEntity {
|
|||||||
id = randomUUID()
|
id = randomUUID()
|
||||||
|
|
||||||
@Property()
|
@Property()
|
||||||
name!: string
|
name: string = ''
|
||||||
|
|
||||||
@Property()
|
@Property()
|
||||||
width = 10
|
width = 10
|
||||||
@ -19,7 +19,7 @@ export class BaseMap extends BaseEntity {
|
|||||||
@Property()
|
@Property()
|
||||||
height = 10
|
height = 10
|
||||||
|
|
||||||
@Property({ type: 'json', nullable: true })
|
@Property({ type: 'json' })
|
||||||
tiles: Array<Array<string>> = []
|
tiles: Array<Array<string>> = []
|
||||||
|
|
||||||
@Property()
|
@Property()
|
||||||
|
@ -2,6 +2,7 @@ import { BaseMap } from '@/entities/base/map'
|
|||||||
import { Entity } from '@mikro-orm/core'
|
import { Entity } from '@mikro-orm/core'
|
||||||
|
|
||||||
export type MapCacheT = ReturnType<Map['cache']> | {}
|
export type MapCacheT = ReturnType<Map['cache']> | {}
|
||||||
|
export type MapEditorMapT = ReturnType<Map['mapEditorObject']> | {}
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class Map extends BaseMap {
|
export class Map extends BaseMap {
|
||||||
@ -35,4 +36,42 @@ export class Map extends BaseMap {
|
|||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async mapEditorObject() {
|
||||||
|
try {
|
||||||
|
await this.getPlacedMapObjects().load()
|
||||||
|
await this.getMapEffects().load()
|
||||||
|
await this.getMapEventTiles().load()
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: this.getId(),
|
||||||
|
name: this.getName(),
|
||||||
|
width: this.getWidth(),
|
||||||
|
height: this.getHeight(),
|
||||||
|
tiles: this.getTiles(),
|
||||||
|
pvp: this.getPvp(),
|
||||||
|
createdAt: this.getCreatedAt(),
|
||||||
|
updatedAt: this.getUpdatedAt(),
|
||||||
|
placedMapObjects: this.getPlacedMapObjects(),
|
||||||
|
mapEffects: this.getMapEffects(),
|
||||||
|
mapEventTiles: this.getMapEventTiles().map((mapEventTile) => ({
|
||||||
|
id: mapEventTile.getId(),
|
||||||
|
type: mapEventTile.getType(),
|
||||||
|
positionX: mapEventTile.getPositionX(),
|
||||||
|
positionY: mapEventTile.getPositionY(),
|
||||||
|
teleport: mapEventTile.getTeleport()
|
||||||
|
? {
|
||||||
|
toMap: mapEventTile.getTeleport()?.getToMap().getId(),
|
||||||
|
toPositionX: mapEventTile.getTeleport()?.getToPositionX(),
|
||||||
|
toPositionY: mapEventTile.getTeleport()?.getToPositionY(),
|
||||||
|
toRotation: mapEventTile.getTeleport()?.getToRotation()
|
||||||
|
}
|
||||||
|
: undefined
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { BaseEvent } from '@/application/base/baseEvent'
|
import { BaseEvent } from '@/application/base/baseEvent'
|
||||||
import { SocketEvent } from '@/application/enums'
|
import { SocketEvent } from '@/application/enums'
|
||||||
import type { UUID } from '@/application/types'
|
import type { UUID } from '@/application/types'
|
||||||
import { Map } from '@/entities/map'
|
import { type MapEditorMapT } from '@/entities/map'
|
||||||
import MapRepository from '@/repositories/mapRepository'
|
import MapRepository from '@/repositories/mapRepository'
|
||||||
|
|
||||||
interface IPayload {
|
interface IPayload {
|
||||||
@ -13,7 +13,7 @@ export default class MapRequestEvent extends BaseEvent {
|
|||||||
this.socket.on(SocketEvent.GM_MAP_REQUEST, this.handleEvent.bind(this))
|
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 {
|
try {
|
||||||
if (!(await this.isCharacterGM())) return
|
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)
|
await mapRepository.getEntityManager().populate(map, mapRepository.POPULATE_MAP_EDITOR as any)
|
||||||
|
|
||||||
// Remove map.mapEventTiles.teleport.toMap and add map.mapEventTiles.teleport.toMapId
|
return callback(await map.mapEditorObject())
|
||||||
|
|
||||||
return callback(map)
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.logger.error('gm:map:request error', error.message)
|
this.logger.error('gm:map:request error', error.message)
|
||||||
return callback(null)
|
return callback(null)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { BaseEvent } from '@/application/base/baseEvent'
|
import { BaseEvent } from '@/application/base/baseEvent'
|
||||||
import { MapEventTileType, SocketEvent } from '@/application/enums'
|
import { MapEventTileType, SocketEvent } from '@/application/enums'
|
||||||
import type { UUID } from '@/application/types'
|
import type { UUID } from '@/application/types'
|
||||||
import { Map } from '@/entities/map'
|
import { type MapEditorMapT } from '@/entities/map'
|
||||||
import { MapEffect } from '@/entities/mapEffect'
|
import { MapEffect } from '@/entities/mapEffect'
|
||||||
import { MapEventTile } from '@/entities/mapEventTile'
|
import { MapEventTile } from '@/entities/mapEventTile'
|
||||||
import { MapEventTileTeleport } from '@/entities/mapEventTileTeleport'
|
import { MapEventTileTeleport } from '@/entities/mapEventTileTeleport'
|
||||||
@ -21,7 +21,7 @@ interface IPayload {
|
|||||||
positionX: number
|
positionX: number
|
||||||
positionY: number
|
positionY: number
|
||||||
teleport?: {
|
teleport?: {
|
||||||
toMapId: string
|
toMap: string
|
||||||
toPositionX: number
|
toPositionX: number
|
||||||
toPositionY: number
|
toPositionY: number
|
||||||
toRotation: number
|
toRotation: number
|
||||||
@ -36,7 +36,7 @@ export default class MapUpdateEvent extends BaseEvent {
|
|||||||
this.socket.on(SocketEvent.GM_MAP_UPDATE, this.handleEvent.bind(this))
|
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 {
|
try {
|
||||||
if (!(await this.isCharacterGM())) return
|
if (!(await this.isCharacterGM())) return
|
||||||
|
|
||||||
@ -80,17 +80,17 @@ export default class MapUpdateEvent extends BaseEvent {
|
|||||||
map.getMapEffects().removeAll()
|
map.getMapEffects().removeAll()
|
||||||
|
|
||||||
// Create and add new map event tiles
|
// Create and add new map event tiles
|
||||||
for (const tile of data.mapEventTiles) {
|
for (const eventTile of data.mapEventTiles) {
|
||||||
const mapEventTile = new MapEventTile().setType(tile.type).setPositionX(tile.positionX).setPositionY(tile.positionY).setMap(map)
|
const mapEventTile = new MapEventTile().setMap(map).setType(eventTile.type).setPositionX(eventTile.positionX).setPositionY(eventTile.positionY)
|
||||||
if (tile.teleport) {
|
if (eventTile.teleport) {
|
||||||
const toMap = await mapRepository.getById(tile.teleport.toMapId as UUID)
|
const toMap = await mapRepository.getById(eventTile.teleport.toMap as UUID)
|
||||||
if (!toMap) continue
|
if (!toMap) continue
|
||||||
const teleport = new MapEventTileTeleport()
|
const teleport = new MapEventTileTeleport()
|
||||||
.setMapEventTile(mapEventTile)
|
.setMapEventTile(mapEventTile)
|
||||||
.setToMap(toMap)
|
.setToMap(toMap)
|
||||||
.setToPositionX(tile.teleport.toPositionX)
|
.setToPositionX(eventTile.teleport.toPositionX)
|
||||||
.setToPositionY(tile.teleport.toPositionY)
|
.setToPositionY(eventTile.teleport.toPositionY)
|
||||||
.setToRotation(tile.teleport.toRotation)
|
.setToRotation(eventTile.teleport.toRotation)
|
||||||
|
|
||||||
mapEventTile.setTeleport(teleport)
|
mapEventTile.setTeleport(teleport)
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ export default class MapUpdateEvent extends BaseEvent {
|
|||||||
mapManager.unloadMap(data.mapId)
|
mapManager.unloadMap(data.mapId)
|
||||||
await mapManager.loadMap(map)
|
await mapManager.loadMap(map)
|
||||||
|
|
||||||
return callback(map)
|
return callback(await map.mapEditorObject())
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.emitError(`gm:map:update error: ${error instanceof Error ? error.message + error.stack : String(error)}`)
|
this.emitError(`gm:map:update error: ${error instanceof Error ? error.message + error.stack : String(error)}`)
|
||||||
return callback(null)
|
return callback(null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user