
import { LQCollideSystem } from "./Collide/lq_collide_system/lq_collide_system";
import { UIList } from "./Core/Ui/UIDef";

import { UILayerNames, UILayers } from "./Core/Ui/UILayers";
import { UIMgr } from "./Core/Ui/UIMgr";
import bullet from "./game/bullet";
import { ConfigMgr } from "./game/cfg/configMgr";
import { LevelMgr } from "./levelMgr";

const {ccclass, property} = cc._decorator;

@ccclass
export default class Start extends cc.Component {

    /*===========================自动绑定组件开始===========================*/
	/*自动生成*/
    @property({type:cc.Node, displayName:""})
    private $bulletLayer_node:cc.Node = null;
	/*自动生成*/
    @property({type:cc.Node, displayName:""})
    private $level_node:cc.Node = null;

    /*自动生成*/
    @property({type:cc.Label, displayName:""})
    private $levelTitle_lb:cc.Label = null;
    	/*自动生成*/
    @property({type:cc.Node, displayName:""})
    private $ui_node:cc.Node = null;

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

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

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

    

    @property(cc.Prefab) bulletPrefab:cc.Prefab = null;
    
    static inst: Start;

    constructor(){
        super();
    }

    protected async onLoad(): Promise<void> {
        Start.inst = this;
        // let node = new cc.Node()

        UIMgr.inst.setup(this.$ui_node, UILayerNames.length, UILayerNames);


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

        await ConfigMgr.inst.init();

        LevelMgr.inst.parent = this.$level_node;
        LevelMgr.inst.title = this.$levelTitle_lb
        LevelMgr.inst.begin();

        // this.testUI();

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

    private testUI() {
        UIMgr.inst.showUI(UIList.loading);
        UIMgr.inst.showUI(UIList.loading);

        setTimeout(() => {
            UIMgr.inst.hideUI(UIList.loading);
        }, 10000);
    }

    createPlayerBullet(pos: cc.Vec2){
        let bulletNode = cc.instantiate(this.bulletPrefab)
        let bulletCpt = bulletNode.getComponent(bullet);
        let moveCpt = bulletCpt.getMoveCpt();
        moveCpt.dirction = cc.v2(0,1);
        moveCpt.speed = 1800*2;

        this.$bulletLayer_node.addChild(bulletNode);
        bulletNode.setPosition(pos);
    }

}