import { IEnemy, IReadonlyEnemy } from '../enemy'; import { IEnemyView, IEnemyContext } from './types'; export class EnemyView implements IEnemyView { /** 计算后怪物 */ private readonly computedEnemy: IEnemy; constructor( readonly baseEnemy: IEnemy, readonly context: IEnemyContext ) { this.computedEnemy = baseEnemy.clone(); } reset(): void { this.computedEnemy.copyFrom(this.baseEnemy); } getBaseEnemy(): IReadonlyEnemy { return this.baseEnemy; } getComputedEnemy(): IReadonlyEnemy { this.context.requestRefresh(this); return this.computedEnemy; } /** * 获取计算中怪物对象,这个接口不对外暴露,仅在系统内部的 EnemyContext 中使用。 */ getComputingEnemy(): IEnemy { return this.computedEnemy; } getModifiableEnemy(): IEnemy { return this.baseEnemy; } markDirty(): void { this.context.markDirty(this); } }