import { _decorator, director, Label, profiler, ProgressBar } from 'cc';
import { csvMgr } from '../core/csv/CsvManager';
import i18n from '../core/i18n/runtime-scripts/LanguageData';
import { audioMgr } from '../core/manager/AudioManager';
import { bundleMgr } from '../core/manager/BundleManager';
import { autoBind } from '../extend/AutoBind';
import { Constants } from '../data/Constants';
import { BaseExp } from '../core/base/BaseExp';
import { userIns } from '../data/UserData';
import { ResUtil } from '../utils/ResUtil';
const { ccclass, property } = _decorator;

@ccclass('Launch')
export class Launch extends BaseExp {
    @autoBind({type:Label,tooltip:"资源加载lable"})
    public load_label: Label;
    @autoBind({type: ProgressBar,tooltip: "加载进度"})
    public progressBar: ProgressBar = null!;

    async start() {
        this.load_label.string = i18n("main.加载中...");
        //关闭FPS展示
        profiler.hideStats()
        //Constants.isDebug ? profiler.showStats() : profiler.hideStats();
        //先加载配置资源包 更新进度条
        await bundleMgr.preloadConfigAllRes((progress) => {
            this.progressBar.progress = progress.totalProgress;
        });
        //加载音效
        await audioMgr.initialize();
        //调用事例 加载所有CSV表
        await csvMgr.loadAll();
        //加载map
        await ResUtil.loadRes(`map/${userIns.getCurLevelData().map}`);
        //进入游戏场景
        director.loadScene(Constants.scenesName.game);
    }
}

