feat: 支持登录、个人信息存储
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { SpriteFrame, Texture2D, ImageAsset, assetManager } from 'cc';
|
||||
import { HttpUtil } from './HttpUtil';
|
||||
import { ApiLevelData, ApiResponse, RuntimeLevelConfig } from '../types/LevelTypes';
|
||||
import { API_ENDPOINTS, API_TIMEOUT } from '../config/ApiConfig';
|
||||
|
||||
/**
|
||||
* 进度回调类型
|
||||
@@ -16,12 +17,6 @@ export type ProgressCallback = (progress: number, message: string) => void;
|
||||
export class LevelDataManager {
|
||||
private static _instance: LevelDataManager | null = null;
|
||||
|
||||
/** API 地址 */
|
||||
private readonly API_URL = 'https://ilookai.cn/api/v1/wechat-game/levels';
|
||||
|
||||
/** 请求超时时间(毫秒) */
|
||||
private readonly REQUEST_TIMEOUT = 8000;
|
||||
|
||||
/** API 请求重试次数 */
|
||||
private readonly API_RETRY_COUNT = 2;
|
||||
|
||||
@@ -114,6 +109,28 @@ export class LevelDataManager {
|
||||
return this._apiData.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据已完成的关卡 ID 列表,计算最高已完成关卡索引
|
||||
* @param completedLevelIds 服务端返回的已完成关卡 ID
|
||||
* @returns 最高已完成关卡的索引(0-based),无匹配返回 -1
|
||||
*/
|
||||
getMaxCompletedIndex(completedLevelIds: string[]): number {
|
||||
if (!this._hasApiData || completedLevelIds.length === 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
const completedSet = new Set(completedLevelIds);
|
||||
let maxIndex = -1;
|
||||
|
||||
for (let i = 0; i < this._apiData.length; i++) {
|
||||
if (completedSet.has(this._apiData[i].id)) {
|
||||
maxIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
return maxIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有 API 数据
|
||||
*/
|
||||
@@ -220,7 +237,7 @@ export class LevelDataManager {
|
||||
try {
|
||||
onProgress?.(progress, `正在请求服务端数据 (第${attempt}次)...`);
|
||||
|
||||
const response = await HttpUtil.get<ApiResponse>(this.API_URL, this.REQUEST_TIMEOUT);
|
||||
const response = await HttpUtil.get<ApiResponse>(API_ENDPOINTS.LEVELS, API_TIMEOUT.DEFAULT);
|
||||
|
||||
if (!response.success) {
|
||||
console.warn(`[LevelDataManager] API 返回失败, 消息: ${response.message}`);
|
||||
|
||||
Reference in New Issue
Block a user