var reGameStates = require('GameStates');


cc.Class({
    extends: cc.Component,
    properties: {
        //人物类型
        AIType: {
            default: 1,
            type: cc.Integer,
            serializable: true,
        },

        FrontName: {
            default: 'front',
            visible: false,
            serializable: false,
        },
        BackName: {
            default: 'back',
            visible: false,
            serializable: false,
        },

        //是否循环
        isLoop: false,
    },

    onLoad: function () {
        this.dragonBones = this.node.getChildByName('dragonBones');
        //获取 ArmatureDisplay
        this._armatureDisPlay = this.dragonBones.getComponent(dragonBones.ArmatureDisplay)

        this._armatureDisPlay.armatureName = 'Tourist' + this.AIType;
    },

    // 切换当前是什么游客
    onSwitchTourist(_AIType) {
        this.AIType = _AIType;
        this._armatureDisPlay.armatureName = 'Tourist' + this.AIType;
    },
    switchAnimation: function (direction) {
        //动画执行方式二
        // cc.log('switchAnimation', direction);
        let loopValue = this.isLoop ? 0 : 1;
        switch (direction) {
            case reGameStates.moveType.none:
                // cc.log('reGameStates.moveType.none!!!!!!!!!!!!!!!');
                // if (this.IdleName)
                this._armatureDisPlay.timeScale = 0;
                break;
            case reGameStates.moveType.moveUp:
                this._armatureDisPlay.timeScale = 1;
                this.dragonBones.scaleX = 1;
                if (this.BackName)
                    this._armatureDisPlay.playAnimation(this.BackName, loopValue);
                break;
            case reGameStates.moveType.moveRight:
                this._armatureDisPlay.timeScale = 1;
                this.dragonBones.scaleX = -1;
                if (this.BackName)
                    this._armatureDisPlay.playAnimation(this.BackName, loopValue);
                break;

            case reGameStates.moveType.moveDown:
                this._armatureDisPlay.timeScale = 1;
                this.dragonBones.scaleX = 1;
                if (this.FrontName)
                    this._armatureDisPlay.playAnimation(this.FrontName, loopValue);
                break;
            case reGameStates.moveType.moveLeft:
                this._armatureDisPlay.timeScale = 1;
                this.dragonBones.scaleX = -1;
                if (this.FrontName)
                    this._armatureDisPlay.playAnimation(this.FrontName, loopValue);
                break;
        }
    },


})
