本地数据存取 完成
This commit is contained in:
@@ -11,6 +11,7 @@ import { AsyncQueue, NextFunction } from "../../../../extensions/oops-plugin-fra
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { UIID } from "../common/config/GameUIConfig";
|
||||
import { LoadingViewComp } from "./view/LoadingViewComp";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
|
||||
|
||||
// import {data} from "../data/data";
|
||||
@@ -46,10 +47,13 @@ export class Initialize extends ecs.Entity {
|
||||
private loadCustom(queue: AsyncQueue) {
|
||||
queue.push(async (next: NextFunction, params: any, args: any) => {
|
||||
// 加载多语言对应字体
|
||||
oops.res.load("language/font/" + oops.language.current, next);
|
||||
oops.res.load("language/font/" + oops.language.current, () => {
|
||||
// 加载本地英雄数据
|
||||
this.loadHeroDataFromLocal();
|
||||
next();
|
||||
});
|
||||
//加载精灵配置表
|
||||
// oops.res.load("config/game/heros", next);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -80,6 +84,40 @@ export class Initialize extends ecs.Entity {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 从本地存储加载游戏数据
|
||||
*/
|
||||
private loadHeroDataFromLocal() {
|
||||
// 检查本地存储状态
|
||||
const storageStatus = smc.checkLocalStorage();
|
||||
|
||||
if (storageStatus.isFirstTime) {
|
||||
console.log("[Initialize]: 检测到首次启动游戏");
|
||||
}
|
||||
|
||||
// 使用SingletonModuleComp的加载方法
|
||||
// loadGameData方法已经包含了首次启动的处理逻辑
|
||||
const success = smc.loadGameData();
|
||||
if (success) {
|
||||
console.log("[Initialize]: 游戏数据加载完成");
|
||||
} else {
|
||||
console.log("[Initialize]: 游戏数据加载失败,使用默认配置");
|
||||
// 如果加载失败,初始化默认数据并保存
|
||||
smc.initDefaultData();
|
||||
smc.saveGameData();
|
||||
}
|
||||
|
||||
// 再次检查存储状态,确认数据已保存
|
||||
if (storageStatus.isFirstTime) {
|
||||
const newStatus = smc.checkLocalStorage();
|
||||
if (newStatus.hasFightHeros && newStatus.hasHeros && newStatus.hasGameData) {
|
||||
console.log("[Initialize]: 首次启动数据保存成功");
|
||||
} else {
|
||||
console.warn("[Initialize]: 首次启动数据保存可能失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 加载完成进入游戏内容加载界面 */
|
||||
private onComplete(queue: AsyncQueue) {
|
||||
queue.complete = () => {
|
||||
|
||||
Reference in New Issue
Block a user