From 6043963c18a00e1a9f92504760c6c55621102556 Mon Sep 17 00:00:00 2001 From: panw Date: Tue, 3 Feb 2026 16:27:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B0=86=E8=B0=83=E8=AF=95=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E4=BB=8Econsole.log=E6=9B=BF=E6=8D=A2=E4=B8=BAmLogger?= =?UTF-8?q?=E5=B9=B6=E9=BB=98=E8=AE=A4=E5=85=B3=E9=97=AD=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在MissionCardComp中默认关闭调试模式 - 在MissionHomeComp、Mon、HeroAttrsSystem和HInfoComp中引入mLogger - 使用debugMode控制日志输出,避免生产环境产生过多console日志 --- assets/script/game/hero/HeroAttrsSystem.ts | 9 ++++---- assets/script/game/hero/Mon.ts | 9 ++++---- assets/script/game/map/HInfoComp.ts | 25 +++++++++++++++------- assets/script/game/map/MissionCardComp.ts | 2 +- assets/script/game/map/MissionHomeComp.ts | 5 ++++- 5 files changed, 32 insertions(+), 18 deletions(-) diff --git a/assets/script/game/hero/HeroAttrsSystem.ts b/assets/script/game/hero/HeroAttrsSystem.ts index 7f128158..ac7766aa 100644 --- a/assets/script/game/hero/HeroAttrsSystem.ts +++ b/assets/script/game/hero/HeroAttrsSystem.ts @@ -5,6 +5,7 @@ import { Attrs } from "../common/config/HeroAttrs"; import { HeroUpSet } from "../common/config/heroSet"; import { HeroSkillsComp } from "./HeroSkills"; import { HeroAttrsComp } from "./HeroAttrsComp"; +import { mLogger } from "../common/Logger"; /** * ==================== 英雄属性更新系统 ==================== * @@ -44,14 +45,14 @@ export class HeroAttrSystem extends ecs.ComblockSystem const model = e.get(HeroAttrsComp); if (!model) return; - console.log(`[HeroAttrSystem] 英雄进入系统: ${model.hero_name} (uuid: ${model.hero_uuid})`); + mLogger.log(this.debugMode, 'HeroAttrSystem', `[HeroAttrSystem] 英雄进入系统: ${model.hero_name} (uuid: ${model.hero_uuid})`); } /** * 系统首次更新前调用(整个系统只调用一次) */ firstUpdate(): void { - console.log("[HeroAttrSystem] 系统首次更新"); + mLogger.log(this.debugMode, 'HeroAttrSystem', "[HeroAttrSystem] 系统首次更新"); } /** @@ -73,7 +74,7 @@ export class HeroAttrSystem extends ecs.ComblockSystem // 调试日志(可选,调试时启用) if (this.debugMode) { - console.log(` [${this.entityCount}] 更新英雄: ${model.hero_name}, HP: ${model.hp.toFixed(2)}`); + mLogger.log(this.debugMode, 'HeroAttrSystem', ` [${this.entityCount}] 更新英雄: ${model.hero_name}, HP: ${model.hp.toFixed(2)}`); } // 1. 更新临时 Buff/Debuff(时间递减,过期自动移除) @@ -106,7 +107,7 @@ export class HeroAttrSystem extends ecs.ComblockSystem // 每 60 帧输出一次统计 this.frameCount++; if (this.frameCount % 60 === 0 && this.entityCount === 1) { - console.log(`[HeroAttrSystem] 第 ${this.frameCount} 帧,处理 ${this.entityCount} 个英雄`); + mLogger.log(this.debugMode, 'HeroAttrSystem', `[HeroAttrSystem] 第 ${this.frameCount} 帧,处理 ${this.entityCount} 个英雄`); } // 注意:显示更新由 HeroViewComp 负责,这里只处理数据 diff --git a/assets/script/game/hero/Mon.ts b/assets/script/game/hero/Mon.ts index 7c00f700..52820458 100644 --- a/assets/script/game/hero/Mon.ts +++ b/assets/script/game/hero/Mon.ts @@ -11,6 +11,7 @@ import { getMonAttr, MonType } from "../map/RogueConfig"; import { HeroViewComp } from "./HeroViewComp"; import { HeroSkillsComp } from "./HeroSkills"; import { MonMoveComp } from "./MonMove"; +import { mLogger } from "../common/Logger"; /** 角色实体 */ @ecs.register(`Monster`) export class Monster extends ecs.Entity { @@ -166,9 +167,9 @@ export class MonLifecycleSystem extends ecs.ComblockSystem // 怪物实体创建时的特殊处理 const heroAttrs = e.get(HeroAttrsComp); if (heroAttrs) { - console.log(`怪物进入世界: ${heroAttrs.hero_name}`); + mLogger.log(heroAttrs.debugMode, 'MonLifecycleSystem', `怪物进入世界: ${heroAttrs.hero_name}`); } else { - console.log(`怪物进入世界: 实体ID ${e.eid}`); + mLogger.log(heroAttrs.debugMode, 'MonLifecycleSystem', `怪物进入世界: 实体ID ${e.eid}`); } } @@ -176,9 +177,9 @@ export class MonLifecycleSystem extends ecs.ComblockSystem // 怪物实体销毁时的清理工作 const heroAttrs = e.get(HeroAttrsComp); if (heroAttrs) { - console.log(`怪物离开世界: ${heroAttrs.hero_name}`); + mLogger.log(heroAttrs.debugMode, 'MonLifecycleSystem', `怪物离开世界: ${heroAttrs.hero_name}`); } else { - console.log(`怪物离开世界: 实体ID ${e.eid}`); + mLogger.log(heroAttrs.debugMode, 'MonLifecycleSystem', `怪物离开世界: 实体ID ${e.eid}`); } } } \ No newline at end of file diff --git a/assets/script/game/map/HInfoComp.ts b/assets/script/game/map/HInfoComp.ts index 8b869eab..f71d60bb 100644 --- a/assets/script/game/map/HInfoComp.ts +++ b/assets/script/game/map/HInfoComp.ts @@ -6,11 +6,14 @@ import { GameEvent } from '../common/config/GameEvent'; import { CCComp } from 'db://oops-framework/module/common/CCComp'; import { ecs } from 'db://oops-framework/libs/ecs/ECS'; import { SkillSet } from '../common/config/SkillSet'; +import { mLogger } from '../common/Logger'; const { ccclass, property } = _decorator; @ccclass('HInfoComp') @ecs.register('HInfoComp', false) export class HInfoComp extends CCComp { + debugMode: boolean = false; + h_uuid:number=0 private uiconsAtlas: SpriteAtlas | null = null; name_node:any=null @@ -116,15 +119,15 @@ export class HInfoComp extends CCComp { */ private updateSkillIcon(node: Node, iconId: string) { if (!node || !iconId) return; - console.log("iconId",iconId) + mLogger.log(this.debugMode, 'HInfoComp', "iconId",iconId) const iconNode = node.getChildByName("icon"); - console.log("iconNode",iconNode) + mLogger.log(this.debugMode, 'HInfoComp', "iconNode",iconNode) if (!iconNode) return; const sprite = iconNode.getComponent(Sprite); - console.log("sprite",sprite) + mLogger.log(this.debugMode, 'HInfoComp', "sprite",sprite) if (!sprite) return; if (this.uiconsAtlas) { - console.log("this.uiconsAtlas",this.uiconsAtlas) + mLogger.log(this.debugMode, 'HInfoComp', "this.uiconsAtlas",this.uiconsAtlas) const frame = this.uiconsAtlas.getSpriteFrame(iconId); if (frame) { sprite.spriteFrame = frame; @@ -133,11 +136,11 @@ export class HInfoComp extends CCComp { // 加载图集 resources.load("gui/uicons", SpriteAtlas, (err, atlas) => { if (err) { - console.error("[HInfoComp] Failed to load uicons atlas", err); + mLogger.log(this.debugMode, 'HInfoComp', "[HInfoComp] Failed to load uicons atlas", err); return; } this.uiconsAtlas = atlas; - console.log("atlas",atlas) + mLogger.log(this.debugMode, 'HInfoComp', "atlas",atlas) const frame = atlas.getSpriteFrame(iconId); if (frame) { sprite.spriteFrame = frame; @@ -207,7 +210,7 @@ export class HInfoComp extends CCComp { animComponent.play("idle"); } } else { - console.error(`[HInfoComp]: Failed to load animation for hero ${uuid}`, err); + mLogger.log(this.debugMode, 'HInfoComp', `[HInfoComp]: Failed to load animation for hero ${uuid}`, err); } }); @@ -291,7 +294,7 @@ export class HInfoComp extends CCComp { this.node.getChildByName("ranks").active=false } buy_hero(){ - console.info("[HInfoComp]:buy_hero",this.h_uuid) + mLogger.log(this.debugMode, 'HInfoComp', "[HInfoComp]:buy_hero",this.h_uuid) if(smc.vmdata.gold < HeroConf.COST) { oops.gui.toast("金币不足") return @@ -302,6 +305,7 @@ export class HInfoComp extends CCComp { this.close_buy() } start_mission() { + mLogger.log(this.debugMode, 'HInfoComp', "[HInfoComp]:start_mission") oops.message.dispatchEvent(GameEvent.MissionStart, {}) this.node.active=false; } @@ -315,6 +319,7 @@ export class HInfoComp extends CCComp { this.isMoving = true; // 在动画开始前,直接销毁hero_pos[6]上的节点 + mLogger.log(this.debugMode, 'HInfoComp', "hero_pos[6]",this.hero_pos[6]) if (this.heroNodes[6]) { this.heroNodes[6].destroy(); this.heroNodes[6] = null; @@ -323,6 +328,7 @@ export class HInfoComp extends CCComp { // 移动所有现有节点向左(除了已销毁的heroNodes[6]) for (let i = 0; i < 6; i++) { if (this.heroNodes[i]) { + mLogger.log(this.debugMode, 'HInfoComp', "i",i) // 计算目标位置:向左移动 let targetPos = this.hero_pos[i + 1]; @@ -339,11 +345,13 @@ export class HInfoComp extends CCComp { this.moveTimeoutId = setTimeout(() => { // 移动数组元素(向后平移) for (let i = 6; i > 0; i--) { + mLogger.log(this.debugMode, 'HInfoComp', "i",i) this.heroNodes[i] = this.heroNodes[i - 1]; } // 创建新节点放在hero_pos[0]位置 let heros = getHeroList(); + mLogger.log(this.debugMode, 'HInfoComp', "heros",heros) let currentIndex = heros.indexOf(this.h_uuid); let newIndex = currentIndex - 3; // 新的最左侧英雄索引 @@ -356,6 +364,7 @@ export class HInfoComp extends CCComp { // 确保新创建的节点使用正确的缩放值 if (this.heroNodes[0]) { + mLogger.log(this.debugMode, 'HInfoComp', "this.heroNodes[0]",this.heroNodes[0]) this.heroNodes[0].setScale(this.getHeroScale(0)); } diff --git a/assets/script/game/map/MissionCardComp.ts b/assets/script/game/map/MissionCardComp.ts index 6013342c..9cdfd87a 100644 --- a/assets/script/game/map/MissionCardComp.ts +++ b/assets/script/game/map/MissionCardComp.ts @@ -29,7 +29,7 @@ interface ICardEvent { @ecs.register('MissionCard', false) export class MissionCardComp extends CCComp { @property({ tooltip: "是否启用调试日志" }) - private debugMode: boolean = true; + private debugMode: boolean = false; /** 视图层逻辑代码分离演示 */ @property(Node) diff --git a/assets/script/game/map/MissionHomeComp.ts b/assets/script/game/map/MissionHomeComp.ts index 2b413a1b..e06190cb 100644 --- a/assets/script/game/map/MissionHomeComp.ts +++ b/assets/script/game/map/MissionHomeComp.ts @@ -5,6 +5,7 @@ import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/O import { smc } from "../common/SingletonModuleComp"; import { GameEvent } from "../common/config/GameEvent"; import { Timer } from "db://oops-framework/core/common/timer/Timer"; +import { mLogger } from "../common/Logger"; const { ccclass, property } = _decorator; @@ -12,6 +13,8 @@ const { ccclass, property } = _decorator; @ccclass('MissionHomeComp') @ecs.register('MissionHome', false) export class MissionHomeComp extends CCComp { + debugMode: boolean = false; + protected onLoad(): void { this.on(GameEvent.MissionEnd,this.mission_end,this) this.on(GameEvent.MissionStart,this.mission_start,this) @@ -29,7 +32,7 @@ export class MissionHomeComp extends CCComp { mission_end(){ - console.log("[MissionHomeComp]=>mission_end") + mLogger.log(this.debugMode, 'MissionHomeComp', "[MissionHomeComp]=>mission_end") this.home_active() } mission_start(){