// 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;
    hat = null;
    // isDebug = false;

    // touchTimeline = [];

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}
    isDebug() {
        return this.hat && this.hat.active;
    }
    start () {
        console.log(111)
        this.hat = this.node.getChildByName('hat');
        if (!this.hat) {
            return;
        }
        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.hat.active) {
                    this.hat.active = false
                } else {
                    this.hat.active = true
                }
                
            }
        });
    }

    // update (dt) {}
}
