feat(英雄组件): 重构HeroAttrsComp解耦数据与表现层
- 移除HeroAttrsComp中对HeroViewComp的直接依赖,改为脏标签机制 - HeroViewComp改为在update中检查脏标签按需更新UI - 优化护盾显示逻辑,即使top_node不活跃也更新状态 - 消除双重UI更新,提升性能
This commit is contained in:
@@ -102,6 +102,7 @@ export class HeroViewComp extends CCComp {
|
||||
/* 显示角色血*/
|
||||
this.top_node.getChildByName("hp").active = true;
|
||||
this.top_node.getChildByName("mp").active = true;
|
||||
this.top_node.getChildByName("shield").active = false;
|
||||
// 初始隐藏血条(被攻击后才显示)
|
||||
this.top_node.active = true;
|
||||
|
||||
@@ -169,14 +170,26 @@ export class HeroViewComp extends CCComp {
|
||||
|
||||
/** 显示护盾 */
|
||||
private show_shield(shield: number = 0, shield_max: number = 0) {
|
||||
if(!this.top_node.active) return
|
||||
let shield_progress = shield / shield_max;
|
||||
this.node.getChildByName("shielded").active = shield > 0;
|
||||
this.top_node.getChildByName("shield").active = shield > 0;
|
||||
this.top_node.getChildByName("shield").getComponent(ProgressBar).progress = shield_progress;
|
||||
this.scheduleOnce(() => {
|
||||
this.top_node.getChildByName("shield").getChildByName("pb").getComponent(ProgressBar).progress = shield_progress;
|
||||
}, 0.15);
|
||||
// ✅ 即使 top_node 不活跃,也要更新护盾的显示状态
|
||||
// 当护盾为0时,隐藏护盾UI
|
||||
const hasShield = shield > 0 && shield_max > 0;
|
||||
|
||||
this.node.getChildByName("shielded").active = hasShield;
|
||||
|
||||
// 如果 top_node 活跃,才更新护盾进度条
|
||||
if (this.top_node) {
|
||||
this.top_node.getChildByName("shield").active = hasShield;
|
||||
|
||||
if (hasShield) {
|
||||
let shield_progress = shield / shield_max;
|
||||
this.top_node.getChildByName("shield").getComponent(ProgressBar).progress = shield_progress;
|
||||
this.scheduleOnce(() => {
|
||||
if (this.top_node && this.top_node.isValid) {
|
||||
this.top_node.getChildByName("shield").getChildByName("pb").getComponent(ProgressBar).progress = shield_progress;
|
||||
}
|
||||
}, 0.15);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 显示血量 */
|
||||
|
||||
@@ -1,15 +1,41 @@
|
||||
1. [待评估] HeroAttrsComp 架构问题:数据层与表现层耦合
|
||||
1. [已完成] HeroAttrsComp 架构问题:数据层与表现层耦合
|
||||
|
||||
- 位置:assets/script/game/hero/HeroAttrsComp.ts 的 add_hp、add_mp
|
||||
- 问题:属性组件中直接通过 this.ent.get(HeroViewComp) 更新视图,
|
||||
数据层与表现层强耦合,不利于复用(例如无头战斗逻辑)。
|
||||
|
||||
- TODO:后续根据整体架构再决定是否重构,方向预留如下:
|
||||
- ✅ 已完成:
|
||||
- 移除 HeroAttrsComp 中对 HeroViewComp 的直接依赖,仅维护数值;
|
||||
- 使用事件或 System 把 hp/mp 变更同步给视图组件;
|
||||
- 保证 HeroAttrsComp 只处理战斗数值逻辑,不直接操作表现层。
|
||||
- 实现脏标签机制,数据层只负责设置脏标签,视图层在update中检查并更新;
|
||||
- 保证 HeroAttrsComp 只处理战斗数值逻辑,不直接操作表现层。
|
||||
|
||||
2. [问题] SkillSet 目标组枚举命名与注释语义不一致
|
||||
- 具体修改:
|
||||
- HeroAttrsComp.ts: add_hp/add_mp/add_shield 只设置脏标签,不调用视图层
|
||||
- HeroViewComp.ts: health/mp_add 只显示特效,不调用 hp_show/mp_show
|
||||
- HeroViewComp.ts: update() 中通过脏标签按需更新UI
|
||||
- 优化效果:消除双重UI更新,实现真正的按需更新,提升性能
|
||||
|
||||
2. [待实现] SACastSystem 扩展治疗/护盾技能支持
|
||||
|
||||
- 位置:assets/script/game/hero/SACastSystem.ts
|
||||
- 现状:只支持 SType.damage (伤害技能),缺少 SType.heal/shield 等辅助技能处理
|
||||
- 待实现功能:
|
||||
- 在 executeCast() 中添加技能类型判断分支
|
||||
- 实现 executeHealSkill() 方法:治疗技能逻辑
|
||||
- 根据技能配置的治疗量修改目标HP
|
||||
- 触发治疗特效(通过 HeroViewComp.health())
|
||||
- 数据层已支持,只需调用 add_hp() + 触发特效
|
||||
- 实现 executeShieldSkill() 方法:护盾技能逻辑
|
||||
- 根据技能配置的护盾量修改目标护盾值
|
||||
- 触发护盾特效(通过 HeroViewComp.add_shield())
|
||||
- 数据层已支持,只需调用 add_shield() + 触发特效
|
||||
- 实现 findEntityAtPosition() 辅助方法:根据位置查找目标实体
|
||||
- 注意事项:
|
||||
- SkillSet 中暂时没有治疗/护盾技能配置,等配置就绪后实现
|
||||
- 目标选择逻辑需根据实际设计实现(血量最低友军/随机友军等)
|
||||
- 治疗量/护盾量需从技能配置读取,当前使用占位值
|
||||
|
||||
3. [问题] SkillSet 目标组枚举命名与注释语义不一致
|
||||
|
||||
- 位置:assets/script/game/common/config/SkillSet.ts 的 TGroup
|
||||
- 现状:Ally/Team 的注释与字面含义相反,容易导致配置选错目标阵营。
|
||||
|
||||
Reference in New Issue
Block a user