refactor: 重命名Logger类并增加错误日志方法

- 将Logger类重命名为mLogger以符合命名规范
- 新增error方法用于统一错误输出
- 在多个组件中替换console.log/warn/error为mLogger的对应方法
- 为多个组件添加debugMode属性以控制模块级日志开关
- 新增HeroMasterComp组件框架
This commit is contained in:
panw
2026-02-03 14:40:02 +08:00
parent 859ab3bc2a
commit 63dd22fb88
16 changed files with 215 additions and 117 deletions

View File

@@ -7,7 +7,10 @@ import { HeroInfo, AttrSet } from "../common/config/heroSet";
import { HeroSkillsComp } from "./HeroSkills";
import { smc } from "../common/SingletonModuleComp";
import { AttrCards, PotionCards } from "../common/config/AttrSet";
import { mLogger } from "../common/Logger";
import { _decorator } from "cc";
const { property } = _decorator;
interface talTrigger{
value:number
@@ -15,6 +18,9 @@ interface talTrigger{
}
@ecs.register('HeroAttrs')
export class HeroAttrsComp extends ecs.Comp {
@property({ tooltip: "是否启用调试日志" })
public debugMode: boolean = false;
Ebus:any=null!
// ==================== 角色基础信息 ====================
hero_uuid: number = 1001;
@@ -95,7 +101,7 @@ export class HeroAttrsComp extends ecs.Comp {
const uuid = args;
const attrCard = AttrCards[uuid];
if (attrCard) {
console.log(`[HeroAttrs] 使用属性卡: ${attrCard.desc}`);
mLogger.log(this.debugMode, 'HeroAttrs', `[HeroAttrs] 使用属性卡: ${attrCard.desc}`);
// 构造 BuffConf默认使用 BType.VALUE永久生效 (time: 0)
const buffConf: BuffConf = {
buff: attrCard.attr,
@@ -117,7 +123,7 @@ export class HeroAttrsComp extends ecs.Comp {
// 1. 尝试从 PotionCards 获取 (新版药水)
const potion = PotionCards[itemId];
if (potion) {
console.log(`[HeroAttrs] 使用药水: ${potion.desc}`);
mLogger.log(this.debugMode, 'HeroAttrs', `[HeroAttrs] 使用药水: ${potion.desc}`);
const buffConf: BuffConf = {
buff: potion.attr,
value: potion.value,
@@ -140,7 +146,7 @@ export class HeroAttrsComp extends ecs.Comp {
const newLv = args.lv;
if (newLv > this.lv) {
console.log(`[HeroAttrs] 英雄升级处理: Lv.${this.lv} -> Lv.${newLv}`);
mLogger.log(this.debugMode, 'HeroAttrs', `[HeroAttrs] 英雄升级处理: Lv.${this.lv} -> Lv.${newLv}`);
this.lv = newLv;
// === 属性成长逻辑 (示例: 固定数值成长) ===
@@ -249,7 +255,7 @@ export class HeroAttrsComp extends ecs.Comp {
this.hp = Math.max(0, Math.min(this.hp, this.Attrs[Attrs.HP_MAX]));
this.dirty_hp = true; // ✅ 仅标记需要更新
smc.updateHeroInfo(this);
// console.log(`[HeroAttrs] HP变更: ${this.hero_name}, 变化=${addValue.toFixed(1)}, ${oldHp.toFixed(1)} -> ${this.hp.toFixed(1)}`);
mLogger.log(this.debugMode, 'HeroAttrs', `[HeroAttrs] HP变更: ${this.hero_name}, 变化=${addValue.toFixed(1)}, ${oldHp.toFixed(1)} -> ${this.hp.toFixed(1)}`);
}
add_mp(value:number,isValue:boolean){
const oldMp = this.mp;
@@ -267,7 +273,7 @@ export class HeroAttrsComp extends ecs.Comp {
this.mp += addValue;
this.mp = Math.max(0, Math.min(this.mp, this.Attrs[Attrs.MP_MAX]));
this.dirty_mp = true; // ✅ 仅标记需要更新
console.log(`[HeroAttrs] MP变更: ${this.hero_name}, 变化=${addValue.toFixed(1)}, ${oldMp.toFixed(1)} -> ${this.mp.toFixed(1)}`);
mLogger.log(this.debugMode, 'HeroAttrs', `[HeroAttrs] MP变更: ${this.hero_name}, 变化=${addValue.toFixed(1)}, ${oldMp.toFixed(1)} -> ${this.mp.toFixed(1)}`);
}
add_shield(value:number,isValue:boolean){
const oldShield = this.shield;
@@ -392,7 +398,7 @@ export class HeroAttrsComp extends ecs.Comp {
const [val, count] = smc.global_attrs[attrIndex];
const globalAdd = val * count;
totalRatio += globalAdd;
// console.log(`[HeroAttrs] 全局加成: ${this.hero_name} Attr=${attrIndex} Val=${val} Count=${count} Add=${globalAdd}%`);
// mLogger.log(this.debugMode, 'HeroAttrs', `[HeroAttrs] 全局加成: ${this.hero_name} Attr=${attrIndex} Val=${val} Count=${count} Add=${globalAdd}%`);
}
// 4. 根据属性类型计算最终值
@@ -411,7 +417,7 @@ export class HeroAttrsComp extends ecs.Comp {
this.clampSingleAttr(attrIndex);
if (oldVal !== this.Attrs[attrIndex]) {
console.log(`[HeroAttrs] 属性重算: ${this.hero_name}, 属性ID=${attrIndex}, ${oldVal} -> ${this.Attrs[attrIndex]} (Base=${baseVal}, Add=${totalValue-baseVal}, Ratio=${totalRatio}%)`);
mLogger.log(this.debugMode, 'HeroAttrs', `[HeroAttrs] 属性重算: ${this.hero_name}, 属性ID=${attrIndex}, ${oldVal} -> ${this.Attrs[attrIndex]} (Base=${baseVal}, Add=${totalValue-baseVal}, Ratio=${totalRatio}%)`);
}
}