refactor(SingletonModuleComp): 整理并简化游戏数据相关类型与初始化代码
1. 移除未使用的TalentType导入与冗余的collection字段定义 2. 统一所有对象属性的空格格式,修复代码风格问题 3. 简化overrideLocalDataWithRemote方法中的云端收集数据更新逻辑 4. 重构getGameDate方法,移除不必要的collection字段返回 5. 统一所有方法的命名风格与代码缩进格式
This commit is contained in:
@@ -7,7 +7,6 @@ import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/O
|
|||||||
import { GameEvent } from "./config/GameEvent";
|
import { GameEvent } from "./config/GameEvent";
|
||||||
import { GameScoreStats } from "./config/HeroAttrs";
|
import { GameScoreStats } from "./config/HeroAttrs";
|
||||||
import { mLogger } from "./Logger";
|
import { mLogger } from "./Logger";
|
||||||
import { TalentType } from "./config/TalentSet";
|
|
||||||
import { gameDataSync } from "./GameDataSync";
|
import { gameDataSync } from "./GameDataSync";
|
||||||
import { FightSet } from "./config/GameSet";
|
import { FightSet } from "./config/GameSet";
|
||||||
|
|
||||||
@@ -18,12 +17,6 @@ import { FightSet } from "./config/GameSet";
|
|||||||
export interface GameDate {
|
export interface GameDate {
|
||||||
gold: number,
|
gold: number,
|
||||||
timestamp?: number, // 用于比对本地与云端数据的最新状态
|
timestamp?: number, // 用于比对本地与云端数据的最新状态
|
||||||
collection?: {
|
|
||||||
talents: Record<TalentType, number>,
|
|
||||||
player_level: number,
|
|
||||||
player_exp: number,
|
|
||||||
talent_points?: number,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
export interface CloudData {
|
export interface CloudData {
|
||||||
openid: string;
|
openid: string;
|
||||||
@@ -65,30 +58,6 @@ export class SingletonModuleComp extends ecs.Comp {
|
|||||||
guides: any = [0, 0, 0, 0, 0]
|
guides: any = [0, 0, 0, 0, 0]
|
||||||
current_guide: number = 0
|
current_guide: number = 0
|
||||||
|
|
||||||
collection: {
|
|
||||||
talents: Record<TalentType, number>;
|
|
||||||
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 = {
|
vmdata: any = {
|
||||||
game_over: false,
|
game_over: false,
|
||||||
game_pause: false,
|
game_pause: false,
|
||||||
@@ -249,16 +218,6 @@ export class SingletonModuleComp extends ecs.Comp {
|
|||||||
if (data.gold !== undefined) {
|
if (data.gold !== undefined) {
|
||||||
this.vmdata.gold = data.gold;
|
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更新
|
// 触发UI更新
|
||||||
@@ -271,7 +230,6 @@ export class SingletonModuleComp extends ecs.Comp {
|
|||||||
getGameDate() {
|
getGameDate() {
|
||||||
let data: GameDate = {
|
let data: GameDate = {
|
||||||
gold: this.vmdata.gold,
|
gold: this.vmdata.gold,
|
||||||
collection: this.collection,
|
|
||||||
timestamp: Date.now() // 每次获取当前数据结构时都附带最新的时间戳
|
timestamp: Date.now() // 每次获取当前数据结构时都附带最新的时间戳
|
||||||
};
|
};
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
Reference in New Issue
Block a user