feat: 接入关卡配置 API 并支持降级到本地配置
- 新增 LevelDataManager 单例管理关卡数据 - 新增 HttpUtil 封装 XMLHttpRequest 请求 - 新增 LevelTypes 类型定义 - PageLoading 集成 API 数据预加载(0-80% 进度) - PageLevel 支持优先使用 API 数据,失败时降级到本地配置 - 字段映射: hint1/2/3 → clue1/2/3, imageUrl → SpriteFrame
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { _decorator, Component, ProgressBar } from 'cc';
|
||||
import { _decorator, Component, ProgressBar, Label } from 'cc';
|
||||
import { ViewManager } from './scripts/core/ViewManager';
|
||||
import { LevelDataManager } from './scripts/utils/LevelDataManager';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**
|
||||
@@ -11,6 +12,9 @@ export class PageLoading extends Component {
|
||||
@property(ProgressBar)
|
||||
progressBar: ProgressBar | null = null;
|
||||
|
||||
@property(Label)
|
||||
statusLabel: Label | null = null;
|
||||
|
||||
start() {
|
||||
this._startPreload();
|
||||
}
|
||||
@@ -18,16 +22,22 @@ export class PageLoading extends Component {
|
||||
/**
|
||||
* 开始预加载
|
||||
*/
|
||||
private _startPreload(): void {
|
||||
private async _startPreload(): Promise<void> {
|
||||
// 初始化进度条
|
||||
if (this.progressBar) {
|
||||
this.progressBar.progress = 0;
|
||||
}
|
||||
|
||||
// 预加载 PageHome
|
||||
// 阶段1: 初始化 LevelDataManager (0-80%)
|
||||
await LevelDataManager.instance.initialize((progress, message) => {
|
||||
this._updateProgress(progress);
|
||||
this._updateStatusLabel(message);
|
||||
});
|
||||
|
||||
// 阶段2: 预加载 PageHome (80-100%)
|
||||
ViewManager.instance.preload('PageHome',
|
||||
(progress) => {
|
||||
this._updateProgress(progress);
|
||||
this._updateProgress(0.8 + progress * 0.2);
|
||||
},
|
||||
() => {
|
||||
this._onPreloadComplete();
|
||||
@@ -44,12 +54,22 @@ export class PageLoading extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新状态标签
|
||||
*/
|
||||
private _updateStatusLabel(message: string): void {
|
||||
if (this.statusLabel) {
|
||||
this.statusLabel.string = message;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 预加载完成回调
|
||||
*/
|
||||
private _onPreloadComplete(): void {
|
||||
// 确保进度条显示完成
|
||||
this._updateProgress(1);
|
||||
this._updateStatusLabel('加载完成');
|
||||
|
||||
// 打开 PageHome
|
||||
ViewManager.instance.open('PageHome', {
|
||||
|
||||
Reference in New Issue
Block a user