var reGameStates = require('GameStates');

cc.Class({
    extends: cc.Component,

    properties: {
        //斑马线的图片
        HighwaySpriteFrame: {
            default: [],
            type: cc.SpriteFrame,
        },
        //村长的路，暂时和镇长一起使用
        villageHighwaySpriteFrame: {
            default: [],
            type: cc.SpriteFrame,
        },
        //公路对应的sprite
        roadSprite: cc.Sprite,

        //当前图片的下标
        currenHighwayType: {
            default: 0,
            type: cc.Integer,
        }
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start() {


    },

    //切换公路图片
    onChangeHighwayStyles(_highwayType) {
        // cc.log( _highwayType,this.currenHighwayType)
        let currentSpriteFrame;
        if (GlobalD.Dapp) {
            switch (GlobalD.Dapp.UserInfo.agent_level) {
                case 0:
                    currentSpriteFrame = this.HighwaySpriteFrame[0];
                    this.roadSprite.node.scaleX = 1;
                    break;
                case 1:
                    currentSpriteFrame = this.villageHighwaySpriteFrame[0];
                    this.roadSprite.node.scaleX = 1;
                    break;
                case 2:
                    currentSpriteFrame = this.villageHighwaySpriteFrame[0];
                    this.roadSprite.node.scaleX = 1;
                    break;
                default:
                    currentSpriteFrame = this.HighwaySpriteFrame[0];
                    this.roadSprite.node.scaleX = 1;
                    break;
            }
        } else {
            switch (_highwayType) {
                case reGameStates.HighwayType.none:
                    currentSpriteFrame = this.HighwaySpriteFrame[0];
                    this.roadSprite.node.scaleX = 1;
                    break;
                case reGameStates.HighwayType.moveX:
                    currentSpriteFrame = this.HighwaySpriteFrame[2];
                    this.currenHighwayType = reGameStates.HighwayType.moveX;
                    this.roadSprite.node.scaleX = 1;
                    break;
                case reGameStates.HighwayType.moveY:
                    currentSpriteFrame = this.HighwaySpriteFrame[2];
                    this.roadSprite.node.scaleX = -1;
                    this.currenHighwayType = reGameStates.HighwayType.moveY;
                    break;
                case reGameStates.HighwayType.ZebraCrossingX:
                    currentSpriteFrame = this.HighwaySpriteFrame[1];
                    this.currenHighwayType = reGameStates.HighwayType.ZebraCrossingX;
                    this.roadSprite.node.scaleX = -1;

                    break;
                case reGameStates.HighwayType.ZebraCrossingY:
                    currentSpriteFrame = this.HighwaySpriteFrame[1];
                    this.currenHighwayType = reGameStates.HighwayType.ZebraCrossingY;
                    this.roadSprite.node.scaleX = 1;
                    break;
            }
        }
        this.roadSprite.spriteFrame = currentSpriteFrame;

    }
    // update (dt) {},
});
