refactor(hero): 移除视图层直接更新逻辑,使用脏标签机制
- 在HeroViewComp中移除hp_show和mp_show的直接调用 - 在HeroAttrsComp中不再直接调用视图层方法 - 使用脏标签机制(dirty flag)来触发UI更新
This commit is contained in:
@@ -3,7 +3,6 @@ import { Attrs, AttrsType, BType, NeAttrs } from "../common/config/HeroAttrs";
|
||||
import { BuffConf } from "../common/config/SkillSet";
|
||||
import { HeroInfo, AttrSet } from "../common/config/heroSet";
|
||||
import { HeroSkillsComp } from "./HeroSkills";
|
||||
import { HeroViewComp } from "./HeroViewComp";
|
||||
|
||||
|
||||
interface talTrigger{
|
||||
@@ -127,26 +126,32 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
if(!isValue){
|
||||
addValue = value * this.Attrs[Attrs.HP_MAX] / 100;
|
||||
}
|
||||
let heroView = this.ent.get(HeroViewComp);
|
||||
if(heroView){
|
||||
heroView.health(addValue);
|
||||
}
|
||||
|
||||
// ✅ 数据层只负责数据修改,不调用视图层
|
||||
// let heroView = this.ent.get(HeroViewComp);
|
||||
// if(heroView){
|
||||
// heroView.health(addValue);
|
||||
// }
|
||||
|
||||
this.hp += addValue;
|
||||
this.hp = Math.max(0, Math.min(this.hp, this.Attrs[Attrs.HP_MAX]));
|
||||
this.dirty_hp = true; // 标记血量需要更新
|
||||
this.dirty_hp = true; // ✅ 仅标记需要更新
|
||||
}
|
||||
add_mp(value:number,isValue:boolean){
|
||||
let addValue = value;
|
||||
if(!isValue){
|
||||
addValue = value * this.Attrs[Attrs.MP_MAX] / 100;
|
||||
}
|
||||
let heroView = this.ent.get(HeroViewComp);
|
||||
if(heroView){
|
||||
heroView.mp_add(addValue);
|
||||
}
|
||||
|
||||
// ✅ 数据层只负责数据修改,不调用视图层
|
||||
// let heroView = this.ent.get(HeroViewComp);
|
||||
// if(heroView){
|
||||
// heroView.mp_add(addValue);
|
||||
// }
|
||||
|
||||
this.mp += addValue;
|
||||
this.mp = Math.max(0, Math.min(this.mp, this.Attrs[Attrs.MP_MAX]));
|
||||
this.dirty_mp = true; // 标记魔法值需要更新
|
||||
this.dirty_mp = true; // ✅ 仅标记需要更新
|
||||
}
|
||||
add_shield(value:number,isValue:boolean){
|
||||
let addValue = value;
|
||||
|
||||
@@ -312,17 +312,22 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
|
||||
health(hp: number = 0) {
|
||||
// 生命值更新由 Model 层处理,这里只负责视图表现
|
||||
// ✅ 仅显示特效和提示,不调用 hp_show()
|
||||
this.heathed();
|
||||
this.hp_tip(TooltipTypes.health, hp.toFixed(0));
|
||||
this.top_node.active=true
|
||||
this.hp_show();
|
||||
this.top_node.active = true;
|
||||
|
||||
// ❌ 移除:UI更新由脏标签机制处理
|
||||
// this.hp_show();
|
||||
}
|
||||
|
||||
mp_add(mp: number = 0) {
|
||||
// 生命值更新由 Model 层处理,这里只负责视图表现
|
||||
// ✅ 仅显示提示,不调用 mp_show()
|
||||
this.hp_tip(TooltipTypes.addmp, mp.toFixed(0));
|
||||
this.top_node.active=true
|
||||
this.mp_show();
|
||||
this.top_node.active = true;
|
||||
|
||||
// ❌ 移除:UI更新由脏标签机制处理
|
||||
// this.mp_show();
|
||||
}
|
||||
|
||||
alive(){
|
||||
|
||||
Reference in New Issue
Block a user