import { Entity } from '@mikro-orm/core' import { BaseMap } from '#entities/base/map' export type MapCacheT = 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 {} } } }