import { BaseMap } from '@/entities/base/map' import { Entity } from '@mikro-orm/core' export type MapCacheT = ReturnType | {} export type MapEditorMapT = ReturnType | {} @Entity() export class Map extends BaseMap { public async cache() { try { await this.getPlacedMapObjects().load() await this.getMapEffects().load() return { id: this.getId(), name: this.getName(), width: this.getWidth(), height: this.getHeight(), tiles: this.getTiles(), pvp: this.getPvp(), updatedAt: this.getUpdatedAt(), placedMapObjects: this.getPlacedMapObjects().map((placedMapObject) => ({ id: placedMapObject.getId(), mapObject: placedMapObject.getMapObject().getId(), isRotated: placedMapObject.getIsRotated(), positionX: placedMapObject.getPositionX(), positionY: placedMapObject.getPositionY() })), mapEffects: this.getMapEffects().map((mapEffect) => ({ effect: mapEffect.getEffect(), strength: mapEffect.getStrength() })) } } catch (error) { console.error(error) 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 {} } } }