feat: 进入关卡时 toast 提示体力消耗,修复 StorageManager 接口位置和 WxSDK 访问级别
- 进入关卡成功后显示 toast 提示消耗体力及剩余体力 - 将 StorageManager 中 UserInfo 接口移至模块顶层,修复嵌套接口语法问题 - WxSDK.getWx() 改为 static 公开方法,便于外部调用
This commit is contained in:
@@ -109,6 +109,45 @@ export class LevelDataManager {
|
||||
return this._apiData.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定索引的关卡 ID
|
||||
* @param index 关卡索引
|
||||
*/
|
||||
getLevelId(index: number): string | null {
|
||||
if (index < 0 || index >= this._apiData.length) {
|
||||
return null;
|
||||
}
|
||||
return this._apiData[index].id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查指定索引的关卡是否已通关
|
||||
* @param index 关卡索引
|
||||
*/
|
||||
isLevelCompleted(index: number): boolean {
|
||||
if (index < 0 || index >= this._apiData.length) {
|
||||
return false;
|
||||
}
|
||||
return this._apiData[index].completed;
|
||||
}
|
||||
|
||||
/**
|
||||
* 标记指定关卡为已通关(本地缓存更新)
|
||||
* @param index 关卡索引
|
||||
*/
|
||||
markLevelCompleted(index: number): void {
|
||||
if (index < 0 || index >= this._apiData.length) {
|
||||
return;
|
||||
}
|
||||
this._apiData[index].completed = true;
|
||||
|
||||
// 同时更新运行时配置的 completed 状态
|
||||
const config = this._levelConfigs.get(index);
|
||||
if (config) {
|
||||
this._levelConfigs.set(index, { ...config, completed: true });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据已完成的关卡 ID 列表,计算最高已完成关卡索引
|
||||
* @param completedLevelIds 服务端返回的已完成关卡 ID
|
||||
@@ -191,6 +230,27 @@ export class LevelDataManager {
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用 enter 接口返回的数据更新运行时关卡配置(填充答案和线索)
|
||||
*/
|
||||
updateLevelDetails(index: number, details: { answer: string; hint1: string | null; hint2: string | null; hint3: string | null }): void {
|
||||
const config = this._levelConfigs.get(index);
|
||||
if (!config) {
|
||||
console.warn(`[LevelDataManager] 关卡 ${index} 配置不存在,无法更新详情`);
|
||||
return;
|
||||
}
|
||||
|
||||
this._levelConfigs.set(index, {
|
||||
...config,
|
||||
answer: details.answer,
|
||||
clue1: details.hint1 ?? null,
|
||||
clue2: details.hint2 ?? null,
|
||||
clue3: details.hint3 ?? null,
|
||||
});
|
||||
|
||||
console.log(`[LevelDataManager] 关卡 ${index} 详情已更新`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 预加载下一关图片(静默加载,不阻塞)
|
||||
* 在进入当前关卡后调用,提前加载下一关资源
|
||||
@@ -278,7 +338,8 @@ export class LevelDataManager {
|
||||
clue1: data.hint1,
|
||||
clue2: data.hint2,
|
||||
clue3: data.hint3,
|
||||
answer: data.answer
|
||||
answer: data.answer,
|
||||
completed: data.completed,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user