// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import GEngine from "../engines/GEngine";
import { GUIManager } from "../engines/gui/GUIManager";
import AssetBundleInitiator from "../engines/initiators/AssetBundleInitiator";
import ConfigInitiator from "../engines/initiators/ConfigInitiator";
import FGUIInitiator from "../engines/initiators/FGUIInitiator";
import LoadingView from "../engines/loadingView/LoadingView";
import SceneManager from "../engines/scenes/SceneManager";
import { SoundManager } from "../engines/sounds/SoundManager";
import MathUtils from "../engines/utils/MathUtils";
import AdsInitiator from "./initiators/AdsInitiator";
import GameInitiator from "./initiators/GameInitiator";
import LoadingViewInitiator from "./initiators/LoadingViewInitiator";
import GameModel from "./models/GameModel";
import UIKeys from "./UIKeys";

const {ccclass, property} = cc._decorator;

@ccclass
export default class Main extends cc.Component {
    
    public static TEST:boolean=true;
    private engineInited:boolean;
    start () {
        GEngine.single.Startup([
            new LoadingViewInitiator(GEngine.single.layerRoot,"loadingViews/LoadingView","LoadingView"),
            new AssetBundleInitiator(["mainPackage"]),
            new ConfigInitiator("mainPackage","configs"),
            new FGUIInitiator("mainPackage","ui/GameBasicsUI"),
            new GameInitiator(),
            new AdsInitiator()
        ],this.engineCallBack.bind(this));
    }
    
    private engineCallBack():void{
        LoadingView.single.UpdateProgress(1);
        LoadingView.single.Hide();

        GameModel.single.ReadByLocal();
        
        SceneManager.single.Swicth("mainPackage","Hall");
        
        GUIManager.single.Show(UIKeys.Hall);
        
        SoundManager.single.PlayMusic("mainPackage","sounds/main");
    }
    private index:number=0;
    private total:number=60*3;
    update (dt:number) {
        if(this.engineInited){
            return;
        }
        this.index++;
        this.index=this.index%this.total;
        LoadingView.single.UpdateProgress(this.index/this.total);
    }
}
