
import { LQCollideSystem } from "../../../lq_collide_system/lq_collide_system";
import { UIList } from "../../Core/Ui/UIDef";
import { UIMgr } from "../../Core/Ui/UIMgr";
import { LevelMgr } from "../../levelMgr";
import { ConfigMgr } from "../cfg/configMgr";
import { Utils } from "../common/utils";
import { Barrage } from "./barrage";
import { EffectMgr } from "./effectMgr";

const {ccclass, property, executeInEditMode, playOnFocus} = cc._decorator;


enum EGameLayer {
    bullet,
    level,
    effect,
    num,
}

let EGameLayerNames = [];
for (let index = 0; index < EGameLayer.num; index++) {
    const element = EGameLayer[index];
    EGameLayerNames.push(element);
}

@ccclass
export class MainGame extends cc.Component{
    /*===========================自动绑定组件开始===========================*/
    /*自动生成*/
    @property({type:cc.Node, displayName:""})
    private $layer_node:cc.Node = null;
    
	/*自动生成*/
    @property({type:cc.Label, displayName:""})
    private $levelTitle_lb:cc.Label = null;

	/*===========================自动绑定组件结束===========================*/

    /*===========================自动生成按钮事件开始==========================*/

	/*===========================自动生成按钮事件结束==========================*/

    layerMap: Map<number, cc.Node> = new Map();

    protected async onLoad() {
        this.setup();

        LQCollideSystem.is_enable = true;
        cc.director.getPhysicsManager().enabled = true; 
        cc.director.getPhysicsManager().gravity = cc.v2(0, 0);

        await ConfigMgr.inst.init();

        LevelMgr.inst.layer = this.getLayer(EGameLayer.level);
        LevelMgr.inst.title = this.$levelTitle_lb
        LevelMgr.inst.begin();

        Barrage.inst.layer = this.getLayer(EGameLayer.bullet);
        EffectMgr.inst.layer = this.getLayer(EGameLayer.effect);

        UIMgr.inst.showUI(UIList.debug);
    }

    private setup() {
        for (let index = 0; index < EGameLayerNames.length; index++) {
            const element = EGameLayerNames[index];
            let node = new cc.Node(element);
            Utils.addFullWidget(node);
            this.$layer_node.addChild(node);
            this.layerMap.set(index, node);
        }
    }

    getLayer(e: EGameLayer){
        return this.layerMap.get(e);
    }
}