refactor(game): 将玩家收集数据移出vmdata以优化结构
将 collection 对象从 vmdata 中移出,作为 SingletonModuleComp 的直接属性。这消除了不必要的嵌套层级,使数据访问更直接,并提高了代码可读性。同时更新了 TalentsComp 中所有相关引用,确保功能一致性。
This commit is contained in:
@@ -61,6 +61,19 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
current_guide:number=0
|
||||
fight_hero: number = 5001; // 单个出战英雄
|
||||
heros:any= [5001]
|
||||
|
||||
collection: {
|
||||
talents: Record<number, number>;
|
||||
player_level: number;
|
||||
player_exp: number;
|
||||
talent_points: number;
|
||||
} = {
|
||||
talents: {}, // 存储各个天赋的等级: { talent_id: level }
|
||||
player_level: 1, // 玩家等级
|
||||
player_exp: 0, // 玩家当前经验
|
||||
talent_points: 0, // 当前可用天赋点
|
||||
};
|
||||
|
||||
vmdata: any = {
|
||||
game_over:false,
|
||||
game_pause:false,
|
||||
@@ -131,13 +144,6 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
} as GameScoreStats,
|
||||
|
||||
gold: 0, // 金币数据(MVVM绑定字段)
|
||||
|
||||
collection: {
|
||||
talents: {}, // 存储各个天赋的等级: { talent_id: level }
|
||||
player_level: 1, // 玩家等级
|
||||
player_exp: 0, // 玩家当前经验
|
||||
talent_points: 0, // 当前可用天赋点
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -260,7 +266,7 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
if(CloudData.data.fight_hero) this.fight_hero=CloudData.data.fight_hero
|
||||
// 恢复收集记录
|
||||
if(CloudData.data.collection) {
|
||||
this.vmdata.collection = CloudData.data.collection;
|
||||
this.collection = CloudData.data.collection;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,7 +279,7 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
gold:this.vmdata.gold,
|
||||
heros:this.heros,
|
||||
fight_hero:this.fight_hero,
|
||||
collection: this.vmdata.collection
|
||||
collection: this.collection
|
||||
}
|
||||
}
|
||||
addHero(hero_uuid:number){
|
||||
|
||||
Reference in New Issue
Block a user