feat: 对接最新的关卡工作流
This commit is contained in:
@@ -3,7 +3,6 @@ import type { AssetManager } from 'cc';
|
||||
import { ViewManager } from './scripts/core/ViewManager';
|
||||
import { LevelDataManager } from './scripts/utils/LevelDataManager';
|
||||
import { AuthManager } from './scripts/utils/AuthManager';
|
||||
import { StorageManager } from './scripts/utils/StorageManager';
|
||||
import { ShareManager } from './scripts/utils/ShareManager';
|
||||
import { WxSDK } from './scripts/utils/WxSDK';
|
||||
const { ccclass, property } = _decorator;
|
||||
@@ -11,7 +10,7 @@ const { ccclass, property } = _decorator;
|
||||
/**
|
||||
* 页面加载组件
|
||||
* 负责用户登录、预加载资源并显示加载进度
|
||||
* 登录与关卡数据加载并行执行以减少等待时间
|
||||
* 流程:登录 + game-data → 拿到 nextLevel → 加载首关图片 → 进入首页
|
||||
*/
|
||||
@ccclass('PageLoading')
|
||||
export class PageLoading extends Component {
|
||||
@@ -34,15 +33,11 @@ export class PageLoading extends Component {
|
||||
|
||||
this._updateStatusLabel('正在加载...');
|
||||
|
||||
// 登录和关卡数据并行加载
|
||||
const [loginSuccess, levelSuccess] = await Promise.all([
|
||||
AuthManager.instance.initialize(),
|
||||
LevelDataManager.instance.initialize((progress, message) => {
|
||||
// 关卡加载占 0-80% 进度
|
||||
this._updateProgress(progress);
|
||||
this._updateStatusLabel(message);
|
||||
}),
|
||||
]);
|
||||
// 阶段1: 登录 + 获取 game-data(含 nextLevel)
|
||||
this._updateProgress(0);
|
||||
this._updateStatusLabel('正在连接服务器...');
|
||||
|
||||
const loginSuccess = await AuthManager.instance.initialize();
|
||||
|
||||
if (loginSuccess) {
|
||||
console.log('[PageLoading] 用户登录成功');
|
||||
@@ -50,22 +45,40 @@ export class PageLoading extends Component {
|
||||
console.warn('[PageLoading] 登录失败,继续离线模式');
|
||||
}
|
||||
|
||||
if (!levelSuccess) {
|
||||
this._updateProgress(0.2);
|
||||
|
||||
// 阶段2: 加载首关图片(如果有 nextLevel)
|
||||
const nextLevel = AuthManager.instance.nextLevel;
|
||||
let levelSuccess = false;
|
||||
|
||||
if (nextLevel) {
|
||||
levelSuccess = await LevelDataManager.instance.initialize(nextLevel, (progress, message) => {
|
||||
// 关卡图片加载占 20%-80% 进度
|
||||
this._updateProgress(0.2 + progress * 0.6);
|
||||
this._updateStatusLabel(message);
|
||||
});
|
||||
|
||||
if (!levelSuccess) {
|
||||
this._updateStatusLabel('资源加载失败,请重新打开游戏');
|
||||
return;
|
||||
}
|
||||
} else if (loginSuccess) {
|
||||
// nextLevel 为 null → 全部通关(或服务端无关卡)
|
||||
console.log('[PageLoading] 全部通关或无可用关卡');
|
||||
this._updateProgress(0.8);
|
||||
} else {
|
||||
// 登录失败且没有 nextLevel
|
||||
this._updateStatusLabel('加载失败,请重新打开游戏');
|
||||
return;
|
||||
}
|
||||
|
||||
// 阶段3: 加载字体分包
|
||||
const fontSuccess = await this._loadFontBundle();
|
||||
if (!fontSuccess) {
|
||||
this._updateStatusLabel('字体资源加载失败,请重新打开游戏');
|
||||
return;
|
||||
}
|
||||
|
||||
// 登录 + 关卡数据都就绪后,用服务端进度覆盖本地进度
|
||||
if (loginSuccess) {
|
||||
this._syncProgressFromServer();
|
||||
}
|
||||
|
||||
// 检测分享码:从微信启动参数中获取
|
||||
const shareCode = WxSDK.getShareCodeFromLaunch();
|
||||
if (shareCode && loginSuccess) {
|
||||
@@ -150,36 +163,4 @@ export class PageLoading extends Component {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 用服务端通关进度同步本地进度
|
||||
* 1. 根据 completedLevelIds 标记已通关关卡
|
||||
* 2. 更新 maxUnlockedLevelIndex
|
||||
* 3. 将 currentLevelIndex 设为第一个未通关关卡
|
||||
*/
|
||||
private _syncProgressFromServer(): void {
|
||||
const completedIds = AuthManager.instance.completedLevelIds;
|
||||
if (completedIds.length === 0) {
|
||||
console.log('[PageLoading] 服务端无通关记录,使用本地进度');
|
||||
return;
|
||||
}
|
||||
|
||||
const maxCompletedIndex = LevelDataManager.instance.getMaxCompletedIndex(completedIds);
|
||||
if (maxCompletedIndex < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const localMax = StorageManager.getMaxUnlockedLevelIndex();
|
||||
|
||||
// 取服务端和本地的较大值,防止进度回退
|
||||
if (maxCompletedIndex > localMax) {
|
||||
StorageManager.onLevelCompleted(maxCompletedIndex);
|
||||
console.log(`[PageLoading] 服务端进度同步:已通关到第 ${maxCompletedIndex + 1} 关`);
|
||||
}
|
||||
|
||||
// 根据关卡列表找到第一个未通关关卡,设为当前关卡
|
||||
const firstUncompleted = LevelDataManager.instance.getFirstUncompletedIndex();
|
||||
StorageManager.setCurrentLevelIndex(firstUncompleted);
|
||||
console.log(`[PageLoading] 当前关卡设为第一个未通关: 第 ${firstUncompleted + 1} 关`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user