
import { _decorator, Component, director, Label, Prefab, profiler, ProgressBar} from 'cc';
import { audioMgr } from '../core/manager/AudioManager';
import { csvMgr } from '../core/csv/CsvManager';
import { Logger } from '../core/extend/Logger';
import { bundleMgr } from '../core/manager/BundleManager';
import { settingData } from '../user/SettingData';
import Data from '../core/manager/Data';
import platformSystem from '../platform/platformSystem';
import BusyLoadingManager from '../core/manager/BusyLoadingManager';
import { ResUtil } from '../core/utils/ResUtil';
import { autoBind } from '../core/extend/AutoBind';
import i18n from '../core/i18n/runtime-scripts/LanguageData';
import { BaseExp } from '../core/base/BaseExp';
import { GameConst } from '../core/common/GameConst';
const { ccclass, property } = _decorator;

@ccclass('Loading')
export class Loading 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("start.loading");
        //关闭FPS展示
        if(GameConst.isDebug){
           profiler.showStats();
        }else{
           profiler.hideStats();
        }
        //先加载配置资源包 更新进度条
        await bundleMgr.preloadConfigAllRes((progress) => {
            this.progressBar.progress = progress.totalProgress;
        });
        //加载音效
        await audioMgr.initialize();
        //调用事例 加载所有CSV表
        await csvMgr.loadAll();
        BusyLoadingManager.ins;
        //设置
        settingData.loadFromCache();
        //数据加载
        Data.loadData();
        //初始化平台接口
        platformSystem.initialize();
        //启动场景
        ResUtil.enteScene("main")
    }
}

