summaryrefslogtreecommitdiff
path: root/js/codeq/stateMachine.js
blob: 12332c42ded3ac247d32807d5a006fc360380d6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
 * Created by robert on 9/15/15.
 */

codeq.makeStateMachine = function(def){
    var currState = null;
    return {
        'transition': function(name){
            if(currState !== null) currState.exit();
            currState = def[name];
            currState.enter();
        },
        'destroy': function(){
            if(currState !== null) currState.exit();
            currState = null;
        },
        'register': function(name,state){
            def[name] = state;
        }
    }
};
codeq.globalStateMachine = codeq.makeStateMachine({});