feat: 对接最新的关卡工作流
This commit is contained in:
@@ -2,7 +2,7 @@ import { HttpUtil } from './HttpUtil';
|
||||
import { StorageManager } from './StorageManager';
|
||||
import { WxSDK } from './WxSDK';
|
||||
import { API_ENDPOINTS, API_TIMEOUT } from '../config/ApiConfig';
|
||||
import { ApiEnvelope, WxLoginData, GameData } from '../types/ApiTypes';
|
||||
import { ApiEnvelope, WxLoginData, GameData, NextLevelData } from '../types/ApiTypes';
|
||||
|
||||
/**
|
||||
* 认证管理器
|
||||
@@ -13,10 +13,10 @@ export class AuthManager {
|
||||
|
||||
private _userId: string = '';
|
||||
private _isLoggedIn: boolean = false;
|
||||
/** 服务端返回的已完成关卡 ID(登录后暂存,等 LevelDataManager 就绪后同步) */
|
||||
private _completedLevelIds: string[] = [];
|
||||
/** 服务端返回的已完成关卡数量,用于称号体系计算 */
|
||||
private _completedLevelCount: number = 0;
|
||||
/** game-data 返回的下一关数据,供 PageLoading 传给 LevelDataManager */
|
||||
private _nextLevel: NextLevelData | null = null;
|
||||
|
||||
static get instance(): AuthManager {
|
||||
if (!this._instance) {
|
||||
@@ -35,14 +35,15 @@ export class AuthManager {
|
||||
return this._userId;
|
||||
}
|
||||
|
||||
get completedLevelIds(): string[] {
|
||||
return this._completedLevelIds;
|
||||
}
|
||||
|
||||
get completedLevelCount(): number {
|
||||
return this._completedLevelCount;
|
||||
}
|
||||
|
||||
/** 获取 game-data 返回的下一关数据 */
|
||||
get nextLevel(): NextLevelData | null {
|
||||
return this._nextLevel;
|
||||
}
|
||||
|
||||
addCompletedLevelCount(delta: number = 1): void {
|
||||
this._completedLevelCount = Math.max(0, this._completedLevelCount + delta);
|
||||
}
|
||||
@@ -118,21 +119,21 @@ export class AuthManager {
|
||||
this._userId = gameData.user.id;
|
||||
this._isLoggedIn = true;
|
||||
StorageManager.setStamina(gameData.user.stamina);
|
||||
this._completedLevelIds = gameData.completedLevelIds;
|
||||
this._completedLevelCount = this._resolveCompletedLevelCount(gameData);
|
||||
this._completedLevelCount = gameData.completedLevelCount;
|
||||
this._nextLevel = gameData.nextLevel;
|
||||
|
||||
console.log(`[AuthManager] Token 验证成功,体力: ${gameData.user.stamina.current}/${gameData.user.stamina.max},已完成: ${this._completedLevelCount} 关`);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录成功后获取游戏数据(体力 + 通关进度)
|
||||
* 登录成功后获取游戏数据(体力 + 通关进度 + 下一关)
|
||||
*/
|
||||
private async fetchGameData(): Promise<void> {
|
||||
const gameData = await this._fetchGameData();
|
||||
if (gameData) {
|
||||
this._completedLevelIds = gameData.completedLevelIds;
|
||||
this._completedLevelCount = this._resolveCompletedLevelCount(gameData);
|
||||
this._completedLevelCount = gameData.completedLevelCount;
|
||||
this._nextLevel = gameData.nextLevel;
|
||||
StorageManager.setStamina(gameData.user.stamina);
|
||||
}
|
||||
}
|
||||
@@ -152,8 +153,4 @@ export class AuthManager {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private _resolveCompletedLevelCount(gameData: GameData): number {
|
||||
return gameData.completedLevelCount ?? gameData.completedLevelIds.length;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user