Map editor teleport enhancements

This commit is contained in:
2025-02-16 21:18:01 +01:00
parent f3e0d6e03a
commit b173a993f7
4 changed files with 55 additions and 18 deletions

View File

@ -2,6 +2,7 @@ import { BaseMap } from '@/entities/base/map'
import { Entity } from '@mikro-orm/core'
export type MapCacheT = ReturnType<Map['cache']> | {}
export type MapEditorMapT = ReturnType<Map['mapEditorObject']> | {}
@Entity()
export class Map extends BaseMap {
@ -35,4 +36,42 @@ export class Map extends BaseMap {
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 {}
}
}
}