feat: 支持本地存储关卡进度
This commit is contained in:
@@ -94,12 +94,20 @@ export class PageLevel extends BaseView {
|
||||
*/
|
||||
onViewLoad(): void {
|
||||
console.log('[PageLevel] onViewLoad');
|
||||
// 从本地存储恢复关卡进度
|
||||
this.currentLevelIndex = StorageManager.getCurrentLevelIndex();
|
||||
console.log(`[PageLevel] 恢复关卡进度: 第 ${this.currentLevelIndex + 1} 关`);
|
||||
this.updateLiveLabel();
|
||||
this.initLevel();
|
||||
this.initIconSetting();
|
||||
this.initUnlockButtons();
|
||||
this.initSubmitButton();
|
||||
this.startCountdown();
|
||||
|
||||
// 异步加载关卡资源,完成后启动倒计时
|
||||
this.initLevel().then(() => {
|
||||
this.startCountdown();
|
||||
}).catch(err => {
|
||||
console.error('[PageLevel] 加载关卡失败:', err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,10 +135,18 @@ export class PageLevel extends BaseView {
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化关卡(从 API 数据加载)
|
||||
* 初始化关卡(从 API 数据加载,异步确保资源就绪)
|
||||
*/
|
||||
private initLevel(): void {
|
||||
const config = LevelDataManager.instance.getLevelConfig(this.currentLevelIndex);
|
||||
private async initLevel(): Promise<void> {
|
||||
// 先尝试从缓存获取
|
||||
let config = LevelDataManager.instance.getLevelConfig(this.currentLevelIndex);
|
||||
|
||||
if (!config) {
|
||||
// 缓存中没有,异步加载
|
||||
console.log(`[PageLevel] 关卡 ${this.currentLevelIndex + 1} 资源未缓存,开始加载...`);
|
||||
config = await LevelDataManager.instance.ensureLevelReady(this.currentLevelIndex);
|
||||
}
|
||||
|
||||
if (!config) {
|
||||
console.warn(`[PageLevel] 没有找到关卡配置,索引: ${this.currentLevelIndex}`);
|
||||
return;
|
||||
@@ -673,7 +689,10 @@ export class PageLevel extends BaseView {
|
||||
/**
|
||||
* 进入下一关
|
||||
*/
|
||||
private nextLevel(): void {
|
||||
private async nextLevel(): Promise<void> {
|
||||
// 保存当前关卡进度
|
||||
StorageManager.onLevelCompleted(this.currentLevelIndex);
|
||||
|
||||
this.currentLevelIndex++;
|
||||
|
||||
// 检查是否还有关卡
|
||||
@@ -688,7 +707,7 @@ export class PageLevel extends BaseView {
|
||||
}
|
||||
|
||||
// 重置并加载下一关,重新开始倒计时
|
||||
this.initLevel();
|
||||
await this.initLevel();
|
||||
this.startCountdown();
|
||||
console.log(`[PageLevel] 进入关卡 ${this.currentLevelIndex + 1}`);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user