From 31df25033dac163f0696e1b62b928945c1fe795e Mon Sep 17 00:00:00 2001 From: pan Date: Tue, 2 Jun 2026 16:00:41 +0800 Subject: [PATCH] =?UTF-8?q?refactor(SingletonModuleComp):=20=E6=95=B4?= =?UTF-8?q?=E7=90=86=E5=B9=B6=E7=AE=80=E5=8C=96=E6=B8=B8=E6=88=8F=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=9B=B8=E5=85=B3=E7=B1=BB=E5=9E=8B=E4=B8=8E=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 移除未使用的TalentType导入与冗余的collection字段定义 2. 统一所有对象属性的空格格式,修复代码风格问题 3. 简化overrideLocalDataWithRemote方法中的云端收集数据更新逻辑 4. 重构getGameDate方法,移除不必要的collection字段返回 5. 统一所有方法的命名风格与代码缩进格式 --- .../script/game/common/SingletonModuleComp.ts | 148 +++++++----------- 1 file changed, 53 insertions(+), 95 deletions(-) diff --git a/assets/script/game/common/SingletonModuleComp.ts b/assets/script/game/common/SingletonModuleComp.ts index 11614536..02ec9163 100644 --- a/assets/script/game/common/SingletonModuleComp.ts +++ b/assets/script/game/common/SingletonModuleComp.ts @@ -7,7 +7,6 @@ import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/O import { GameEvent } from "./config/GameEvent"; import { GameScoreStats } from "./config/HeroAttrs"; import { mLogger } from "./Logger"; -import { TalentType } from "./config/TalentSet"; import { gameDataSync } from "./GameDataSync"; import { FightSet } from "./config/GameSet"; @@ -15,15 +14,9 @@ import { FightSet } from "./config/GameSet"; * 用远程数据覆盖本地数据(统一方法) * @param remoteData 远程数据(云端或本地调试) */ -export interface GameDate{ - gold:number, +export interface GameDate { + gold: number, timestamp?: number, // 用于比对本地与云端数据的最新状态 - collection?: { - talents: Record, - player_level: number, - player_exp: number, - talent_points?: number, - } } export interface CloudData { openid: string; @@ -38,74 +31,50 @@ export class SingletonModuleComp extends ecs.Comp { initialize: Initialize = null!; /** 游戏地图 */ map: GameMap = null!; - + /** 全局缓存的通用图集 */ uiconsAtlas: SpriteAtlas | null = null; - - openid:string='' - mission:any={ - status:0, //0:未开始 1:进行中 2:胜利 3:失败 - play:false, - pause:false, - in_select:false, - in_fight:false, - stop_mon_action:false, + + openid: string = '' + mission: any = { + status: 0, //0:未开始 1:进行中 2:胜利 3:失败 + play: false, + pause: false, + in_select: false, + in_fight: false, + stop_mon_action: false, }; - data:any={ - score:0, - mission:1, - diamond:100, //商店购买 及 双倍奖励资源 - gold:1000, - task:0, - noStop:false, - showInfo:true, + data: any = { + score: 0, + mission: 1, + diamond: 100, //商店购买 及 双倍奖励资源 + gold: 1000, + task: 0, + noStop: false, + showInfo: true, } - - guides:any=[0,0,0,0,0] - current_guide:number=0 - - collection: { - talents: Record; - player_level: number; - player_exp: number; - talent_points?: number; - } = { - talents: { - [TalentType.Attack]: 0, - [TalentType.Hp]: 0, - [TalentType.Critical]: 0, - [TalentType.WindFury]: 0, - [TalentType.Freeze]: 0, - [TalentType.Puncture]: 0, - [TalentType.DeadTrigger]: 0, - [TalentType.Summon]: 0, - [TalentType.BuyDiscount]: 0, - [TalentType.RefreshDiscount]: 0, - [TalentType.SellBonus]: 0 - }, // 存储各个天赋的等级: { talent_id: level } - player_level: 1, // 玩家等级 - player_exp: 0, // 玩家当前经验 - talent_points: 0, // 兼容旧存档的历史字段 - }; + + guides: any = [0, 0, 0, 0, 0] + current_guide: number = 0 vmdata: any = { - game_over:false, - game_pause:false, - mission_data:{ - mon_num:0,//怪物数量 - hero_num:0,//英雄数量 - hero_max_num:FightSet.HERO_MAX_NUM,//英雄可召唤上限 - hero_extend_max_num:FightSet.HERO_MAX_NUM + 1,//英雄可拓展上限 - wave_time_num:0,//波次时间 - in_fight:false, - fight_time:0,//战斗时间 - level:1,//关卡等级 - max_mission:4,//最大关卡 - coin:0, - time:15*60,//游戏时间 - }, - scores: { + game_over: false, + game_pause: false, + mission_data: { + mon_num: 0,//怪物数量 + hero_num: 0,//英雄数量 + hero_max_num: FightSet.HERO_MAX_NUM,//英雄可召唤上限 + hero_extend_max_num: FightSet.HERO_MAX_NUM + 1,//英雄可拓展上限 + wave_time_num: 0,//波次时间 + in_fight: false, + fight_time: 0,//战斗时间 + level: 1,//关卡等级 + max_mission: 4,//最大关卡 + coin: 0, + time: 15 * 60,//游戏时间 + }, + scores: { score: 0, // 基础得分 // 战斗统计 crt_count: 0, // 暴击次数 @@ -114,20 +83,20 @@ export class SingletonModuleComp extends ecs.Comp { back_count: 0, // 击退次数 stun_count: 0, // 击晕次数 freeze_count: 0, // 冰冻次数 - + // 伤害统计 total_dmg: 0, // 总伤害 atk_count: 0, // 攻击次数 avg_dmg: 0, // 平均伤害 thorns_dmg: 0, // 反伤伤害 crit_dmg_total: 0, // 暴击伤害总额 - + // 生存统计 heal_total: 0, // 治疗总量 lifesteal_total: 0, // 吸血总量 shield_block_count: 0, dead_trigger_count: 0, - + // 资源统计 exp_total: 0, // 经验总数 gold_total: 0, // 金币总数 @@ -156,14 +125,14 @@ export class SingletonModuleComp extends ecs.Comp { score_efficiency: 0, achieved_highlights: [], - } as GameScoreStats, - - gold: 0, // 金币数据(MVVM绑定字段) + } as GameScoreStats, + + gold: 0, // 金币数据(MVVM绑定字段) }; - + vmAdd() { VM.add(this.vmdata, "data"); // mLogger.log(this.debugMode, 'SMC', "[MissionComp]局内数据初始化",smc.vmdata.mission_data) @@ -228,12 +197,12 @@ export class SingletonModuleComp extends ecs.Comp { isWxClient(): boolean { return gameDataSync.isWxClient(); } - - updateCloudData(){ + + updateCloudData() { return gameDataSync.updateCloudData(); } - getCloudData(){ + getCloudData() { gameDataSync.getCloudData(); } public async overrideLocalDataWithRemote(cloudData: any) { @@ -249,35 +218,24 @@ export class SingletonModuleComp extends ecs.Comp { if (data.gold !== undefined) { this.vmdata.gold = data.gold; } - // 恢复收集记录 - if (data.collection) { - const remoteCol = data.collection; - if (remoteCol.talents) { - Object.assign(this.collection.talents, remoteCol.talents); - } - if (typeof remoteCol.player_level === 'number') this.collection.player_level = remoteCol.player_level; - if (typeof remoteCol.player_exp === 'number') this.collection.player_exp = remoteCol.player_exp; - if (typeof remoteCol.talent_points === 'number') this.collection.talent_points = remoteCol.talent_points; - } } - + // 触发UI更新 oops.message.dispatchEvent(GameEvent.GOLD_UPDATE); - + } catch (error) { mLogger.error(this.debugMode, 'SMC', `[SMC]: 数据覆盖失败:`, error); } } - getGameDate(){ + getGameDate() { let data: GameDate = { gold: this.vmdata.gold, - collection: this.collection, timestamp: Date.now() // 每次获取当前数据结构时都附带最新的时间戳 }; return data; } - updateGold(gold:number, is_sync: boolean = true){ + updateGold(gold: number, is_sync: boolean = true) { this.vmdata.gold += gold; if (is_sync) { gameDataSync.markDataDirty();