refactor: 合并英雄与怪物的生命周期系统为统一系统
移除 MonLifecycleSystem,将其功能整合至 HeroLifecycleSystem 并重命名为 BattleEntityLifecycleSystem。新系统根据实体的 fac 属性区分英雄与怪物,输出相应的调试日志,消除了重复代码并提高了维护性。
This commit is contained in:
@@ -7,7 +7,6 @@ import { HeroInfo } from "../common/config/heroSet";
|
||||
import { HeroAttrsComp } from "./HeroAttrsComp";
|
||||
import { HeroViewComp } from "./HeroViewComp";
|
||||
import { MoveComp } from "./MoveComp";
|
||||
import { mLogger } from "../common/Logger";
|
||||
/** 怪物实体:负责怪物对象池复用、属性初始化、入场动画与回收 */
|
||||
@ecs.register(`Monster`)
|
||||
export class Monster extends ecs.Entity {
|
||||
@@ -226,35 +225,3 @@ export class Monster extends ecs.Entity {
|
||||
}
|
||||
|
||||
}
|
||||
/** 怪物生命周期系统:监听实体进入与移除并输出调试日志 */
|
||||
@ecs.register('MonLifecycleSystem')
|
||||
export class MonLifecycleSystem extends ecs.ComblockSystem
|
||||
implements ecs.IEntityEnterSystem, ecs.IEntityRemoveSystem {
|
||||
/** 调试开关,控制系统日志输出 */
|
||||
debugMode: boolean = false;
|
||||
|
||||
/** 仅处理拥有 MoveComp 的实体 */
|
||||
filter() {
|
||||
return ecs.allOf(MoveComp);
|
||||
}
|
||||
|
||||
/** 实体进入世界时记录日志 */
|
||||
entityEnter(e: ecs.Entity): void {
|
||||
const heroAttrs = e.get(HeroAttrsComp);
|
||||
if (heroAttrs) {
|
||||
mLogger.log(this.debugMode, 'MonLifecycleSystem', `怪物进入世界: ${heroAttrs.hero_name}`);
|
||||
} else {
|
||||
mLogger.log(this.debugMode, 'MonLifecycleSystem', `怪物进入世界: 实体ID ${e.eid}`);
|
||||
}
|
||||
}
|
||||
|
||||
/** 实体离开世界时记录日志 */
|
||||
entityRemove(e: ecs.Entity): void {
|
||||
const heroAttrs = e.get(HeroAttrsComp);
|
||||
if (heroAttrs) {
|
||||
mLogger.log(this.debugMode, 'MonLifecycleSystem', `怪物离开世界: ${heroAttrs.hero_name}`);
|
||||
} else {
|
||||
mLogger.log(this.debugMode, 'MonLifecycleSystem', `怪物离开世界: 实体ID ${e.eid}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user