refactor: 重命名Logger类并增加错误日志方法
- 将Logger类重命名为mLogger以符合命名规范 - 新增error方法用于统一错误输出 - 在多个组件中替换console.log/warn/error为mLogger的对应方法 - 为多个组件添加debugMode属性以控制模块级日志开关 - 新增HeroMasterComp组件框架
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
export class Logger {
|
||||
export class mLogger {
|
||||
/** 总开关:控制所有日志输出 */
|
||||
public static GLOBAL_ENABLED: boolean = true;
|
||||
|
||||
@@ -25,4 +25,16 @@ export class Logger {
|
||||
console.warn(`[${tag}]`, ...args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一错误输出
|
||||
* @param enable 单独开关(模块级开关)
|
||||
* @param tag 标签(通常是类名或模块名)
|
||||
* @param args 错误内容
|
||||
*/
|
||||
public static error(enable: boolean, tag: string, ...args: any[]) {
|
||||
if (this.GLOBAL_ENABLED && enable) {
|
||||
console.error(`[${tag}]`, ...args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import { Attrs, GameScoreStats } from "./config/HeroAttrs";
|
||||
import { count, time } from "console";
|
||||
import { getLevelExp } from "../map/RogueConfig";
|
||||
import { FightSet } from "./config/GameSet";
|
||||
import { mLogger } from "./Logger";
|
||||
/**
|
||||
* 用远程数据覆盖本地数据(统一方法)
|
||||
* @param remoteData 远程数据(云端或本地调试)
|
||||
@@ -32,6 +33,8 @@ interface CloudData {
|
||||
/** 游戏模块 */
|
||||
@ecs.register('SingletonModule')
|
||||
export class SingletonModuleComp extends ecs.Comp {
|
||||
private debugMode: boolean = false;
|
||||
|
||||
/** 游戏初始化模块 */
|
||||
initialize: Initialize = null!;
|
||||
/** 游戏地图 */
|
||||
@@ -165,7 +168,7 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
this.vmdata.collection.talents[id] = 0;
|
||||
}
|
||||
this.vmdata.collection.talents[id]++;
|
||||
console.log(`[SMC] 记录天赋获取: ID=${id}, 次数=${this.vmdata.collection.talents[id]}`);
|
||||
mLogger.log(this.debugMode, 'SMC', `[SMC] 记录天赋获取: ID=${id}, 次数=${this.vmdata.collection.talents[id]}`);
|
||||
oops.message.dispatchEvent(GameEvent.UpdateCollection);
|
||||
}
|
||||
|
||||
@@ -178,7 +181,7 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
this.vmdata.collection.skill.uuid = id;
|
||||
}
|
||||
this.vmdata.collection.skill.count++;
|
||||
console.log(`[SMC] 记录技能获取: ID=${id}, 次数=${this.vmdata.collection.skill.count}`);
|
||||
mLogger.log(this.debugMode, 'SMC', `[SMC] 记录技能获取: ID=${id}, 次数=${this.vmdata.collection.skill.count}`);
|
||||
oops.message.dispatchEvent(GameEvent.UpdateCollection);
|
||||
}
|
||||
/**
|
||||
@@ -190,7 +193,7 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
this.vmdata.collection.friend.uuid = id;
|
||||
}
|
||||
this.vmdata.collection.friend.count++;
|
||||
console.log(`[SMC] 记录好友获取: ID=${id}, 次数=${this.vmdata.collection.friend.count}`);
|
||||
mLogger.log(this.debugMode, 'SMC', `[SMC] 记录好友获取: ID=${id}, 次数=${this.vmdata.collection.friend.count}`);
|
||||
oops.message.dispatchEvent(GameEvent.UpdateCollection);
|
||||
}
|
||||
|
||||
@@ -219,7 +222,7 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
// 更新下一级所需经验
|
||||
h.exp_max = getLevelExp(h.lv);
|
||||
|
||||
console.log(`[SMC] 升级! Lv.${h.lv - 1} -> Lv.${h.lv}, 下级所需: ${h.exp_max}`);
|
||||
mLogger.log(this.debugMode, 'SMC', `[SMC] 升级! Lv.${h.lv - 1} -> Lv.${h.lv}, 下级所需: ${h.exp_max}`);
|
||||
}
|
||||
|
||||
if (isLevelUp) {
|
||||
@@ -230,6 +233,7 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
|
||||
vmAdd() {
|
||||
VM.add(this.vmdata, "data");
|
||||
// mLogger.log(this.debugMode, 'SMC', "[MissionComp]局内数据初始化",smc.vmdata.mission_data)
|
||||
}
|
||||
reset() {
|
||||
for (var key in this.vmdata) {
|
||||
@@ -256,16 +260,16 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
|
||||
let gemeDate=this.getGameDate()
|
||||
WxCloudApi.save(gemeDate).then((result) => {
|
||||
console.log('云端保存')
|
||||
mLogger.log(this.debugMode, 'SMC', '云端保存')
|
||||
if(result.result.code === 200) {
|
||||
console.log("保存成功",result.result)
|
||||
mLogger.log(this.debugMode, 'SMC', "保存成功",result.result)
|
||||
return true
|
||||
} else {
|
||||
console.warn(`[SMC]: 游戏数据增加失败: ${result.result.msg}`);
|
||||
mLogger.warn(this.debugMode, 'SMC', `[SMC]: 游戏数据增加失败: ${result.result.msg}`);
|
||||
return false
|
||||
}
|
||||
}).catch((error) => {
|
||||
console.error(`[SMC]: 增加游戏数据异常:`, error);
|
||||
mLogger.error(this.debugMode, 'SMC', `[SMC]: 增加游戏数据异常:`, error);
|
||||
return false
|
||||
});
|
||||
return true
|
||||
@@ -274,15 +278,15 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
WxCloudApi.get().then(async (result) => {
|
||||
if(result.result.code === 200) {
|
||||
let data=result.result.data
|
||||
console.log(`[SMC]: 获取游戏数据成功:`, result.result);
|
||||
mLogger.log(this.debugMode, 'SMC', `[SMC]: 获取游戏数据成功:`, result.result);
|
||||
this.overrideLocalDataWithRemote(data)
|
||||
return true
|
||||
} else {
|
||||
console.warn(`[SMC]: 游戏数据增加失败`);
|
||||
mLogger.warn(this.debugMode, 'SMC', `[SMC]: 游戏数据增加失败`);
|
||||
return false
|
||||
}
|
||||
}).catch((error) => {
|
||||
console.error(`[SMC]: 获取游戏数据异常:`, error);
|
||||
mLogger.error(this.debugMode, 'SMC', `[SMC]: 获取游戏数据异常:`, error);
|
||||
});
|
||||
}
|
||||
public async overrideLocalDataWithRemote(CloudData) {
|
||||
@@ -303,7 +307,7 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error(`[SMC]: 数据覆盖失败:`, error);
|
||||
mLogger.error(this.debugMode, 'SMC', `[SMC]: 数据覆盖失败:`, error);
|
||||
}
|
||||
}
|
||||
getGameDate(){
|
||||
|
||||
Reference in New Issue
Block a user