diff --git a/assets/script/game/common/SingletonModuleComp.ts b/assets/script/game/common/SingletonModuleComp.ts index 02ec9163..ab723803 100644 --- a/assets/script/game/common/SingletonModuleComp.ts +++ b/assets/script/game/common/SingletonModuleComp.ts @@ -7,6 +7,7 @@ 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"; @@ -17,6 +18,12 @@ import { FightSet } from "./config/GameSet"; export interface GameDate { gold: number, timestamp?: number, // 用于比对本地与云端数据的最新状态 + collection?: { + talents: Record, + player_level: number, + player_exp: number, + talent_points?: number, + } } export interface CloudData { openid: string; @@ -58,6 +65,30 @@ export class SingletonModuleComp extends ecs.Comp { 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, // 兼容旧存档的历史字段 + }; + vmdata: any = { game_over: false, game_pause: false, @@ -218,6 +249,16 @@ 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更新 @@ -230,6 +271,7 @@ export class SingletonModuleComp extends ecs.Comp { getGameDate() { let data: GameDate = { gold: this.vmdata.gold, + collection: this.collection, timestamp: Date.now() // 每次获取当前数据结构时都附带最新的时间戳 }; return data;