From cee672f22d516ecc73f84a3dbe01328883a2a47d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Smodi=C5=A1?= Date: Mon, 21 Sep 2015 17:45:31 +0200 Subject: Refactoring: simplified python.js and prolog.js, removed all DOM IDs except for the top-level block #screen_prolog, made a copy of the latter into #screen_python so the two screens can now diverge. --- js/codeq/stateMachine.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'js/codeq/stateMachine.js') diff --git a/js/codeq/stateMachine.js b/js/codeq/stateMachine.js index cfb27e7..dff89d5 100644 --- a/js/codeq/stateMachine.js +++ b/js/codeq/stateMachine.js @@ -6,8 +6,17 @@ codeq.makeStateMachine = function(def){ var currState = null; return { 'transition': function(name){ + var newState = def[name]; + if (!newState) { + codeq.log.error('Cannot transition to state ' + name + ': it is not defined'); + return; + } + if (newState === currState) { + codeq.log.info('Will not transition between identical states: ' + name); + return; + } if(currState !== null) currState.exit(); - currState = def[name]; + currState = newState; currState.enter.apply(currState,Array.prototype.slice.apply(arguments,[1])); }, 'destroy': function(){ @@ -15,6 +24,7 @@ codeq.makeStateMachine = function(def){ currState = null; }, 'register': function(name,state){ + if (name in def) codeq.log.error('The state ' + name + ' is already registered, overriding'); def[name] = state; } } -- cgit v1.2.1