refactor: 重命名Logger类并增加错误日志方法
- 将Logger类重命名为mLogger以符合命名规范 - 新增error方法用于统一错误输出 - 在多个组件中替换console.log/warn/error为mLogger的对应方法 - 为多个组件添加debugMode属性以控制模块级日志开关 - 新增HeroMasterComp组件框架
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { mLogger } from "../common/Logger";
|
||||
import { _decorator, Label, Node, tween, Vec3, Color, Sprite, Tween, SpriteAtlas, resources } from "cc";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
||||
@@ -24,6 +25,9 @@ interface ICardEvent {
|
||||
@ccclass('MissionCardComp')
|
||||
@ecs.register('MissionCard', false)
|
||||
export class MissionCardComp extends CCComp {
|
||||
@property({ tooltip: "是否启用调试日志" })
|
||||
private debugMode: boolean = false;
|
||||
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
@property(Node)
|
||||
card1:Node = null!
|
||||
@@ -376,7 +380,7 @@ export class MissionCardComp extends CCComp {
|
||||
// 加载图集
|
||||
resources.load("gui/uicons", SpriteAtlas, (err, atlas) => {
|
||||
if (err) {
|
||||
console.error("[MissionCardComp] Failed to load uicons atlas", err);
|
||||
mLogger.error(this.debugMode, 'MissionCard', "[MissionCardComp] Failed to load uicons atlas", err);
|
||||
return;
|
||||
}
|
||||
this.uiconsAtlas = atlas;
|
||||
@@ -395,7 +399,7 @@ export class MissionCardComp extends CCComp {
|
||||
}
|
||||
|
||||
selectCard(e: any, index: string) {
|
||||
console.log("selectCard", index)
|
||||
mLogger.log(this.debugMode, 'MissionCard', "selectCard", index)
|
||||
let _index = parseInt(index);
|
||||
// 如果已经选择过,则不再处理
|
||||
if (this.hasSelected) return;
|
||||
@@ -406,7 +410,7 @@ export class MissionCardComp extends CCComp {
|
||||
|
||||
if (selectedData && selectedCardNode) {
|
||||
this.hasSelected = true;
|
||||
console.log("选择卡片:", selectedData.name, "类型:", selectedData.type);
|
||||
mLogger.log(this.debugMode, 'MissionCard', "选择卡片:", selectedData.name, "类型:", selectedData.type);
|
||||
|
||||
// 未选中的卡片缩小
|
||||
const cards = [this.card1, this.card2, this.card3, this.card4];
|
||||
@@ -432,7 +436,24 @@ export class MissionCardComp extends CCComp {
|
||||
.call(() => {
|
||||
// 根据类型直接操作 smc.role (如果是主角)
|
||||
// 确保只影响主角,避免广播事件导致所有实体生效
|
||||
const role = smc.role;
|
||||
let role = smc.role;
|
||||
|
||||
// 容错处理:如果 smc.role 为空,尝试通过 ECS 查询查找主角
|
||||
if (!role) {
|
||||
console.warn("[MissionCard] smc.role 为空,尝试查找主角实体...");
|
||||
// @ts-ignore
|
||||
const entities = ecs.query(ecs.allOf(HeroAttrsComp));
|
||||
for (const e of entities) {
|
||||
const attrs = e.get(HeroAttrsComp);
|
||||
if (attrs && attrs.is_master) {
|
||||
role = e;
|
||||
smc.role = e; // 修复 smc.role 引用
|
||||
console.log("[MissionCard] 成功找回主角实体并修复 smc.role");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (role) {
|
||||
switch (selectedData.type) {
|
||||
case CardType.Talent:
|
||||
@@ -441,10 +462,10 @@ export class MissionCardComp extends CCComp {
|
||||
const talComp = role.get(TalComp);
|
||||
if (talComp) {
|
||||
const beforeCount = Object.keys(talComp.Tals).length;
|
||||
console.log(`[MissionCard] Talent Before: Count=${beforeCount}`);
|
||||
mLogger.log(this.debugMode, 'MissionCard', `[MissionCard] Talent Before: Count=${beforeCount}`);
|
||||
talComp.addTal(selectedData.uuid);
|
||||
const afterCount = Object.keys(talComp.Tals).length;
|
||||
console.log(`[MissionCard] Talent After: Count=${afterCount}, Added=${selectedData.uuid}`);
|
||||
mLogger.log(this.debugMode, 'MissionCard', `[MissionCard] Talent After: Count=${afterCount}, Added=${selectedData.uuid}`);
|
||||
}
|
||||
break;
|
||||
case CardType.Skill:
|
||||
@@ -453,10 +474,10 @@ export class MissionCardComp extends CCComp {
|
||||
const skillComp = role.get(HeroSkillsComp);
|
||||
if (skillComp) {
|
||||
const beforeCount = Object.keys(skillComp.skills).length;
|
||||
console.log(`[MissionCard] Skill Before: Count=${beforeCount}`);
|
||||
mLogger.log(this.debugMode, 'MissionCard', `[MissionCard] Skill Before: Count=${beforeCount}`);
|
||||
skillComp.addSkill(selectedData.uuid);
|
||||
const afterCount = Object.keys(skillComp.skills).length;
|
||||
console.log(`[MissionCard] Skill After: Count=${afterCount}, Added=${selectedData.uuid}`);
|
||||
mLogger.log(this.debugMode, 'MissionCard', `[MissionCard] Skill After: Count=${afterCount}, Added=${selectedData.uuid}`);
|
||||
}
|
||||
break;
|
||||
case CardType.Partner:
|
||||
@@ -470,7 +491,7 @@ export class MissionCardComp extends CCComp {
|
||||
const potion = PotionCards[selectedData.uuid];
|
||||
if (potion) {
|
||||
const beforeVal = attrsComp.Attrs[potion.attr] || 0;
|
||||
console.log(`[MissionCard] Potion Before: Attr[${potion.attr}]=${beforeVal}`);
|
||||
mLogger.log(this.debugMode, 'MissionCard', `[MissionCard] Potion Before: Attr[${potion.attr}]=${beforeVal}`);
|
||||
|
||||
const buffConf: BuffConf = {
|
||||
buff: potion.attr,
|
||||
@@ -482,7 +503,7 @@ export class MissionCardComp extends CCComp {
|
||||
attrsComp.addBuff(buffConf);
|
||||
smc.updateHeroInfo(attrsComp);
|
||||
|
||||
console.log(`[MissionCard] Potion Applied: ${potion.desc}, Value=${potion.value}`);
|
||||
mLogger.log(this.debugMode, 'MissionCard', `[MissionCard] Potion Applied: ${potion.desc}, Value=${potion.value}`);
|
||||
oops.gui.toast(potion.desc);
|
||||
}
|
||||
}
|
||||
@@ -500,7 +521,7 @@ export class MissionCardComp extends CCComp {
|
||||
if (roleAttrs) {
|
||||
roleBefore = roleAttrs.Attrs[attrCard.attr] || 0;
|
||||
}
|
||||
console.log(`[MissionCard] Attr Before: Global=${globalBefore}, Hero=${roleBefore}`);
|
||||
mLogger.log(this.debugMode, 'MissionCard', `[MissionCard] Attr Before: Global=${globalBefore}, Hero=${roleBefore}`);
|
||||
|
||||
if (!smc.global_attrs[attrCard.attr]) {
|
||||
smc.global_attrs[attrCard.attr] = [0, 0];
|
||||
@@ -516,7 +537,7 @@ export class MissionCardComp extends CCComp {
|
||||
smc.updateHeroInfo(attrsComp);
|
||||
|
||||
const roleAfter = attrsComp.Attrs[attrCard.attr] || 0;
|
||||
console.log(`[MissionCard] Attr After: Global=${current[0]}, Hero=${roleAfter}`);
|
||||
mLogger.log(this.debugMode, 'MissionCard', `[MissionCard] Attr After: Global=${current[0]}, Hero=${roleAfter}`);
|
||||
}
|
||||
oops.gui.toast(attrCard.desc);
|
||||
}
|
||||
@@ -542,7 +563,7 @@ export class MissionCardComp extends CCComp {
|
||||
/** 看广告关闭 Lock */
|
||||
watchAdCloseLock() {
|
||||
// TODO: 此处接入 IAA 广告 SDK
|
||||
console.log("播放激励视频广告...");
|
||||
mLogger.log(this.debugMode, 'MissionCard', "播放激励视频广告...");
|
||||
|
||||
// 模拟广告播放成功回调
|
||||
this.isLocked = false;
|
||||
|
||||
Reference in New Issue
Block a user