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
|
current_guide:number=0
|
||||||
fight_hero: number = 5001; // 单个出战英雄
|
fight_hero: number = 5001; // 单个出战英雄
|
||||||
heros:any= [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 = {
|
vmdata: any = {
|
||||||
game_over:false,
|
game_over:false,
|
||||||
game_pause:false,
|
game_pause:false,
|
||||||
@@ -131,13 +144,6 @@ export class SingletonModuleComp extends ecs.Comp {
|
|||||||
} as GameScoreStats,
|
} as GameScoreStats,
|
||||||
|
|
||||||
gold: 0, // 金币数据(MVVM绑定字段)
|
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.fight_hero) this.fight_hero=CloudData.data.fight_hero
|
||||||
// 恢复收集记录
|
// 恢复收集记录
|
||||||
if(CloudData.data.collection) {
|
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,
|
gold:this.vmdata.gold,
|
||||||
heros:this.heros,
|
heros:this.heros,
|
||||||
fight_hero:this.fight_hero,
|
fight_hero:this.fight_hero,
|
||||||
collection: this.vmdata.collection
|
collection: this.collection
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
addHero(hero_uuid:number){
|
addHero(hero_uuid:number){
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ export class TalentsComp extends CCComp {
|
|||||||
|
|
||||||
/** 更新玩家等级、经验、天赋点信息 */
|
/** 更新玩家等级、经验、天赋点信息 */
|
||||||
private updatePlayerInfo() {
|
private updatePlayerInfo() {
|
||||||
const collection = smc.vmdata.collection;
|
const collection = smc.collection;
|
||||||
let level = collection.player_level || 1;
|
let level = collection.player_level || 1;
|
||||||
let exp = collection.player_exp || 0;
|
let exp = collection.player_exp || 0;
|
||||||
let points = collection.talent_points || 0;
|
let points = collection.talent_points || 0;
|
||||||
@@ -137,7 +137,7 @@ export class TalentsComp extends CCComp {
|
|||||||
private updateTalentList() {
|
private updateTalentList() {
|
||||||
if (!this.talents_content || !this.prefab_talent_item) return;
|
if (!this.talents_content || !this.prefab_talent_item) return;
|
||||||
|
|
||||||
const collection = smc.vmdata.collection;
|
const collection = smc.collection;
|
||||||
if (!collection.talents) collection.talents = {};
|
if (!collection.talents) collection.talents = {};
|
||||||
|
|
||||||
// 如果内容为空,则实例化预制体
|
// 如果内容为空,则实例化预制体
|
||||||
@@ -180,7 +180,7 @@ export class TalentsComp extends CCComp {
|
|||||||
|
|
||||||
let isMax = currentLevel >= talentInfo.maxLevel;
|
let isMax = currentLevel >= talentInfo.maxLevel;
|
||||||
let cost = isMax ? 0 : TalentConfig.costPerLevel[currentLevel];
|
let cost = isMax ? 0 : TalentConfig.costPerLevel[currentLevel];
|
||||||
let points = smc.vmdata.collection.talent_points || 0;
|
let points = smc.collection.talent_points || 0;
|
||||||
|
|
||||||
if (lblCost) {
|
if (lblCost) {
|
||||||
lblCost.string = isMax ? "已满级" : `消耗: ${cost}点`;
|
lblCost.string = isMax ? "已满级" : `消耗: ${cost}点`;
|
||||||
@@ -198,7 +198,7 @@ export class TalentsComp extends CCComp {
|
|||||||
|
|
||||||
/** 点击升级按钮 */
|
/** 点击升级按钮 */
|
||||||
private onUpgradeClicked(talentId: number, currentLevel: number, cost: number) {
|
private onUpgradeClicked(talentId: number, currentLevel: number, cost: number) {
|
||||||
const collection = smc.vmdata.collection;
|
const collection = smc.collection;
|
||||||
let points = collection.talent_points || 0;
|
let points = collection.talent_points || 0;
|
||||||
|
|
||||||
if (points >= cost && currentLevel < 5) {
|
if (points >= cost && currentLevel < 5) {
|
||||||
@@ -224,7 +224,7 @@ export class TalentsComp extends CCComp {
|
|||||||
// 看广告回调(预留)
|
// 看广告回调(预留)
|
||||||
this.watch_ad().then(success => {
|
this.watch_ad().then(success => {
|
||||||
if (success) {
|
if (success) {
|
||||||
const collection = smc.vmdata.collection;
|
const collection = smc.collection;
|
||||||
// 计算已消耗的天赋点总和
|
// 计算已消耗的天赋点总和
|
||||||
let refundedPoints = 0;
|
let refundedPoints = 0;
|
||||||
for (let id in collection.talents) {
|
for (let id in collection.talents) {
|
||||||
|
|||||||
Reference in New Issue
Block a user