// 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

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    // @property(cc.Label)
    // label: cc.Label = null;

    // @property
    // text: string = 'hello';
    @property
    need: number = 5;

    touchCounter = 0;
    countTimer = null;
    isDebug = false;

    // touchTimeline = [];

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start () {
        this.node.on(cc.Node.EventType.TOUCH_START, () => {
            // console.log(Date.now());
            // this.touchTimeline.push(Date.now());
            this.touchCounter++;
            if (!this.countTimer) {
                this.countTimer = setTimeout(() =>{
                    this.touchCounter = 0;
                    clearTimeout(this.countTimer);
                    this.countTimer = null;
                }, 2000);
            }
            if (this.touchCounter == this.need) {
                clearTimeout(this.countTimer);
                this.countTimer = null;
                if (this.isDebug) {
                    this.node.color = new cc.Color(255, 255, 255,255);
                    this.isDebug = false;
                } else {
                    this.node.color = new cc.Color(3, 246, 18,255);
                    this.isDebug = true;
                }
                
            }
        });
    }

    // update (dt) {}
}
