import { ITileRawData, shouldReplay } from '@user/data-common'; import { IDynamicTile, IMapLayer, IStaticBlockSave, IStaticTile } from './types'; import { MapTileBase } from './tile'; export class StaticTile extends MapTileBase implements IStaticTile { constructor(x: number, y: number, layer: IMapLayer) { super(x, y, layer); this.restoreDefaultEvents(); } num(): number { return this.layer.getBlock(this.locator.x, this.locator.y); } raw(): ITileRawData | null { return this.state.tileStore.getData(this.num()); } @shouldReplay('Setting static tile num should be replayed.') set(num: number): void { this.layer.setBlock(num, this.locator.x, this.locator.y); this.restoreDefaultEvents(); } @shouldReplay('Transfering static tile to dynamic should be replayed.') toDynamic(): IDynamicTile { return this.layer.transferToDynamic(this.locator.x, this.locator.y)!; } shouldSave(): boolean { const eventView = this.tileEvent(); return eventView.dirty(); } saveState(): Readonly { const eventView = this.tileEvent(); if (eventView.dirty()) { return { events: new Map(eventView.get()) }; } else { return {}; } } loadState(save: Readonly): void { this.restoreDefaultEvents(); if (save.events) { const eventView = this.tileEvent(); eventView.clear(); for (const [priority, id] of save.events) { eventView.set(priority, id); } } } }