refactoring

This commit is contained in:
Peter Cottle 2013-01-09 00:42:42 -08:00
parent 2bee3d357a
commit eba8734667
6 changed files with 72 additions and 59 deletions

View file

@ -6648,7 +6648,7 @@ var Level = Sandbox.extend({
},
initParseWaterfall: function(options) {
this.parseWaterfall = new ParseWaterfall();
Level.__super__.initParseWaterfall.apply(this, [options]);
// add our specific functionaity
this.parseWaterfall.addFirst(
@ -6779,10 +6779,9 @@ var Level = Sandbox.extend({
die: function() {
this.levelToolbar.die();
this.goalCanvasHolder.die();
this.goalDie();
this.mainVis.die();
this.goalVis.die();
this.releaseControl();
this.clear();
@ -6793,6 +6792,11 @@ var Level = Sandbox.extend({
delete this.goalCanvasHolder;
},
goalDie: function() {
this.goalCanvasHolder.die();
this.goalVis.die();
},
getInstantCommands: function() {
var hintMsg = (this.level.hint) ?
this.level.hint :
@ -19168,6 +19172,10 @@ var LevelBuilder = Level.extend({
);
},
initParseWaterfall: function() {
LevelBuilder.__super__.initParseWaterfall.apply(this, [options]);
},
takeControl: function() {
Main.getEventBaton().stealBaton('processLevelBuilderCommand', this.processLevelCommand, this);
@ -19441,7 +19449,7 @@ var Level = Sandbox.extend({
},
initParseWaterfall: function(options) {
this.parseWaterfall = new ParseWaterfall();
Level.__super__.initParseWaterfall.apply(this, [options]);
// add our specific functionaity
this.parseWaterfall.addFirst(
@ -19572,10 +19580,9 @@ var Level = Sandbox.extend({
die: function() {
this.levelToolbar.die();
this.goalCanvasHolder.die();
this.goalDie();
this.mainVis.die();
this.goalVis.die();
this.releaseControl();
this.clear();
@ -19586,6 +19593,11 @@ var Level = Sandbox.extend({
delete this.goalCanvasHolder;
},
goalDie: function() {
this.goalCanvasHolder.die();
this.goalVis.die();
},
getInstantCommands: function() {
var hintMsg = (this.level.hint) ?
this.level.hint :

View file

@ -18,6 +18,12 @@ var ConfirmCancelTerminal = require('../views').ConfirmCancelTerminal;
var NextLevelConfirm = require('../views').NextLevelConfirm;
var LevelToolbar = require('../views').LevelToolbar;
var regexMap = {
'show goal': /^show goal$/,
'hide goal': /^hide goal$/,
'show solution': /^show solution$/
};
var LevelBuilder = Level.extend({
initialize: function(options) {
options = options || {};
@ -71,6 +77,19 @@ var LevelBuilder = Level.extend({
);
},
initParseWaterfall: function() {
LevelBuilder.__super__.initParseWaterfall.apply(this, [options]);
this.parseWaterfall.addFirst(
'parseWaterfall',
parse
);
this.parseWaterfall.addFirst(
'instantWaterfall',
this.getInstantCommands()
);
},
takeControl: function() {
Main.getEventBaton().stealBaton('processLevelBuilderCommand', this.processLevelCommand, this);

View file

@ -1,27 +0,0 @@
var _ = require('underscore');
var regexMap = {
'show goal': /^show goal$/,
'hide goal': /^hide goal$/,
'show solution': /^show solution$/
};
var parse = function(str) {
var levelMethod;
_.each(regexMap, function(regex, method) {
if (regex.test(str)) {
levelMethod = method;
}
});
return (!levelMethod) ? false : {
toSet: {
eventName: 'processLevelCommand',
method: levelMethod
}
};
};
exports.parse = parse;

View file

@ -22,6 +22,14 @@ var LevelToolbar = require('../views').LevelToolbar;
var TreeCompare = require('../git/treeCompare').TreeCompare;
var regexMap = {
'show goal': /^show goal$/,
'hide goal': /^hide goal$/,
'show solution': /^show solution$/
};
var parse = util.genParseCommand(regexMap, 'processLevelCommand');
var Level = Sandbox.extend({
initialize: function(options) {
options = options || {};
@ -179,12 +187,12 @@ var Level = Sandbox.extend({
},
initParseWaterfall: function(options) {
this.parseWaterfall = new ParseWaterfall();
Level.__super__.initParseWaterfall.apply(this, [options]);
// add our specific functionaity
this.parseWaterfall.addFirst(
'parseWaterfall',
require('../level/commands').parse
parse
);
this.parseWaterfall.addFirst(
@ -310,10 +318,9 @@ var Level = Sandbox.extend({
die: function() {
this.levelToolbar.die();
this.goalCanvasHolder.die();
this.goalDie();
this.mainVis.die();
this.goalVis.die();
this.releaseControl();
this.clear();
@ -324,6 +331,11 @@ var Level = Sandbox.extend({
delete this.goalCanvasHolder;
},
goalDie: function() {
this.goalCanvasHolder.die();
this.goalVis.die();
},
getInstantCommands: function() {
var hintMsg = (this.level.hint) ?
this.level.hint :

View file

@ -55,27 +55,6 @@ var regexMap = {
'iosAlert': /^iOS alert($|\s)/
};
var parse = function(str) {
var sandboxMethod;
var regexResults;
_.each(regexMap, function(regex, method) {
var results = regex.exec(str);
if (results) {
sandboxMethod = method;
regexResults = results;
}
});
return (!sandboxMethod) ? false : {
toSet: {
eventName: 'processSandboxCommand',
method: sandboxMethod,
regexResults: regexResults
}
};
};
exports.instantCommands = instantCommands;
exports.parse = parse;
exports.parse = util.genParseCommand(regexMap, 'processSandboxCommand');

View file

@ -22,3 +22,21 @@ exports.splitTextCommand = function(value, func, context) {
});
};
util.genParseCommand = function(regexMap, eventName) {
return function(str) {
var method;
_.each(regexMap, function(regex, _method) {
if (regex.test(str)) {
method = _method;
}
});
return (!method) ? false : {
toSet: {
eventName: 'processLevelBuilderCommand',
method: method
}
};
};
};