云环境和本地调试 添加

This commit is contained in:
2025-08-18 17:00:40 +08:00
parent addc61e2a9
commit a824d9a124
155 changed files with 6531 additions and 997 deletions

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "0474d69a-4ed2-4470-a797-19d9f23c09b0", "uuid": "0474d69a-4ed2-4470-a797-19d9f23c09b0",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "15588387-53dc-4224-bf79-8427e1cc1e9a", "uuid": "15588387-53dc-4224-bf79-8427e1cc1e9a",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "2b4c7ab0-b58d-4893-ade9-d8e56e03cf86", "uuid": "2b4c7ab0-b58d-4893-ade9-d8e56e03cf86",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "f35115b6-daca-417b-b2e3-059e6760e173", "uuid": "f35115b6-daca-417b-b2e3-059e6760e173",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "3403fbf1-f543-4e09-a6ec-24425bc59177", "uuid": "3403fbf1-f543-4e09-a6ec-24425bc59177",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "459d724d-7610-4d02-bd68-031a7a628d12", "uuid": "459d724d-7610-4d02-bd68-031a7a628d12",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "ddee9ebe-e001-473c-850a-3650df821ca5", "uuid": "ddee9ebe-e001-473c-850a-3650df821ca5",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "7a7b06c8-a066-4238-869c-cec4f7621361", "uuid": "7a7b06c8-a066-4238-869c-cec4f7621361",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "ea52be76-7907-4118-941a-822a9cda1966", "uuid": "ea52be76-7907-4118-941a-822a9cda1966",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "c3578585-1456-4045-b18d-96a2367dfe3e", "uuid": "c3578585-1456-4045-b18d-96a2367dfe3e",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "50fa0bab-1535-4892-94a8-c44c7b4736db", "uuid": "50fa0bab-1535-4892-94a8-c44c7b4736db",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "3842ed73-2247-4cb4-bd02-b1dfd3b0a2af", "uuid": "3842ed73-2247-4cb4-bd02-b1dfd3b0a2af",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "1cc562dd-d004-41b6-ba70-bef23074076a", "uuid": "1cc562dd-d004-41b6-ba70-bef23074076a",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "db035da2-17ca-4877-9579-1ea97b5d8443", "uuid": "db035da2-17ca-4877-9579-1ea97b5d8443",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "099a81bb-31a5-4d85-b854-9f2a8b60d279", "uuid": "099a81bb-31a5-4d85-b854-9f2a8b60d279",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "85e5c51a-3127-426a-a3c5-36ada6764f8f", "uuid": "85e5c51a-3127-426a-a3c5-36ada6764f8f",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "24774750-953a-4e0b-b361-b985bae02ecb", "uuid": "24774750-953a-4e0b-b361-b985bae02ecb",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "ad487883-575b-4cdf-a4b8-ecd284aa53cb", "uuid": "ad487883-575b-4cdf-a4b8-ecd284aa53cb",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "697e2bd1-01c2-4282-94c2-e8cf6370ca7d", "uuid": "697e2bd1-01c2-4282-94c2-e8cf6370ca7d",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "266933cf-0ed2-497e-98af-49472013e126", "uuid": "266933cf-0ed2-497e-98af-49472013e126",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "c53c26db-4847-4d14-887b-da9e1b2e748a", "uuid": "c53c26db-4847-4d14-887b-da9e1b2e748a",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "cd104e76-5215-49fe-a074-e65ffa26583e", "uuid": "cd104e76-5215-49fe-a074-e65ffa26583e",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "ebe57f11-acc7-4969-a421-464c625f2041", "uuid": "ebe57f11-acc7-4969-a421-464c625f2041",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "5f017fb0-494a-409b-99ed-ceae143e0f6f", "uuid": "5f017fb0-494a-409b-99ed-ceae143e0f6f",

View File

@@ -23429,10 +23429,10 @@
"__id__": 1028 "__id__": 1028
}, },
"templateMode": true, "templateMode": true,
"watchPath": "data.mission_data.exp", "watchPath": "data.data.exp",
"labelType": "cc.Label", "labelType": "cc.Label",
"watchPathArr": [ "watchPathArr": [
"data.mission_data.exp" "data.data.exp"
], ],
"_id": "" "_id": ""
}, },
@@ -24211,10 +24211,10 @@
"__id__": 1060 "__id__": 1060
}, },
"templateMode": true, "templateMode": true,
"watchPath": "data.mission_data.gold", "watchPath": "data.data.gold",
"labelType": "cc.Label", "labelType": "cc.Label",
"watchPathArr": [ "watchPathArr": [
"data.mission_data.gold" "data.data.gold"
], ],
"_id": "" "_id": ""
}, },

View File

@@ -737,7 +737,7 @@
"__id__": 28 "__id__": 28
}, },
"templateMode": false, "templateMode": false,
"watchPath": "data.mission_data.gold", "watchPath": "data.data.gold",
"labelType": "cc.Label", "labelType": "cc.Label",
"watchPathArr": [], "watchPathArr": [],
"_id": "" "_id": ""
@@ -1191,7 +1191,7 @@
"__id__": 48 "__id__": 48
}, },
"templateMode": false, "templateMode": false,
"watchPath": "data.mission_data.diamond", "watchPath": "data.data.diamond",
"labelType": "cc.Label", "labelType": "cc.Label",
"watchPathArr": [], "watchPathArr": [],
"_id": "" "_id": ""
@@ -1645,7 +1645,7 @@
"__id__": 68 "__id__": 68
}, },
"templateMode": false, "templateMode": false,
"watchPath": "data.mission_data.mission", "watchPath": "data.data.mission",
"labelType": "cc.Label", "labelType": "cc.Label",
"watchPathArr": [], "watchPathArr": [],
"_id": "" "_id": ""

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "486aac0a-12a3-438a-8902-c797ec07aedc", "uuid": "486aac0a-12a3-438a-8902-c797ec07aedc",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "4ca85ea7-6d3d-4e52-bb59-e0ad41ff0599", "uuid": "4ca85ea7-6d3d-4e52-bb59-e0ad41ff0599",

View File

@@ -5961,10 +5961,10 @@
"__id__": 259 "__id__": 259
}, },
"templateMode": true, "templateMode": true,
"watchPath": "data.mission_data.mission", "watchPath": "data.data.mission",
"labelType": "cc.Label", "labelType": "cc.Label",
"watchPathArr": [ "watchPathArr": [
"data.mission_data.mission" "data.data.mission"
], ],
"_id": "" "_id": ""
}, },
@@ -15857,10 +15857,10 @@
"__id__": 691 "__id__": 691
}, },
"templateMode": true, "templateMode": true,
"watchPath": "data.mission_data.mission", "watchPath": "data.data.mission",
"labelType": "cc.Label", "labelType": "cc.Label",
"watchPathArr": [ "watchPathArr": [
"data.mission_data.mission" "data.data.mission"
], ],
"_id": "" "_id": ""
}, },
@@ -38082,7 +38082,7 @@
"__id__": 1744 "__id__": 1744
}, },
"templateMode": false, "templateMode": false,
"watchPath": "data.mission_data.gold", "watchPath": "data.data.gold",
"labelType": "cc.Label", "labelType": "cc.Label",
"watchPathArr": [], "watchPathArr": [],
"_id": "" "_id": ""
@@ -38536,7 +38536,7 @@
"__id__": 1764 "__id__": 1764
}, },
"templateMode": false, "templateMode": false,
"watchPath": "data.mission_data.diamond", "watchPath": "data.data.diamond",
"labelType": "cc.Label", "labelType": "cc.Label",
"watchPathArr": [], "watchPathArr": [],
"_id": "" "_id": ""
@@ -38990,7 +38990,7 @@
"__id__": 1784 "__id__": 1784
}, },
"templateMode": false, "templateMode": false,
"watchPath": "data.mission_data.meat", "watchPath": "data.data.meat",
"labelType": "cc.Label", "labelType": "cc.Label",
"watchPathArr": [], "watchPathArr": [],
"_id": "" "_id": ""

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "b2d8f297-8058-482c-a848-956b5594d717", "uuid": "b2d8f297-8058-482c-a848-956b5594d717",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "f42b9fb1-b246-4d57-8733-31a1365729a6", "uuid": "f42b9fb1-b246-4d57-8733-31a1365729a6",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "4e4d1811-5bd5-4b5d-9535-a118dc3c970f", "uuid": "4e4d1811-5bd5-4b5d-9535-a118dc3c970f",
@@ -129,6 +129,6 @@
"type": "sprite-frame", "type": "sprite-frame",
"hasAlpha": true, "hasAlpha": true,
"fixAlphaTransparencyArtifacts": false, "fixAlphaTransparencyArtifacts": false,
"redirect": "4e4d1811-5bd5-4b5d-9535-a118dc3c970f@f9941" "redirect": "4e4d1811-5bd5-4b5d-9535-a118dc3c970f@6c48a"
} }
} }

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "3d5b607a-face-426b-8200-acf8384108db", "uuid": "3d5b607a-face-426b-8200-acf8384108db",
@@ -128,7 +128,7 @@
"userData": { "userData": {
"hasAlpha": true, "hasAlpha": true,
"type": "sprite-frame", "type": "sprite-frame",
"redirect": "3d5b607a-face-426b-8200-acf8384108db@f9941", "redirect": "3d5b607a-face-426b-8200-acf8384108db@6c48a",
"fixAlphaTransparencyArtifacts": false "fixAlphaTransparencyArtifacts": false
} }
} }

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.26", "ver": "1.0.27",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "a65eaaec-d315-4134-a79e-23bb817d1939", "uuid": "a65eaaec-d315-4134-a79e-23bb817d1939",
@@ -128,7 +128,7 @@
"userData": { "userData": {
"hasAlpha": true, "hasAlpha": true,
"type": "sprite-frame", "type": "sprite-frame",
"redirect": "a65eaaec-d315-4134-a79e-23bb817d1939@f9941", "redirect": "a65eaaec-d315-4134-a79e-23bb817d1939@6c48a",
"fixAlphaTransparencyArtifacts": false "fixAlphaTransparencyArtifacts": false
} }
} }

