// 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 pg from "../scene/pg";

const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Node)
    item: cc.Node = null;



    // LIFE-CYCLE CALLBACKS:
    private mouseList = [];
    private mouseNum = 0;
    onLoad() {
        pg.event.on("mouse_add", () => {
            this.reviceMouse();
        })
        let max = 3;
        for (let i = 0; i < max; i++) {
            this.addMouse();
        }
    }
    reviceMouse() {
        this.mouseNum++;
        this.updateMouse();
    }

    start() {

    }

    addMouse() {
        let item = cc.instantiate(this.item);
        item.active = true;
        item.getChildByName("light").active = false;
        this.node.addChild(item);
        this.mouseList.push(item)
    }
    updateMouse() {
        for (let i = 0; i < this.mouseList.length; i++) {
            let item = this.mouseList[i];
            item.getChildByName("light").active = i < this.mouseNum;
        }
    }

    // update (dt) {}
}
