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 FSM = (function () {
    function FSM() {
        this._states = [];
    }
    FSM.prototype.init = function (name) {
        this.switchTo(name);
    };
    FSM.prototype.addState = function (name) {
        var s = this.getState(name);
        if (s == null) {
            s = new State(name);
            this._states.push(s);
        }
        return s;
    };
    FSM.prototype.removeState = function (name) {
        var i;
        var tempStates;
        for (i = this._states.length - 1; i >= 0; --i) {
            if (this._states[i].name == name) {
                tempStates = this._states.splice(i, 1);
                return tempStates[0];
            }
        }
        return null;
    };
    FSM.prototype.getState = function (name) {
        var i;
        for (i = this._states.length - 1; i >= 0; --i) {
            if (this._states[i].name == name) {
                return this._states[i];
            }
        }
        return;
    };
    Object.defineProperty(FSM.prototype, "currentState", {
        get: function () {
            if (this._curState == null) {
                return null;
            }
            return this._curState.name;
        },
        enumerable: true,
        configurable: true
    });
    FSM.prototype.switchTo = function (name) {
        // console.log("fsm ",name);
        if (this._curState != null) {
            if (this._curState.name == name) {
                return;
            }
            this._curState.end();
        }
        this._curState = this.getState(name);
        if (this._curState) {
            this._curState.start();
        }
    };
    FSM.prototype.pushFront = function (state, fun) {
        var s = this.getState(state);
        if (s) {
            s.pushFront(fun);
        }
    };
    FSM.prototype.pushBack = function (state, fun) {
        var s = this.getState(state);
        if (s) {
            s.pushBack(fun);
        }
    };
    return FSM;
}());
__reflect(FSM.prototype, "FSM");
//# sourceMappingURL=FSM.js.map