View File

@@ -1,5 +1,5 @@
{ {
"ver": "1.0.2", "ver": "1.0.1",
"importer": "text", "importer": "text",
"imported": true, "imported": true,
"uuid": "ecad0109-344e-47b2-aaa9-ee5902b9b016", "uuid": "ecad0109-344e-47b2-aaa9-ee5902b9b016",

View File

@@ -12,13 +12,12 @@ import { WxCloudApi } from './game/wx_clound_client_api/WxCloudApi';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
// WxCloudApi.init("cloud1-6gknw0qk911036d8")
@ccclass('Main') @ccclass('Main')
export class Main extends Root { export class Main extends Root {
start() { start() {
if(this.isWxClient()){ // if(this.isWxClient()){
WxCloudApi.init("cloud1-6gknw0qk911036d8") // WxCloudApi.init("cloud1-6gknw0qk911036d8")
} // }
PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Aabb | PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Aabb |
EPhysics2DDrawFlags.Pair EPhysics2DDrawFlags.Pair
// EPhysics2DDrawFlags.CenterOfMass | // EPhysics2DDrawFlags.CenterOfMass |

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "0eec0b38-aab6-45ee-89cf-95806b0fecbe", "uuid": "0eec0b38-aab6-45ee-89cf-95806b0fecbe",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "f680d91a-831f-4f99-b7ea-b45e3adff51a", "uuid": "f680d91a-831f-4f99-b7ea-b45e3adff51a",

View File

@@ -0,0 +1,568 @@
import { WxCloudApi ,UserGameData} from "../wx_clound_client_api/WxCloudApi";
import { smc } from "./SingletonModuleComp";
/**
* 游戏数据同步管理器
* 负责管理fight_heros、heros、items、tals、equips的远程操作和本地同步
* 只有在远程修改成功后才同步修改本地数据
*/
export class GameDataSyncManager {
private static instance: GameDataSyncManager;
private constructor() {}
public static getInstance(): GameDataSyncManager {
if (!GameDataSyncManager.instance) {
GameDataSyncManager.instance = new GameDataSyncManager();
}
return GameDataSyncManager.instance;
}
/**
* 用远程数据覆盖本地数据(统一方法)
* @param remoteData 远程数据(云端或本地调试)
* @param dataSource 数据源描述
*/
async overrideLocalDataWithRemote(remoteData: UserGameData, dataSource: string) {
try {
console.log(`[Initialize]: 开始用${dataSource}数据覆盖客户端数据...`);
// 直接覆盖基础游戏数据
if (remoteData.data) {
Object.assign(smc.data, remoteData.data);
console.log(`[Initialize]: 基础游戏数据已从${dataSource}覆盖`);
}
// 直接覆盖出战英雄配置
if (remoteData.fight_heros) {
Object.assign(smc.fight_heros, remoteData.fight_heros);
console.log(`[Initialize]: 出战英雄配置已从${dataSource}覆盖`);
}
// 直接覆盖英雄数据
if (remoteData.heros) {
smc.heros = { ...remoteData.heros };
console.log(`[Initialize]: 英雄数据已从${dataSource}覆盖`);
}
// 直接覆盖道具数据
if (remoteData.items) {
Object.assign(smc.itmes, remoteData.items);
console.log(`[Initialize]: 道具数据已从${dataSource}覆盖`);
}
// 直接覆盖天赋数据
if (remoteData.tals) {
Object.assign(smc.tals, remoteData.tals);
console.log(`[Initialize]: 天赋数据已从${dataSource}覆盖`);
}
// 直接覆盖装备数据
if (remoteData.equips) {
Object.assign(smc.equips, remoteData.equips);
console.log(`[Initialize]: 装备数据已从${dataSource}覆盖`);
}
// 同步ViewModel数据
smc.syncData();
// 保存到本地存储(确保数据持久化)
// smc.saveGameData();
console.log(`[Initialize]: ${dataSource}数据覆盖完成,已保存到本地`);
} catch (error) {
console.error(`[Initialize]: ${dataSource}数据覆盖失败:`, error);
}
}
/**
* 批量更新出战英雄配置
* @param fightHeros 出战英雄配置对象
* @returns 是否成功
*/
async updateFightHeros(fightHeros: any): Promise<boolean> {
try {
console.log(`[GameDataSyncManager]: 批量更新出战英雄配置:`, fightHeros);
const result = await WxCloudApi.updateFightHeros(fightHeros);
if (result.result.code === 200) {
// 远程修改成功,同步本地数据
Object.assign(smc.fight_heros, fightHeros);
console.log(`[GameDataSyncManager]: 出战英雄配置更新成功,本地数据已同步`);
return true;
} else {
console.warn(`[GameDataSyncManager]: 出战英雄配置更新失败: ${result.result.msg}`);
return false;
}
} catch (error) {
console.error(`[GameDataSyncManager]: 更新出战英雄配置异常:`, error);
return false;
}
}
/**
* 重置出战英雄配置为默认值
* @returns 是否成功
*/
async resetFightHeros(): Promise<boolean> {
try {
console.log(`[GameDataSyncManager]: 重置出战英雄配置`);
const result = await WxCloudApi.resetFightHeros();
if (result.result.code === 200) {
// 远程修改成功,同步本地数据
smc.fight_heros = result.result.data;
console.log(`[GameDataSyncManager]: 出战英雄配置重置成功,本地数据已同步`);
return true;
} else {
console.warn(`[GameDataSyncManager]: 出战英雄配置重置失败: ${result.result.msg}`);
return false;
}
} catch (error) {
console.error(`[GameDataSyncManager]: 重置出战英雄配置异常:`, error);
return false;
}
}
// ==================== 英雄管理 ====================
/**
* 添加新英雄到用户库存
* @param heroId 英雄ID
* @param heroData 英雄数据(可选)
* @returns 是否成功
*/
async addHero(heroId: number, heroData?: any): Promise<boolean> {
try {
console.log(`[GameDataSyncManager]: 添加英雄 ID:${heroId}, 数据:`, heroData);
const result = await WxCloudApi.addHero(heroId, heroData);
if (result.result.code === 200) {
// 远程修改成功,同步本地数据
smc.heros[heroId] = result.result.data;
console.log(`[GameDataSyncManager]: 英雄添加成功,本地数据已同步`);
return true;
} else {
console.warn(`[GameDataSyncManager]: 英雄添加失败: ${result.result.msg}`);
return false;
}
} catch (error) {
console.error(`[GameDataSyncManager]: 添加英雄异常:`, error);
return false;
}
}
/**
* 更新英雄的多个属性
* @param heroId 英雄ID
* @param updateData 要更新的属性
* @returns 是否成功
*/
async updateHero(heroId: number, updateData: any): Promise<boolean> {
try {
console.log(`[GameDataSyncManager]: 更新英雄 ID:${heroId}, 更新数据:`, updateData);
const result = await WxCloudApi.updateHero(heroId, updateData);
if (result.result.code === 200) {
// 远程修改成功,同步本地数据
Object.assign(smc.heros[heroId], result.result.data.new_data);
console.log(`[GameDataSyncManager]: 英雄更新成功,本地数据已同步`);
return true;
} else {
console.warn(`[GameDataSyncManager]: 英雄更新失败: ${result.result.msg}`);
return false;
}
} catch (error) {
console.error(`[GameDataSyncManager]: 更新英雄异常:`, error);
return false;
}
}
/**
* 设置英雄的单个属性值
* @param heroId 英雄ID
* @param property 属性名
* @param value 属性值
* @returns 是否成功
*/
async setHeroProperty(heroId: number, property: any, value: any): Promise<boolean> {
try {
console.log(`[GameDataSyncManager]: 设置英雄属性 ID:${heroId}, 属性:${property}, 值:${value}`);
const result = await WxCloudApi.setHeroProperty(heroId, property, value);
if (result.result.code === 200) {
// 远程修改成功,同步本地数据
smc.heros[heroId][property] = value;
console.log(`[GameDataSyncManager]: 英雄属性设置成功,本地数据已同步`);
return true;
} else {
console.warn(`[GameDataSyncManager]: 英雄属性设置失败: ${result.result.msg}`);
return false;
}
} catch (error) {
console.error(`[GameDataSyncManager]: 设置英雄属性异常:`, error);
return false;
}
}
/**
* 英雄升级指定级数
* @param heroId 英雄ID
* @param levels 升级级数默认1级
* @returns 是否成功
*/
async levelUpHero(heroId: number, exp:number,gold:number,levels: number = 1,): Promise<boolean> {
try {
console.log(`[GameDataSyncManager]: 英雄升级 ID:${heroId}, 级数:${levels}`);
const result = await WxCloudApi.levelUpHero(heroId, exp,gold,levels);
if (result.result.code === 200) {
// 远程修改成功,同步本地数据
smc.heros[heroId].lv = result.result.data.new_value;
console.log(`[GameDataSyncManager]: 英雄升级成功,本地数据已同步`);
return true;
} else {
console.warn(`[GameDataSyncManager]: 英雄升级失败: ${result.result.msg}`);
return false;
}
} catch (error) {
console.error(`[GameDataSyncManager]: 英雄升级异常:`, error);
return false;
}
}
/**
* 删除指定英雄
* @param heroId 英雄ID
* @returns 是否成功
*/
async deleteHero(heroId: number): Promise<boolean> {
try {
console.log(`[GameDataSyncManager]: 删除英雄 ID:${heroId}`);
const result = await WxCloudApi.deleteHero(heroId);
if (result.result.code === 200) {
// 远程修改成功,同步本地数据
delete smc.heros[heroId];
console.log(`[GameDataSyncManager]: 英雄删除成功,本地数据已同步`);
return true;
} else {
console.warn(`[GameDataSyncManager]: 英雄删除失败: ${result.result.msg}`);
return false;
}
} catch (error) {
console.error(`[GameDataSyncManager]: 删除英雄异常:`, error);
return false;
}
}
// ==================== 库存管理 (items, tals, equips) ====================
/**
* 增加指定物品的数量
* @param type 库存类型 ('items', 'tals', 'equips')
* @param itemId 物品ID
* @param count 添加数量
* @returns 是否成功
*/
async addInventoryItem(type: 'items' | 'tals' | 'equips', itemId: number, count: number): Promise<boolean> {
try {
console.log(`[GameDataSyncManager]: 增加库存物品 类型:${type}, ID:${itemId}, 数量:${count}`);
const result = await WxCloudApi.addInventoryItem(type, itemId, count);
if (result.result.code === 200) {
// 远程修改成功,同步本地数据
const targetData = this.getTargetData(type);
targetData[itemId] = (targetData[itemId] || 0) + count;
console.log(`[GameDataSyncManager]: 库存物品增加成功,本地数据已同步`);
return true;
} else {
console.warn(`[GameDataSyncManager]: 库存物品增加失败: ${result.result.msg}`);
return false;
}
} catch (error) {
console.error(`[GameDataSyncManager]: 增加库存物品异常:`, error);
return false;
}
}
/**
* 消耗指定数量的物品
* @param type 库存类型 ('items', 'tals', 'equips')
* @param itemId 物品ID
* @param count 消耗数量
* @returns 是否成功
*/
async consumeInventoryItem(type: 'items' | 'tals' | 'equips', itemId: number, count: number): Promise<boolean> {
try {
console.log(`[GameDataSyncManager]: 消耗库存物品 类型:${type}, ID:${itemId}, 数量:${count}`);
const result = await WxCloudApi.consumeInventoryItem(type, itemId, count);
if (result.result.code === 200) {
// 远程修改成功,同步本地数据
const targetData = this.getTargetData(type);
targetData[itemId] = Math.max(0, (targetData[itemId] || 0) - count);
console.log(`[GameDataSyncManager]: 库存物品消耗成功,本地数据已同步`);
return true;
} else {
console.warn(`[GameDataSyncManager]: 库存物品消耗失败: ${result.result.msg}`);
return false;
}
} catch (error) {
console.error(`[GameDataSyncManager]: 消耗库存物品异常:`, error);
return false;
}
}
/**
* 直接设置物品的数量
* @param type 库存类型 ('items', 'tals', 'equips')
* @param itemId 物品ID
* @param count 新的数量
* @returns 是否成功
*/
async setInventoryItem(type: 'items' | 'tals' | 'equips', itemId: number, count: number): Promise<boolean> {
try {
console.log(`[GameDataSyncManager]: 设置库存物品 类型:${type}, ID:${itemId}, 数量:${count}`);
const result = await WxCloudApi.setInventoryItem(type, itemId, count);
if (result.result.code === 200) {
// 远程修改成功,同步本地数据
const targetData = this.getTargetData(type);
targetData[itemId] = count;
console.log(`[GameDataSyncManager]: 库存物品设置成功,本地数据已同步`);
return true;
} else {
console.warn(`[GameDataSyncManager]: 库存物品设置失败: ${result.result.msg}`);
return false;
}
} catch (error) {
console.error(`[GameDataSyncManager]: 设置库存物品异常:`, error);
return false;
}
}
/**
* 批量更新多个物品的数量
* @param type 库存类型 ('items', 'tals', 'equips')
* @param data 更新数据对象
* @param merge 是否合并更新默认true
* @returns 是否成功
*/
async updateInventory(type: 'items' | 'tals' | 'equips', data: any, merge: boolean = true): Promise<boolean> {
try {
console.log(`[GameDataSyncManager]: 批量更新库存 类型:${type}, 数据:`, data);
const result = await WxCloudApi.updateInventory(type, data, merge);
if (result.result.code === 200) {
// 远程修改成功,同步本地数据
const targetData = this.getTargetData(type);
if (merge) {
Object.assign(targetData, data);
} else {
Object.keys(targetData).forEach(key => delete targetData[key]);
Object.assign(targetData, data);
}
console.log(`[GameDataSyncManager]: 库存批量更新成功,本地数据已同步`);
return true;
} else {
console.warn(`[GameDataSyncManager]: 库存批量更新失败: ${result.result.msg}`);
return false;
}
} catch (error) {
console.error(`[GameDataSyncManager]: 批量更新库存异常:`, error);
return false;
}
}
/**
* 重置指定类型的库存为默认值
* @param type 库存类型 ('items', 'tals', 'equips')
* @returns 是否成功
*/
async resetInventory(type: 'items' | 'tals' | 'equips'): Promise<boolean> {
try {
console.log(`[GameDataSyncManager]: 重置库存 类型:${type}`);
const result = await WxCloudApi.resetInventory(type);
if (result.result.code === 200) {
// 远程修改成功,同步本地数据
const targetData = this.getTargetData(type);
Object.keys(targetData).forEach(key => delete targetData[key]);
Object.assign(targetData, result.result.data);
console.log(`[GameDataSyncManager]: 库存重置成功,本地数据已同步`);
return true;
} else {
console.warn(`[GameDataSyncManager]: 库存重置失败: ${result.result.msg}`);
return false;
}
} catch (error) {
console.error(`[GameDataSyncManager]: 重置库存异常:`, error);
return false;
}
}
// ==================== 便捷方法 ====================
/**
* 增加道具
* @param itemId 道具ID
* @param count 数量
* @returns 是否成功
*/
async addItem(itemId: number, count: number): Promise<boolean> {
return this.addInventoryItem('items', itemId, count);
}
/**
* 消耗道具
* @param itemId 道具ID
* @param count 数量
* @returns 是否成功
*/
async consumeItem(itemId: number, count: number): Promise<boolean> {
return this.consumeInventoryItem('items', itemId, count);
}
/**
* 增加天赋点
* @param talId 天赋ID
* @param count 数量
* @returns 是否成功
*/
async addTalent(talId: number, count: number): Promise<boolean> {
return this.addInventoryItem('tals', talId, count);
}
/**
* 消耗天赋点
* @param talId 天赋ID
* @param count 数量
* @returns 是否成功
*/
async consumeTalent(talId: number, count: number): Promise<boolean> {
return this.consumeInventoryItem('tals', talId, count);
}
/**
* 增加装备
* @param equipId 装备ID
* @param count 数量
* @returns 是否成功
*/
async addEquipment(equipId: number, count: number): Promise<boolean> {
return this.addInventoryItem('equips', equipId, count);
}
/**
* 消耗装备
* @param equipId 装备ID
* @param count 数量
* @returns 是否成功
*/
async consumeEquipment(equipId: number, count: number): Promise<boolean> {
return this.consumeInventoryItem('equips', equipId, count);
}
// ==================== 私有辅助方法 ====================
/**
* 根据类型获取对应的目标数据对象
* @param type 库存类型
* @returns 对应的数据对象
*/
private getTargetData(type: 'items' | 'tals' | 'equips'): any {
switch (type) {
case 'items':
return smc.itmes;
case 'tals':
return smc.tals;
case 'equips':
return smc.equips;
default:
throw new Error(`未知的库存类型: ${type}`);
}
}
/**
* 从云端加载所有游戏数据并同步到本地
* @returns 是否成功
*/
async loadAllGameData(): Promise<boolean> {
try {
console.log(`[GameDataSyncManager]: 从云端加载所有游戏数据`);
const result = await WxCloudApi.getAllGameData();
if (result.result.code === 200) {
// 远程数据获取成功,同步本地数据
const cloudData = result.result.data;
smc.data = cloudData.data;
smc.fight_heros = cloudData.fight_heros;
smc.heros = cloudData.heros;
smc.itmes = cloudData.items;
smc.tals = cloudData.tals;
smc.equips = cloudData.equips;
// 同步vmdata
smc.syncData();
console.log(`[GameDataSyncManager]: 云端数据加载成功,本地数据已同步`);
return true;
} else {
console.warn(`[GameDataSyncManager]: 云端数据加载失败: ${result.result.msg}`);
return false;
}
} catch (error) {
console.error(`[GameDataSyncManager]: 加载云端数据异常:`, error);
return false;
}
}
}
// 导出单例实例
export const gameDataSyncManager = GameDataSyncManager.getInstance();
/*
使用示例:
// 1. 出战英雄管理
await gameDataSyncManager.setFightHero(0, 5001); // 设置位置0的英雄
await gameDataSyncManager.swapFightHeros(0, 1); // 交换位置0和1的英雄
await gameDataSyncManager.updateFightHeros({0: 5001, 1: 5005}); // 批量更新
// 2. 英雄管理
await gameDataSyncManager.addHero(5008, {uuid: 5008, lv: 1}); // 添加新英雄
await gameDataSyncManager.levelUpHero(5001, 5); // 英雄升级5级
await gameDataSyncManager.setHeroProperty(5001, "exp", 1000); // 设置英雄经验
// 3. 库存管理
await gameDataSyncManager.addItem(1001, 10); // 增加道具
await gameDataSyncManager.consumeItem(1001, 2); // 消耗道具
await gameDataSyncManager.addTalent(2001, 5); // 增加天赋点
await gameDataSyncManager.addEquipment(3001, 2); // 增加装备
// 4. 数据加载
await gameDataSyncManager.loadAllGameData(); // 从云端加载所有数据
注意:所有方法都返回 Promise<boolean>true表示成功false表示失败
只有在远程修改成功后,本地数据才会被同步修改
*/

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "89c45a3b-d0bf-4e45-9e27-b7d714ba7e29",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -4,6 +4,10 @@ import { Initialize } from "../initialize/Initialize";
import { GameMap } from "../map/GameMap"; import { GameMap } from "../map/GameMap";
import { HeroUI, VmInfo } from "./config/Mission"; import { HeroUI, VmInfo } from "./config/Mission";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { WxCloudApi } from "../wx_clound_client_api/WxCloudApi";
import { gameDataSyncManager } from "./GameDataSyncManager";
import { GameSet } from "./config/BoxSet";
import { Test } from "./Test";
// import { Role } from "../role/Role"; // import { Role } from "../role/Role";
@@ -15,6 +19,8 @@ export class SingletonModuleComp extends ecs.Comp {
initialize: Initialize = null!; initialize: Initialize = null!;
/** 游戏地图 */ /** 游戏地图 */
map: GameMap = null!; map: GameMap = null!;
/** 游戏数据同步管理器 */
private gameDataSyncManager = gameDataSyncManager;
mission:any={ mission:any={
status:0, //0:未开始 1:进行中 2:胜利 3:失败 status:0, //0:未开始 1:进行中 2:胜利 3:失败
play:false, play:false,
@@ -37,21 +43,19 @@ export class SingletonModuleComp extends ecs.Comp {
ckey:0, //铜钥匙 解锁稀有英雄 也可以直接兑换金币 ckey:0, //铜钥匙 解锁稀有英雄 也可以直接兑换金币
skey:0, //银钥匙 解锁史诗英雄 也可以直接兑换金币 skey:0, //银钥匙 解锁史诗英雄 也可以直接兑换金币
gkey:0, //金钥匙 解锁传说英雄 也可以直接兑换金币 gkey:0, //金钥匙 解锁传说英雄 也可以直接兑换金币
}
fight_heros:any={
0:5001,
1:5005,
2:0,
3:0,
4:0,
} }
fight_heros:any={ 0:5001, 1:5005, 2:0, 3:0, 4:0, }
heros:any = { heros:any = {
5001:{uuid:5001,lv:1}, 5001:{uuid:5001,lv:1},
5005:{uuid:5005,lv:1}, 5005:{uuid:5005,lv:1},
5007:{uuid:5007,lv:1}, 5007:{uuid:5007,lv:1},
}; };
itmes:any={
}
tals:any={
}
equips:any={
}
monsters:any = []; monsters:any = [];
sk_info:any = [] sk_info:any = []
monsters_dead:any = [] monsters_dead:any = []
@@ -60,32 +64,46 @@ export class SingletonModuleComp extends ecs.Comp {
vmdata: any = { vmdata: any = {
game_over:false, game_over:false,
game_pause:false, game_pause:false,
data:{
score:0,
mission:1,
gold:100, //升级主要资源
diamond:100, //商店购买 及 双倍奖励资源
meat:0,
exp:0, //升级经验
ghstone:0, //英雄石 绿色 普通英雄升星
bhstone:0, //英雄石 蓝色 稀有英雄升星
phlestone:0, //英雄石 紫色 史诗英雄升星
rhstone:0, //英雄石 红色 传说英雄升星
herocard:0, //英雄卡,抽卡凭证
ckey:0, //铜钥匙 解锁稀有英雄 也可以直接兑换金币
skey:0, //银钥匙 解锁史诗英雄 也可以直接兑换金币
gkey:0, //金钥匙 解锁传说英雄 也可以直接兑换金币
},
mission_data:{ mission_data:{
gold:1000,//金币
exp:0,//经验
score:0,//分数
diamond:0,//钻石
mission:1,//关卡
chapter:1,//章节
level:1,//关卡等级
max_mission:4,//最大关卡
meat:0,//肉
mon_num:0,//怪物数量 mon_num:0,//怪物数量
hero_num:0,//英雄数量 hero_num:0,//英雄数量
wave_time_num:0,//波次时间 wave_time_num:0,//波次时间
in_fight:false, in_fight:false,
fight_time:0,//战斗时间 fight_time:0,//战斗时间
level:1,//关卡等级
max_mission:4,//最大关卡
}, },
reward:{ reward:{
gold:0,
meat:0,
diamond:0,
score:0, score:0,
exp:0, mission:0,
gcard:0, gold:0, //升级主要资源
bcard:0, diamond:0, //商店购买 及 双倍奖励资源
pcard:0, meat:0,
ycard:0, exp:0, //升级经验
ghstone:0, //英雄石 绿色 普通英雄升星
bhstone:0, //英雄石 蓝色 稀有英雄升星
phlestone:0, //英雄石 紫色 史诗英雄升星
rhstone:0, //英雄石 红色 传说英雄升星
herocard:0, //英雄卡,抽卡凭证
ckey:0, //铜钥匙 解锁稀有英雄 也可以直接兑换金币
skey:0, //银钥匙 解锁史诗英雄 也可以直接兑换金币
gkey:0, //金钥匙 解锁传说英雄 也可以直接兑换金币
} }
}; };
vmAdd() { vmAdd() {
@@ -97,483 +115,97 @@ export class SingletonModuleComp extends ecs.Comp {
} }
} }
// ==================== 本地存储管理方法 ==================== // ==================== 数据管理方法 ====================
/** /**
* 初始化默认游戏数据 * 同步数据到vmdata
*/ */
initDefaultData() {
// 确保出战英雄有默认值
if (!this.fight_heros || Object.keys(this.fight_heros).length === 0) {
this.fight_heros = {
0: 5001,
1: 5005,
2: 0,
3: 0,
4: 0,
};
}
// 确保英雄属性有默认值
if (!this.heros || Object.keys(this.heros).length === 0) {
this.heros = {
5001: {lv: 1},
5005: {lv: 1},
5007: {lv: 1},
};
}
// 确保游戏数据有默认值
if (!this.data || Object.keys(this.data).length === 0) {
this.data = {
score: 888,
mission: 1,
gold: 100,
diamond: 100,
};
}
console.log("[SMC]: 默认数据已初始化 - 出战英雄:", this.fight_heros, "英雄属性:", this.heros, "游戏数据:", this.data);
}
/**
* 保存游戏数据到本地存储
*/
saveGameData() {
try {
// 保存出战英雄数据
const fightHerosJson = JSON.stringify(this.fight_heros);
oops.storage.set("fight_heros", fightHerosJson);
// 保存英雄属性数据
const herosJson = JSON.stringify(this.heros);
oops.storage.set("heros", herosJson);
// 保存游戏数据(金币、钻石等)
const dataJson = JSON.stringify(this.data);
oops.storage.set("game_data", dataJson);
console.log("[SMC]: 游戏数据已保存 - 出战英雄:", this.fight_heros, "英雄属性:", this.heros, "游戏数据:", this.data);
return true;
} catch (error) {
console.error("[SMC]: 保存游戏数据失败:", error);
return false;
}
}
/**
* 保存英雄数据到本地存储(兼容旧方法名)
*/
saveHeroData() {
return this.saveGameData();
}
/**
* 从本地存储加载游戏数据
*/
loadGameData() {
console.log("[SMC]: 加载游戏数据")
try {
let hasAnyData = false;
// 加载出战英雄数据
const savedFightHeros = oops.storage.get("fight_heros");
if (savedFightHeros && savedFightHeros !== "") {
const fightHerosData = JSON.parse(savedFightHeros);
this.fight_heros = fightHerosData;
console.log("[SMC]: 从本地加载出战英雄数据:", fightHerosData);
hasAnyData = true;
} else {
console.log("[SMC]: 未找到本地出战英雄数据,使用默认配置");
}
// 加载英雄属性数据
const savedHeros = oops.storage.get("heros");
if (savedHeros && savedHeros !== "") {
const herosData = JSON.parse(savedHeros);
this.heros = herosData;
console.log("[SMC]: 从本地加载英雄属性数据:", herosData);
hasAnyData = true;
} else {
console.log("[SMC]: 未找到本地英雄属性数据,使用默认配置");
}
// 加载游戏数据
const savedData = oops.storage.get("game_data");
if (savedData && savedData !== "") {
const gameData = JSON.parse(savedData);
this.data = gameData;
console.log("[SMC]: 从本地加载游戏数据:", gameData);
hasAnyData = true;
} else {
console.log("[SMC]: 未找到本地游戏数据,使用默认配置");
}
// 如果没有任何本地数据,说明是首次启动,初始化并保存默认数据
if (!hasAnyData) {
console.log("[SMC]: 首次启动,初始化默认游戏数据");
this.initDefaultData();
this.saveGameData();
return true; // 首次启动也算成功
}
return hasAnyData;
} catch (error) {
console.error("[SMC]: 加载游戏数据失败:", error);
return false;
}
}
/**
* 从本地存储加载英雄数据(兼容旧方法名)
*/
loadHeroData() {
return this.loadGameData();
}
/**
* 设置出战英雄
* @param position 出战位置 (0-4)
* @param heroId 英雄ID0表示移除
* @param autoSave 是否自动保存 (默认true)
*/
setFightHero(position: number, heroId: number, autoSave: boolean = true) {
if (position < 0 || position > 4) {
console.warn("[SMC]: 出战位置无效:", position);
return false;
}
this.fight_heros[position] = heroId;
console.log(`[SMC]: 设置出战位置${position} -> 英雄${heroId}`);
if (autoSave) {
this.saveGameData();
}
return true;
}
/**
* 获取出战英雄ID
* @param position 出战位置 (0-4)
*/
getFightHero(position: number): number {
if (position < 0 || position > 4) {
console.warn("[SMC]: 出战位置无效:", position);
return 0;
}
return this.fight_heros[position] || 0;
}
/**
* 获取当前出战英雄列表(不包含空位)
*/
getActiveFightHeros(): number[] {
const activeHeros: number[] = [];
for (let i = 0; i < 5; i++) {
const heroId = this.fight_heros[i];
if (heroId && heroId > 0) {
activeHeros.push(heroId);
}
}
return activeHeros;
}
/**
* 设置英雄属性
* @param heroId 英雄ID
* @param property 属性名 (如: lv, exp等)
* @param value 属性值
* @param autoSave 是否自动保存 (默认true)
*/
setHeroProperty(heroId: number, property: string, value: any, autoSave: boolean = true) {
if (!this.heros[heroId]) {
this.heros[heroId] = {};
}
this.heros[heroId][property] = value;
console.log(`[SMC]: 设置英雄${heroId}${property} = ${value}`);
if (autoSave) {
this.saveGameData();
}
}
/**
* 获取英雄属性
* @param heroId 英雄ID
* @param property 属性名
* @param defaultValue 默认值
*/
getHeroProperty(heroId: number, property: string, defaultValue: any = null): any {
if (!this.heros[heroId]) {
return defaultValue;
}
return this.heros[heroId][property] !== undefined ? this.heros[heroId][property] : defaultValue;
}
/**
* 英雄升级
* @param heroId 英雄ID
* @param levels 升级级数 (默认1级)
* @param autoSave 是否自动保存 (默认true)
*/
levelUpHero(heroId: number, levels: number = 1, autoSave: boolean = true) {
const currentLevel = this.getHeroProperty(heroId, "lv", 1);
const newLevel = currentLevel + levels;
this.setHeroProperty(heroId, "lv", newLevel, autoSave);
console.log(`[SMC]: 英雄${heroId}升级: ${currentLevel} -> ${newLevel}`);
}
getHasHeroUUID() {
return Object.keys(this.heros).map(Number)
}
/**
* 获取英雄等级
* @param heroId 英雄ID
*/
getHeroLevel(heroId: number): number {
return this.getHeroProperty(heroId, "lv", 1);
}
/**
* 清除所有本地存储数据
*/
clearAllSaveData() {
try {
oops.storage.remove("fight_heros");
oops.storage.remove("heros");
oops.storage.remove("game_data");
console.log("[SMC]: 已清除所有本地存储数据");
return true;
} catch (error) {
console.error("[SMC]: 清除存储数据失败:", error);
return false;
}
}
/**
* 重置英雄数据为默认值
* @param autoSave 是否自动保存 (默认true)
*/
resetHeroData(autoSave: boolean = true) {
// 重置为默认出战英雄
this.fight_heros = {
0: 5001,
1: 5005,
2: 0,
3: 0,
4: 0,
};
// 重置为默认英雄属性
this.heros = {
5001: {lv: 1},
5005: {lv: 1},
5007: {lv: 1},
};
console.log("[SMC]: 英雄数据已重置为默认值");
if (autoSave) {
this.saveGameData();
}
}
// ==================== 游戏数据管理方法 ====================
/**
* 设置游戏数据属性
* @param property 属性名 (如: score, mission, gold, diamond)
* @param value 属性值
* @param autoSave 是否自动保存 (默认true)
*/
setGameProperty(property: string, value: any, autoSave: boolean = true) {
this.data[property] = value;
this.vmdata.mission_data[property] = value;
console.log(`[SMC]: 设置游戏数据 ${property} = ${value}`);
if (autoSave) {
this.saveGameData();
}
}
addGameProperty(property: string, value: any, autoSave: boolean = true) {
this.data[property] = this.data[property] + value;
this.vmdata.mission_data[property] = this.data[property]
console.log(`[SMC]:增加游戏数据 ${property} = ${value}`);
if (autoSave) {
this.saveGameData();
}
}
spendGameProperty(property: string, value: any, autoSave: boolean = true) {
this.data[property] = this.data[property] - value;
this.vmdata.mission_data[property] = this.data[property]
console.log(`[SMC]: 消耗游戏数据 ${property} = ${value}`);
if (autoSave) {
this.saveGameData();
}
}
/**
* 获取游戏数据属性
* @param property 属性名
* @param defaultValue 默认值
*/
getGameProperty(property: string, defaultValue: any = null): any {
return this.data[property] !== undefined ? this.data[property] : defaultValue;
}
syncData(){ syncData(){
this.vmdata.mission_data.gold=this.getGameProperty("gold", 0) this.vmdata.data = this.data;
this.vmdata.mission_data.meat=this.getGameProperty("meat", 0)
this.vmdata.mission_data.diamond=this.getGameProperty("diamond", 0)
this.vmdata.mission_data.mission=this.getGameProperty("mission", 1)
this.vmdata.mission_data.score=this.getGameProperty("score", 0)
this.vmdata.mission_data.exp=this.getGameProperty("exp", 0)
// // 计算章节和关卡等级
// const currentMission = this.getGameProperty("mission", 1)
// this.vmdata.mission_data.chapter = Math.floor((currentMission - 1) / 10) + 1
// this.vmdata.mission_data.level = ((currentMission - 1) % 10) + 1
} }
initReward(){ /**
this.vmdata.reward.gold=0 * 判断是否为微信客户端
this.vmdata.reward.meat=0
this.vmdata.reward.diamond=0
this.vmdata.reward.score=0
this.vmdata.reward.exp=0
this.vmdata.reward.gcard=0
this.vmdata.reward.bcard=0
this.vmdata.reward.pcard=0
this.vmdata.reward.ycard=0
}
/**
* 增加金币
* @param amount 金币数量
* @param autoSave 是否自动保存 (默认true)
*/ */
addGold(amount: number, autoSave: boolean = true) { private isWxClient(): boolean {
const currentGold = this.getGameProperty("gold", 0); // 检查是否存在微信API
const newGold = Math.max(0, currentGold + amount); return typeof wx !== 'undefined' && typeof (wx as any).getSystemInfoSync === 'function';
this.setGameProperty("gold", newGold, autoSave); }
console.log(`[SMC]: 金币变更: ${currentGold} -> ${newGold} (${amount > 0 ? '+' : ''}${amount})`); //调试用
return newGold; syncDataFromLocal(){
if(this.isWxClient()) return
const loginResult = new Test().load_data_from_local()
this.gameDataSyncManager.overrideLocalDataWithRemote(loginResult, "本地调试");
}
setFightHero(position:number,heroId:number,autoSave:boolean=true){
this.fight_heros[position] = heroId;
if(autoSave){
this.updateFightHeros()
}
}
updateFightHeros(){
this.gameDataSyncManager.updateFightHeros(this.fight_heros);
}
resetFightHeros(){
this.gameDataSyncManager.resetFightHeros();
}
getHasHeroUUID(){
let heros=this.heros
let heros_uuid=[]
for(let key in heros){
heros_uuid.push(heros[key].uuid)
}
return heros_uuid
}
levelUpHero(heroId:number,exp:number,gold:number){
let result=this.gameDataSyncManager.levelUpHero(heroId,exp,gold);
if(result){
this.heros[heroId].lv++;
}
return result;
}
// ==================== 统一的数据操作接口 ====================
/**
* 增加游戏数据属性(统一接口)
* @param property 属性名
* @param value 增加的值
* @param autoSave 是否自动保存 (默认true)
* @returns 操作结果
*/
async addGameProperty(property: string, value: any, autoSave: boolean = true): Promise<any> {
const currentValue = this.data[property] || 0;
const newValue = currentValue + value;
this.data[property] = newValue;
this.vmdata.data[property] = newValue;
console.log(`[SMC]: 增加游戏数据 ${property} = ${value}, 当前值: ${newValue}`);
return newValue;
} }
/** /**
* 消耗金币 * 消耗游戏数据属性(统一接口)
* @param amount 消耗数量 * @param property 属性名
* @param value 消耗的值
* @param autoSave 是否自动保存 (默认true) * @param autoSave 是否自动保存 (默认true)
* @returns 是否成功消耗 * @returns 是否成功消耗
*/ */
spendGold(amount: number, autoSave: boolean = true): boolean { async spendGameProperty(property: string, value: any, autoSave: boolean = true): Promise<boolean> {
const currentGold = this.getGameProperty("gold", 0); const currentValue = this.data[property] || 0;
if (currentGold < amount) { if (currentValue < value) {
console.warn(`[SMC]: 金币不足,当前: ${currentGold}, 需要: ${amount}`); console.warn(`[SMC]: ${property} 不足,当前: ${currentValue}, 需要: ${value}`);
return false; return false;
} }
const newValue = currentValue - value;
this.addGold(-amount, autoSave); this.data[property] = newValue;
this.vmdata.data[property] = newValue;
console.log(`[SMC]: 消耗游戏数据 ${property} = ${value}, 当前值: ${newValue}`);
return true; return true;
} }
/**
* 增加钻石
* @param amount 钻石数量
* @param autoSave 是否自动保存 (默认true)
*/
addDiamond(amount: number, autoSave: boolean = true) {
const currentDiamond = this.getGameProperty("diamond", 0);
const newDiamond = Math.max(0, currentDiamond + amount);
this.setGameProperty("diamond", newDiamond, autoSave);
console.log(`[SMC]: 钻石变更: ${currentDiamond} -> ${newDiamond} (${amount > 0 ? '+' : ''}${amount})`);
return newDiamond;
}
/**
* 消耗钻石
* @param amount 消耗数量
* @param autoSave 是否自动保存 (默认true)
* @returns 是否成功消耗
*/
spendDiamond(amount: number, autoSave: boolean = true): boolean {
const currentDiamond = this.getGameProperty("diamond", 0);
if (currentDiamond < amount) {
console.warn(`[SMC]: 钻石不足,当前: ${currentDiamond}, 需要: ${amount}`);
return false;
}
this.addDiamond(-amount, autoSave);
return true;
}
/**
* 增加关卡进度
* @param amount 增加的关卡数 (默认1)
* @param autoSave 是否自动保存 (默认true)
*/
addMission(amount: number = 1, autoSave: boolean = true) {
const currentMission = this.getGameProperty("mission", 1);
const newMission = currentMission + amount;
this.setGameProperty("mission", newMission, autoSave);
console.log(`[SMC]: 关卡进度增加: ${currentMission} -> ${newMission} (+${amount})`);
// 计算章节和关卡等级
// this.vmdata.mission_data.chapter = Math.floor((newMission - 1) / 10) + 1
// this.vmdata.mission_data.level = ((newMission - 1) % 10) + 1
return newMission;
}
/**
* 增加分数
* @param score 分数
* @param autoSave 是否自动保存 (默认true)
*/
addScore(score: number, autoSave: boolean = true) {
const currentScore = this.getGameProperty("score", 0);
const newScore = currentScore + score;
this.setGameProperty("score", newScore, autoSave);
console.log(`[SMC]: 分数增加: ${currentScore} -> ${newScore} (+${score})`);
return newScore;
}
/**
* 重置游戏数据为默认值
* @param autoSave 是否自动保存 (默认true)
*/
resetGameData(autoSave: boolean = true) {
this.data = {
score: 888,
mission: 1,
gold: 100,
diamond: 100,
};
console.log("[SMC]: 游戏数据已重置为默认值:", this.data);
if (autoSave) {
this.saveGameData();
}
}
/**
* 检查本地存储状态(调试用)
*/
checkLocalStorage() {
const fightHeros = oops.storage.get("fight_heros");
const heros = oops.storage.get("heros");
const gameData = oops.storage.get("game_data");
console.log("[SMC]: 本地存储状态检查:");
console.log(" - fight_heros:", fightHeros ? "存在" : "不存在", fightHeros);
console.log(" - heros:", heros ? "存在" : "不存在", heros);
console.log(" - game_data:", gameData ? "存在" : "不存在", gameData);
return {
hasFightHeros: !!fightHeros,
hasHeros: !!heros,
hasGameData: !!gameData,
isFirstTime: !fightHeros && !heros && !gameData
};
}
} }
export var smc: SingletonModuleComp = ecs.getSingleton(SingletonModuleComp); export var smc: SingletonModuleComp = ecs.getSingleton(SingletonModuleComp);

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "58714c1c-3ffe-4ad1-959a-82e5dfeb2dc3", "uuid": "58714c1c-3ffe-4ad1-959a-82e5dfeb2dc3",

View File

@@ -0,0 +1,49 @@
import { oops } from "db://oops-framework/core/Oops"
export class Test{
load_data_from_local() {
let local_data = this.get_local_data()
if(!local_data.data||!local_data.fight_heros||!local_data.heros||!local_data.items||!local_data.tals||!local_data.equips){
return this.init_local_data()
}
return local_data
}
get_local_data(){
let local_data ={
user_id: "local_debug",
openid: "local_debug",
regist_time: Date.now(),
data: JSON.parse(oops.storage.get("data")),
fight_heros: JSON.parse(oops.storage.get("fight_heros")),
heros: JSON.parse(oops.storage.get("heros")),
items: JSON.parse(oops.storage.get("items")),
tals: JSON.parse(oops.storage.get("tals")),
equips: JSON.parse(oops.storage.get("equips"))
}
return local_data
}
init_local_data(){
let init_data = {
data : {
score: 0, mission: 1, gold: 100, diamond: 100, meat: 0, exp: 0,
ghstone: 0, bhstone: 0, phlestone: 0, rhstone: 0, herocard: 0,
ckey: 0, skey: 0, gkey: 0,},
fight_heros: { 0: 0, 1: 0, 2: 0, 3: 0, 4: 0 },
heros: {
5001: { uuid: 5001, lv: 1 },
5005: { uuid: 5005, lv: 1 },
5007: { uuid: 5007, lv: 1 }
},
items: {},
tals: {},
equips: {}
}
oops.storage.set("data", JSON.stringify(init_data.data))
oops.storage.set("fight_heros", JSON.stringify(init_data.fight_heros))
oops.storage.set("heros", JSON.stringify(init_data.heros))
oops.storage.set("items", JSON.stringify(init_data.items))
oops.storage.set("tals", JSON.stringify(init_data.tals))
oops.storage.set("equips", JSON.stringify(init_data.equips))
return this.get_local_data()
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "893646a7-1cf0-4c80-8fe1-39ac111130fc",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "28d11009-6d68-462a-9880-8b31cf5975fd", "uuid": "28d11009-6d68-462a-9880-8b31cf5975fd",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "ffda71d7-624d-40de-8c09-712edd44bfdc", "uuid": "ffda71d7-624d-40de-8c09-712edd44bfdc",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "6f6a81bc-e767-4001-b181-2c18c896cfd0", "uuid": "6f6a81bc-e767-4001-b181-2c18c896cfd0",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "28ac0ad6-53bf-471a-9256-ae7c8ad351a7", "uuid": "28ac0ad6-53bf-471a-9256-ae7c8ad351a7",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "14663cf6-fb92-4921-8ba9-c836b2667737", "uuid": "14663cf6-fb92-4921-8ba9-c836b2667737",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "49217bd4-ee11-49f7-b404-e8d40478fa2d", "uuid": "49217bd4-ee11-49f7-b404-e8d40478fa2d",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "bbef9ac6-154b-4e27-9c56-e964e27ef2d5", "uuid": "bbef9ac6-154b-4e27-9c56-e964e27ef2d5",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "26aee2e6-ab33-4155-a0aa-221c6be8d030", "uuid": "26aee2e6-ab33-4155-a0aa-221c6be8d030",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "167eb23c-6d7e-4e30-96ca-06fec16eeaa8", "uuid": "167eb23c-6d7e-4e30-96ca-06fec16eeaa8",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "0388f0b8-c77d-4020-8b9a-dabf774f6502", "uuid": "0388f0b8-c77d-4020-8b9a-dabf774f6502",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "bde4950f-acae-4c3e-a6a7-39248c34613d", "uuid": "bde4950f-acae-4c3e-a6a7-39248c34613d",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "bb894d46-7785-4e72-9314-8e384a338ab3", "uuid": "bb894d46-7785-4e72-9314-8e384a338ab3",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "5fdc5c44-f438-4c0e-8c5c-a2673d49aafd", "uuid": "5fdc5c44-f438-4c0e-8c5c-a2673d49aafd",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "91ba5d4e-bef8-4b0d-8c64-7ce0f37e43d2", "uuid": "91ba5d4e-bef8-4b0d-8c64-7ce0f37e43d2",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "196aaacb-556c-4bb2-925c-9a70dc3e56fc", "uuid": "196aaacb-556c-4bb2-925c-9a70dc3e56fc",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "9f62614b-42c3-4f21-a3d6-68c9190082e8", "uuid": "9f62614b-42c3-4f21-a3d6-68c9190082e8",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "b44c446b-ce5f-4079-ac42-269837dbf580", "uuid": "b44c446b-ce5f-4079-ac42-269837dbf580",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "d26fa84f-22b4-4136-bb46-d7e978683365", "uuid": "d26fa84f-22b4-4136-bb46-d7e978683365",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "cb9afa42-2112-471e-b86c-79407ba6abd4", "uuid": "cb9afa42-2112-471e-b86c-79407ba6abd4",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "0aefc30a-9392-4ada-b3d0-8c15625e8cfc", "uuid": "0aefc30a-9392-4ada-b3d0-8c15625e8cfc",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "8ae6d033-ff0f-44d5-9ff7-c57751bd4ea1", "uuid": "8ae6d033-ff0f-44d5-9ff7-c57751bd4ea1",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "4209bcee-3867-4c0b-83c9-a4eeee989328", "uuid": "4209bcee-3867-4c0b-83c9-a4eeee989328",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "7eb34351-e975-447f-bf07-0a2e5e00a2e6", "uuid": "7eb34351-e975-447f-bf07-0a2e5e00a2e6",

View File

@@ -1 +1,9 @@
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"31289da2-91ea-4ffe-85f3-879a3ac7641d","files":[],"subMetas":{},"userData":{}} {
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "31289da2-91ea-4ffe-85f3-879a3ac7641d",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1 +1,9 @@
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"d8a3d973-c3c2-449f-82bd-adb9f6d5149d","files":[],"subMetas":{},"userData":{}} {
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "d8a3d973-c3c2-449f-82bd-adb9f6d5149d",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -17,7 +17,6 @@ export default class HeroAnmComp extends Component{
stop () { stop () {
// this.spine?.clearTrack(0);
this._hasStop = true; this._hasStop = true;
} }
onAnimationFinished(type:Animation.EventType, state:AnimationState){ onAnimationFinished(type:Animation.EventType, state:AnimationState){

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "4ba4ac2e-cfcb-45df-8aea-e13919f56d52", "uuid": "4ba4ac2e-cfcb-45df-8aea-e13919f56d52",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "846e0307-e55e-4bc3-a9db-b387c89ad671", "uuid": "846e0307-e55e-4bc3-a9db-b387c89ad671",

View File

@@ -1 +1,9 @@
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"c9121e83-b457-492d-aa56-2119d79a3360","files":[],"subMetas":{},"userData":{}} {
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "c9121e83-b457-492d-aa56-2119d79a3360",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1 +1,9 @@
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"a03797e6-86f0-4771-b35c-045fe5e373bc","files":[],"subMetas":{},"userData":{}} {
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "a03797e6-86f0-4771-b35c-045fe5e373bc",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1 +1,9 @@
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"873f877e-4a89-4c12-8f03-8934f1651878","files":[],"subMetas":{},"userData":{}} {
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "873f877e-4a89-4c12-8f03-8934f1651878",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1 +1,9 @@
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"c1d7128f-5af5-4f7c-b4a1-6bb6fd4f12e0","files":[],"subMetas":{},"userData":{}} {
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "c1d7128f-5af5-4f7c-b4a1-6bb6fd4f12e0",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "118ca580-773a-458b-8544-ab6c3cb2b376", "uuid": "118ca580-773a-458b-8544-ab6c3cb2b376",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "6f882a1f-6f5a-4ef5-9ea0-21a0192c2785", "uuid": "6f882a1f-6f5a-4ef5-9ea0-21a0192c2785",

View File

@@ -12,8 +12,9 @@ import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ec
import { UIID } from "../common/config/GameUIConfig"; import { UIID } from "../common/config/GameUIConfig";
import { LoadingViewComp } from "./view/LoadingViewComp"; import { LoadingViewComp } from "./view/LoadingViewComp";
import { smc } from "../common/SingletonModuleComp"; import { smc } from "../common/SingletonModuleComp";
import { WxCloudApi } from "../wx_clound_client_api/WxCloudApi"; import { WxCloudApi, UserGameData } from "../wx_clound_client_api/WxCloudApi";
import { GameDataSyncManager } from "../common/GameDataSyncManager";
import { Test } from "../common/Test";
// import {data} from "../data/data"; // import {data} from "../data/data";
/** /**
@@ -47,18 +48,20 @@ export class Initialize extends ecs.Entity {
/** 加载自定义内容(可选) */ /** 加载自定义内容(可选) */
private loadCustom(queue: AsyncQueue) { private loadCustom(queue: AsyncQueue) {
queue.push(async (next: NextFunction, params: any, args: any) => { queue.push(async (next: NextFunction, params: any, args: any) => {
try {
// 加载多语言对应字体 // 加载多语言对应字体
oops.res.load("language/font/" + oops.language.current, () => { oops.res.load("language/font/" + oops.language.current, async () => {
// 加载本地英雄数据 // 统一的数据加载流程
this.loadHeroDataFromLocal(); await this.loadGameDataUnified();
// 判断是否为微信客户端,是的话才加载云端数据
if (this.isWxClient()) {
this.loadWxDataFromCloud();
}
next(); next();
}); });
//加载精灵配置表 //加载精灵配置表
// oops.res.load("config/game/heros", next); // oops.res.load("config/game/heros", next);
} catch (error) {
console.error("[Initialize]: 自定义内容加载失败:", error);
next(); // 即使失败也要继续,不阻塞游戏启动
}
}); });
} }
@@ -96,43 +99,88 @@ export class Initialize extends ecs.Entity {
return typeof wx !== 'undefined' && typeof (wx as any).getSystemInfoSync === 'function'; return typeof wx !== 'undefined' && typeof (wx as any).getSystemInfoSync === 'function';
} }
private loadWxDataFromCloud() {
WxCloudApi.login().then(loginRes=>{
console.log("login res", loginRes);
});
}
/** /**
* 从本地存储加载游戏数据 * 统一的游戏数据加载流程
* 微信客户端:使用云端数据
* 非微信客户端:使用本地调试数据
*/ */
private loadHeroDataFromLocal() { private async loadGameDataUnified() {
// 检查本地存储状态 try {
const storageStatus = smc.checkLocalStorage(); console.log("[Initialize]: 开始统一数据加载流程...");
if (storageStatus.isFirstTime) { if (this.isWxClient()) {
console.log("[Initialize]: 检测到首次启动游戏"); // 微信客户端:加载云端数据
} console.log("[Initialize]: 检测到微信客户端,使用云端数据");
await this.loadFromCloud();
// 使用SingletonModuleComp的加载方法
// loadGameData方法已经包含了首次启动的处理逻辑
const success = smc.loadGameData();
if (success) {
console.log("[Initialize]: 游戏数据加载完成");
} else { } else {
console.log("[Initialize]: 游戏数据加载失败,使用默认配置"); // 非微信客户端:使用本地调试数据
// 如果加载失败,初始化默认数据并保存 console.log("[Initialize]: 非微信客户端,使用本地调试数据");
smc.initDefaultData(); await this.loadFromLocalDebug();
smc.saveGameData();
} }
// 再次检查存储状态,确认数据已保存 } catch (error) {
if (storageStatus.isFirstTime) { console.error("[Initialize]: 统一数据加载失败:", error);
const newStatus = smc.checkLocalStorage(); // 失败时使用默认数据 游戏需要退出
if (newStatus.hasFightHeros && newStatus.hasHeros && newStatus.hasGameData) {
console.log("[Initialize]: 首次启动数据保存成功");
} else {
console.warn("[Initialize]: 首次启动数据保存可能失败");
} }
} }
/**
* 从云端加载数据(微信客户端)
*/
private async loadFromCloud() {
try {
// 1. 初始化微信云环境
this.initWxCloudEnv();
// 2. 登录并获取云端数据
const loginResult = await WxCloudApi.login();
const response = loginResult.result;
if (response.code === 200) {
console.log("[Initialize]: 云端登录成功");
const cloudData = response.data;
// 3. 用云端数据覆盖本地数据
GameDataSyncManager.getInstance().overrideLocalDataWithRemote(cloudData, "云端");
} else {
console.warn("[Initialize]: 云端登录失败:", response.msg);
// 登录失败时使用本地数据 游戏需要退出
console.log("[Initialize]: 云端登录失败:", response.msg);
}
} catch (error) {
console.error("[Initialize]: 云端数据加载异常:", error);
// 异常时使用本地数据 游戏需要退出
}
}
/**
* 从本地调试数据加载(非微信客户端)
*/
private async loadFromLocalDebug() {
try {
// 使用本地调试API模拟云端接口
const loginResult = new Test().load_data_from_local()
// 用本地调试数据覆盖客户端数据
GameDataSyncManager.getInstance().overrideLocalDataWithRemote(loginResult, "本地调试");
} catch (error) {
console.error("[Initialize]: 本地调试数据加载异常:", error);
}
}
/**
* 初始化微信云环境
*/
private initWxCloudEnv() {
try {
// 请替换为您的实际云环境ID
const cloudEnvId = "cloud1-6gknw0qk911036d8"; // TODO: 配置您的云环境ID
WxCloudApi.init(cloudEnvId);
console.log("[Initialize]: 微信云环境初始化完成");
} catch (error) {
console.error("[Initialize]: 微信云环境初始化失败:", error);
}
} }
/** 加载完成进入游戏内容加载界面 */ /** 加载完成进入游戏内容加载界面 */

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "ffbce42c-e99f-48a0-8e73-ea6b756af330", "uuid": "ffbce42c-e99f-48a0-8e73-ea6b756af330",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "92429ca4-4e7c-450a-b706-c96e7c2568e3", "uuid": "92429ca4-4e7c-450a-b706-c96e7c2568e3",

View File

@@ -364,11 +364,11 @@ export class CardComp extends CCComp {
this.reset_card() this.reset_card()
} }
cost_gold_check(){ cost_gold_check(){
if(smc.vmdata.mission_data.gold< this.cost_gold){ if(smc.vmdata.data.gold< this.cost_gold){
oops.gui.toast("[cardcomp]:金币不足", false); oops.gui.toast("[cardcomp]:金币不足", false);
return false return false
} }
smc.vmdata.mission_data.gold-=this.cost_gold smc.vmdata.data.gold-=this.cost_gold
return true return true
} }
reset() { reset() {

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "e06b1406-878e-482d-99dd-46eb7ed2c7a8", "uuid": "e06b1406-878e-482d-99dd-46eb7ed2c7a8",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "ee99b110-f3d9-44b5-abc0-1d0b18dac6da", "uuid": "ee99b110-f3d9-44b5-abc0-1d0b18dac6da",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "3d183133-c60d-44c0-933f-a629bea43331", "uuid": "3d183133-c60d-44c0-933f-a629bea43331",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "df953176-a9fa-4f3e-865e-7956fccc4c52", "uuid": "df953176-a9fa-4f3e-865e-7956fccc4c52",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "d15fc8d4-c897-4a5c-a97c-b65114b41a69", "uuid": "d15fc8d4-c897-4a5c-a97c-b65114b41a69",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "d625f285-3706-4f2e-bf30-e03e34f16650", "uuid": "d625f285-3706-4f2e-bf30-e03e34f16650",

View File

@@ -56,16 +56,17 @@ export class HInfoComp extends Component {
this.node.getChildByName("luck").active=lv == 0 this.node.getChildByName("luck").active=lv == 0
} }
uplevel(){ uplevel(){
let hero_data = HeroInfo[this.h_uuid]
let lv=smc.heros[this.h_uuid].lv let lv=smc.heros[this.h_uuid].lv
let {experience,gold}=getUpgradeResources(lv) let {experience,gold}=getUpgradeResources(lv)
if(smc.vmdata.mission_data.exp<=experience||smc.vmdata.mission_data.gold<=gold){ if(smc.vmdata.data.exp<=experience||smc.vmdata.data.gold<=gold){
oops.gui.toast("经验或金币不足") oops.gui.toast("经验或金币不足")
return return
} }
smc.spendGameProperty("exp",experience) let result=smc.levelUpHero(this.h_uuid,experience,gold)
smc.spendGameProperty("gold",gold) if(!result){
smc.levelUpHero(this.h_uuid) oops.gui.toast("网络出错了,升级失败,请重试")
return
}
this.update_data(this.h_uuid) this.update_data(this.h_uuid)
oops.message.dispatchEvent(GameEvent.UpdateHero, {}) oops.message.dispatchEvent(GameEvent.UpdateHero, {})
} }

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "f8dd2383-61ab-4cf9-9879-0d0fe2cd6c2f", "uuid": "f8dd2383-61ab-4cf9-9879-0d0fe2cd6c2f",

View File

@@ -38,9 +38,9 @@ export class HeroPageComp extends Component {
console.error("[Skill] 预制体加载失败:", path); console.error("[Skill] 预制体加载失败:", path);
return; return;
} }
const node = instantiate(prefab); const node = instantiate(prefab) as unknown as Node;
node.parent=parent node.parent = parent;
let hcard=node.getComponent(HCardUICom)! let hcard = node.getComponent(HCardUICom)!;
hcard.update_data(uuid,{type:HeroConSet.INFO}) hcard.update_data(uuid,{type:HeroConSet.INFO})
} }
clear_heros(){ clear_heros(){

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "985ee2ae-8a25-4d68-a4f3-d909f5b2c225", "uuid": "985ee2ae-8a25-4d68-a4f3-d909f5b2c225",

View File

@@ -24,6 +24,7 @@ export class HeroReadyCom extends Component {
} }
update_hero(){ update_hero(){
let hero = smc.fight_heros[this.slot] let hero = smc.fight_heros[this.slot]
console.log("[HeroReadyCom]hero",hero,smc.fight_heros,this.slot)
if(hero==0){ if(hero==0){
this.no_hero() this.no_hero()
return return

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "11781c25-08d5-41fc-af3e-b2dfd46dc5d7", "uuid": "11781c25-08d5-41fc-af3e-b2dfd46dc5d7",

View File

@@ -50,9 +50,9 @@ export class HeroSelectCom extends Component {
console.error("[Skill] 预制体加载失败:", path); console.error("[Skill] 预制体加载失败:", path);
return; return;
} }
const node = instantiate(prefab); const node = instantiate(prefab) as unknown as Node;
node.parent=parent node.parent = parent;
let hcard=node.getComponent(HCardUICom)! let hcard = node.getComponent(HCardUICom)!;
hcard.update_data(uuid,{type:HeroConSet.SELECT,slot:this.slot}) hcard.update_data(uuid,{type:HeroConSet.SELECT,slot:this.slot})
} }

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "0c9b9c74-9486-4b43-b797-f602d26f2f1a", "uuid": "0c9b9c74-9486-4b43-b797-f602d26f2f1a",

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "598155fc-f31b-4496-b1e4-82219435f425", "uuid": "598155fc-f31b-4496-b1e4-82219435f425",

View File

@@ -1 +1,9 @@
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"e0acc008-a00f-4682-ba4f-c47506bddf26","files":[],"subMetas":{},"userData":{}} {
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "e0acc008-a00f-4682-ba4f-c47506bddf26",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,5 +1,5 @@
{ {
"ver": "4.0.23", "ver": "4.0.24",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "3748c53e-6b9b-479f-aba0-87fc123ce161", "uuid": "3748c53e-6b9b-479f-aba0-87fc123ce161",

View File

@@ -55,7 +55,7 @@ export class MissionComp extends CCComp {
oops.message.dispatchEvent(GameEvent.NewWave) oops.message.dispatchEvent(GameEvent.NewWave)
return return
} }
smc.addMission(1) smc.addGameProperty("mission",1)
oops.message.dispatchEvent(GameEvent.FightEnd,{victory:true}) oops.message.dispatchEvent(GameEvent.FightEnd,{victory:true})
oops.gui.open(UIID.Victory,{victory:true}) oops.gui.open(UIID.Victory,{victory:true})
} }
@@ -135,7 +135,6 @@ export class MissionComp extends CCComp {
smc.vmdata.mission_data.in_fight=false smc.vmdata.mission_data.in_fight=false
smc.vmdata.mission_data.fight_time=0 smc.vmdata.mission_data.fight_time=0
smc.vmdata.mission_data.level=0 smc.vmdata.mission_data.level=0
smc.initReward()
console.log("[MissionComp]局内数据初始化",smc.vmdata.mission_data) console.log("[MissionComp]局内数据初始化",smc.vmdata.mission_data)
} }

Some files were not shown because too many files have changed in this diff Show More