var __reflect = (this && this.__reflect) || function (p, c, t) {
    p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t;
};
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var Role = (function (_super) {
    __extends(Role, _super);
    function Role(name, scale) {
        if (name === void 0) { name = "man1"; }
        if (scale === void 0) { scale = 1; }
        var _this = _super.call(this) || this;
        _this.name = name;
        _this._scale = scale;
        console.log("name armature", name);
        var skeletonData = RES.getRes(name + "_ske_json");
        var textureData = RES.getRes(name + "_tex_json");
        var texture = RES.getRes(name + "_tex_png");
        var factory = new dragonBones.EgretFactory();
        factory.addSkeletonData(dragonBones.DataParser.parseDragonBonesData(skeletonData));
        factory.addTextureAtlas(new dragonBones.EgretTextureAtlas(texture, textureData));
        _this.armature = factory.buildArmature(name);
        var armatureDisplay = _this.armature.display;
        armatureDisplay.scaleX = _this._scale * 2;
        armatureDisplay.scaleY = _this._scale * 2;
        dragonBones.WorldClock.clock.add(_this.armature);
        _this.addChild(armatureDisplay);
        return _this;
    }
    Object.defineProperty(Role.prototype, "roleX", {
        get: function () {
            return this._roleX;
        },
        set: function (v) {
            this._roleX = v;
            this.x = this._roleX * GameLevel.STEP;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Role.prototype, "roleY", {
        get: function () {
            return this._roleY;
        },
        set: function (v) {
            this._roleY = v;
            this.y = this._roleY * GameLevel.STEP;
        },
        enumerable: true,
        configurable: true
    });
    Role.prototype.addStep = function (endX, endY) {
        if (this.roleX == endX && this.roleY == endY) {
            return 0;
        }
        if (this.roleX > endX) {
            this.roleX--;
            this.walk(Role.LEFT);
        }
        else if (this.roleX < endX) {
            this.roleX++;
            this.walk(Role.RIGHT);
        }
        else {
            if (this.roleY > endY) {
                this.roleY--;
                this.walk(Role.BACK);
            }
            else if (this.roleY < endY) {
                this.roleY++;
                this.walk(Role.FRONT);
            }
        }
        if (this.roleX == endX && this.roleY == endY) {
            return 2;
        }
        return 1;
    };
    Object.defineProperty(Role.prototype, "direct", {
        get: function () {
            return this._direct;
        },
        set: function (v) {
            this._direct = v;
        },
        enumerable: true,
        configurable: true
    });
    Role.prototype.stand = function (direct) {
        if (direct == this._direct && this.dbType == "stand") {
            return;
        }
        this._direct = direct;
        this.dbType = "stand";
        this.play("stand_" + direct);
    };
    Role.prototype.walk = function (direct) {
        if (direct == this._direct && this.dbType == "walk") {
            return;
        }
        this._direct = direct;
        this.dbType = "walk";
        this.play("walk_" + direct);
    };
    Role.prototype.play = function (name) {
        this.armature.animation.play(name, 0);
    };
    Role.prototype.gotoAndStop = function (name, pos) {
        this.armature.animation.gotoAndStop(name, pos);
    };
    Object.defineProperty(Role.prototype, "totleTime", {
        get: function () {
            return this.armature.animation.lastAnimationState.totalTime;
        },
        enumerable: true,
        configurable: true
    });
    Role.prototype.remove = function () {
        dragonBones.WorldClock.clock.remove(this.armature);
    };
    return Role;
}(egret.Sprite));
Role.LEFT = "left";
Role.RIGHT = "right";
Role.FRONT = "front";
Role.BACK = "back";
__reflect(Role.prototype, "Role");
//# sourceMappingURL=Role.js.map