summaryrefslogtreecommitdiff
path: root/js/codeq/stateMachine.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/codeq/stateMachine.js')
-rw-r--r--js/codeq/stateMachine.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/js/codeq/stateMachine.js b/js/codeq/stateMachine.js
new file mode 100644
index 0000000..cfb27e7
--- /dev/null
+++ b/js/codeq/stateMachine.js
@@ -0,0 +1,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.apply(currState,Array.prototype.slice.apply(arguments,[1]));
+ },
+ 'destroy': function(){
+ if(currState !== null) currState.exit();
+ currState = null;
+ },
+ 'register': function(name,state){
+ def[name] = state;
+ }
+ }
+};
+codeq.globalStateMachine = codeq.makeStateMachine({}); \ No newline at end of file