feat: 支持本地存储关卡进度

This commit is contained in:
richarjiang
2026-03-16 21:49:55 +08:00
parent 45bb6b35ae
commit 9899f696b2
7 changed files with 1931 additions and 12 deletions

View File

@@ -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