refactor(game): 将玩家收集数据移出vmdata以优化结构
将 collection 对象从 vmdata 中移出,作为 SingletonModuleComp 的直接属性。这消除了不必要的嵌套层级,使数据访问更直接,并提高了代码可读性。同时更新了 TalentsComp 中所有相关引用,确保功能一致性。
This commit is contained in:
@@ -98,7 +98,7 @@ export class TalentsComp extends CCComp {
|
||||
|
||||
/** 更新玩家等级、经验、天赋点信息 */
|
||||
private updatePlayerInfo() {
|
||||
const collection = smc.vmdata.collection;
|
||||
const collection = smc.collection;
|
||||
let level = collection.player_level || 1;
|
||||
let exp = collection.player_exp || 0;
|
||||
let points = collection.talent_points || 0;
|
||||
@@ -137,7 +137,7 @@ export class TalentsComp extends CCComp {
|
||||
private updateTalentList() {
|
||||
if (!this.talents_content || !this.prefab_talent_item) return;
|
||||
|
||||
const collection = smc.vmdata.collection;
|
||||
const collection = smc.collection;
|
||||
if (!collection.talents) collection.talents = {};
|
||||
|
||||
// 如果内容为空,则实例化预制体
|
||||
@@ -180,7 +180,7 @@ export class TalentsComp extends CCComp {
|
||||
|
||||
let isMax = currentLevel >= talentInfo.maxLevel;
|
||||
let cost = isMax ? 0 : TalentConfig.costPerLevel[currentLevel];
|
||||
let points = smc.vmdata.collection.talent_points || 0;
|
||||
let points = smc.collection.talent_points || 0;
|
||||
|
||||
if (lblCost) {
|
||||
lblCost.string = isMax ? "已满级" : `消耗: ${cost}点`;
|
||||
@@ -198,7 +198,7 @@ export class TalentsComp extends CCComp {
|
||||
|
||||
/** 点击升级按钮 */
|
||||
private onUpgradeClicked(talentId: number, currentLevel: number, cost: number) {
|
||||
const collection = smc.vmdata.collection;
|
||||
const collection = smc.collection;
|
||||
let points = collection.talent_points || 0;
|
||||
|
||||
if (points >= cost && currentLevel < 5) {
|
||||
@@ -224,7 +224,7 @@ export class TalentsComp extends CCComp {
|
||||
// 看广告回调(预留)
|
||||
this.watch_ad().then(success => {
|
||||
if (success) {
|
||||
const collection = smc.vmdata.collection;
|
||||
const collection = smc.collection;
|
||||
// 计算已消耗的天赋点总和
|
||||
let refundedPoints = 0;
|
||||
for (let id in collection.talents) {
|
||||
|
||||
Reference in New Issue
Block a user