// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,


    properties: {
        offsetReduceSpeed : 20,
        offsetIncreaseSpeed : 10,

        player: {
            // ATTRIBUTES:
            default: null,        // The default value will be used only when the component attaching
                                  // to a node for the first time
            type: cc.Node, // optional, default is typeof default
            serializable: true,   // optional, default is true
        },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad : function() {
        // this.startDamp(500,5,200,600,8);
    },

    // start () {
    //
    // },

    update: function (dt) {

    },
    startDamp : function (speedMax,speedMaxtime,speedMin,speedMaxtoo,speedMaxtimetoo) {
        this.speedMax = speedMax;
        this.speedMaxtime = speedMaxtime;

        this.speedMin = speedMin;
        // this.speedMintime = speedMintime;

        this.speedMaxtoo = speedMaxtoo;
        this.speedMaxtimetoo = speedMaxtimetoo;
        // cc.log("这俩毁掉的状况 0", this.callTime ,this.callTimetoo);
        if (this.callTime != null) {
            this.unschedule(this.callTime);
        }else if (this.callTimetoo != null) {
            this.unschedule(this.callTimetoo);
        }
        // cc.log("减速轨迹 开始");
        this.reduce();
        // this.increase();
    },



    //减少
    reduce : function () {
        var s1 = this.speedMax;
        var s2 = this.speedMin;
        // cc.log("这俩毁掉的状况 1", this.callTime ,this.callTimetoo);
        this.callTime = function () {
            s1-=this.offsetReduceSpeed;
            // cc.log("轨迹 减速",s1);
            this.reduceListnener(s1);
            if (s1 <= s2) {
                // 在第六次执行回调时取消这个计时器
                this.unschedule(this.callTime);
                this.callTime = null;
                this.increase();
            }
        }.bind(this);

      this.schedule(this.callTime, this.speedMaxtime/100);

    },

    reduceListnener : function () {

    },
    setreduceListnener : function (reduceListnener) {
        this.reduceListnener = reduceListnener;
    },

    //增加
    increase : function () {
        var s1 = this.speedMin;
        var s2 = this.speedMaxtoo;
        // cc.log("这俩毁掉的状况 2", this.callTime ,this.callTimetoo);
        this.callTimetoo = function () {
            s1+=this.offsetIncreaseSpeed;
            this.increaseListnener(s1);
            // cc.log("轨迹 加速",s1);
            if (s1 >= s2) {
                // 在第六次执行回调时取消这个计时器
                this.unschedule(this.callTimetoo);
                this.callTimetoo = null;
                this.handleCallBack();
            }
        }.bind(this);

            this.schedule(this.callTimetoo, this.speedMaxtimetoo/100);
    },
    increaseListnener : function () {

    },
    setincreaseListnener : function (increaseListnener) {
        this.increaseListnener = increaseListnener;
    },

    handleCallBack : function () {
        // this.player.getComponent()
    },
    sethandleCallBack : function (handleCallBack) {
        this.handleCallBack = handleCallBack;
    },


});
