forked from noxious/server
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { Entity } from '@mikro-orm/core'
|
|
|
|
import { BaseMap } from '#entities/base/map'
|
|
|
|
export type MapCacheT = ReturnType<Map['cache']> | {}
|
|
|
|
@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 {}
|
|
}
|
|
}
|
|
}
|