mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-27 08:28:50 +02:00
refactoring
This commit is contained in:
parent
2bee3d357a
commit
eba8734667
6 changed files with 72 additions and 59 deletions
|
@ -6648,7 +6648,7 @@ var Level = Sandbox.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
initParseWaterfall: function(options) {
|
initParseWaterfall: function(options) {
|
||||||
this.parseWaterfall = new ParseWaterfall();
|
Level.__super__.initParseWaterfall.apply(this, [options]);
|
||||||
|
|
||||||
// add our specific functionaity
|
// add our specific functionaity
|
||||||
this.parseWaterfall.addFirst(
|
this.parseWaterfall.addFirst(
|
||||||
|
@ -6779,10 +6779,9 @@ var Level = Sandbox.extend({
|
||||||
|
|
||||||
die: function() {
|
die: function() {
|
||||||
this.levelToolbar.die();
|
this.levelToolbar.die();
|
||||||
this.goalCanvasHolder.die();
|
|
||||||
|
|
||||||
|
this.goalDie();
|
||||||
this.mainVis.die();
|
this.mainVis.die();
|
||||||
this.goalVis.die();
|
|
||||||
this.releaseControl();
|
this.releaseControl();
|
||||||
|
|
||||||
this.clear();
|
this.clear();
|
||||||
|
@ -6793,6 +6792,11 @@ var Level = Sandbox.extend({
|
||||||
delete this.goalCanvasHolder;
|
delete this.goalCanvasHolder;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
goalDie: function() {
|
||||||
|
this.goalCanvasHolder.die();
|
||||||
|
this.goalVis.die();
|
||||||
|
},
|
||||||
|
|
||||||
getInstantCommands: function() {
|
getInstantCommands: function() {
|
||||||
var hintMsg = (this.level.hint) ?
|
var hintMsg = (this.level.hint) ?
|
||||||
this.level.hint :
|
this.level.hint :
|
||||||
|
@ -19168,6 +19172,10 @@ var LevelBuilder = Level.extend({
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
initParseWaterfall: function() {
|
||||||
|
LevelBuilder.__super__.initParseWaterfall.apply(this, [options]);
|
||||||
|
},
|
||||||
|
|
||||||
takeControl: function() {
|
takeControl: function() {
|
||||||
Main.getEventBaton().stealBaton('processLevelBuilderCommand', this.processLevelCommand, this);
|
Main.getEventBaton().stealBaton('processLevelBuilderCommand', this.processLevelCommand, this);
|
||||||
|
|
||||||
|
@ -19441,7 +19449,7 @@ var Level = Sandbox.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
initParseWaterfall: function(options) {
|
initParseWaterfall: function(options) {
|
||||||
this.parseWaterfall = new ParseWaterfall();
|
Level.__super__.initParseWaterfall.apply(this, [options]);
|
||||||
|
|
||||||
// add our specific functionaity
|
// add our specific functionaity
|
||||||
this.parseWaterfall.addFirst(
|
this.parseWaterfall.addFirst(
|
||||||
|
@ -19572,10 +19580,9 @@ var Level = Sandbox.extend({
|
||||||
|
|
||||||
die: function() {
|
die: function() {
|
||||||
this.levelToolbar.die();
|
this.levelToolbar.die();
|
||||||
this.goalCanvasHolder.die();
|
|
||||||
|
|
||||||
|
this.goalDie();
|
||||||
this.mainVis.die();
|
this.mainVis.die();
|
||||||
this.goalVis.die();
|
|
||||||
this.releaseControl();
|
this.releaseControl();
|
||||||
|
|
||||||
this.clear();
|
this.clear();
|
||||||
|
@ -19586,6 +19593,11 @@ var Level = Sandbox.extend({
|
||||||
delete this.goalCanvasHolder;
|
delete this.goalCanvasHolder;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
goalDie: function() {
|
||||||
|
this.goalCanvasHolder.die();
|
||||||
|
this.goalVis.die();
|
||||||
|
},
|
||||||
|
|
||||||
getInstantCommands: function() {
|
getInstantCommands: function() {
|
||||||
var hintMsg = (this.level.hint) ?
|
var hintMsg = (this.level.hint) ?
|
||||||
this.level.hint :
|
this.level.hint :
|
||||||
|
|
|
@ -18,6 +18,12 @@ var ConfirmCancelTerminal = require('../views').ConfirmCancelTerminal;
|
||||||
var NextLevelConfirm = require('../views').NextLevelConfirm;
|
var NextLevelConfirm = require('../views').NextLevelConfirm;
|
||||||
var LevelToolbar = require('../views').LevelToolbar;
|
var LevelToolbar = require('../views').LevelToolbar;
|
||||||
|
|
||||||
|
var regexMap = {
|
||||||
|
'show goal': /^show goal$/,
|
||||||
|
'hide goal': /^hide goal$/,
|
||||||
|
'show solution': /^show solution$/
|
||||||
|
};
|
||||||
|
|
||||||
var LevelBuilder = Level.extend({
|
var LevelBuilder = Level.extend({
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
options = 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() {
|
takeControl: function() {
|
||||||
Main.getEventBaton().stealBaton('processLevelBuilderCommand', this.processLevelCommand, this);
|
Main.getEventBaton().stealBaton('processLevelBuilderCommand', this.processLevelCommand, this);
|
||||||
|
|
||||||
|
|
|
@ -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;
|
|
||||||
|
|
|
@ -22,6 +22,14 @@ var LevelToolbar = require('../views').LevelToolbar;
|
||||||
|
|
||||||
var TreeCompare = require('../git/treeCompare').TreeCompare;
|
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({
|
var Level = Sandbox.extend({
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
@ -179,12 +187,12 @@ var Level = Sandbox.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
initParseWaterfall: function(options) {
|
initParseWaterfall: function(options) {
|
||||||
this.parseWaterfall = new ParseWaterfall();
|
Level.__super__.initParseWaterfall.apply(this, [options]);
|
||||||
|
|
||||||
// add our specific functionaity
|
// add our specific functionaity
|
||||||
this.parseWaterfall.addFirst(
|
this.parseWaterfall.addFirst(
|
||||||
'parseWaterfall',
|
'parseWaterfall',
|
||||||
require('../level/commands').parse
|
parse
|
||||||
);
|
);
|
||||||
|
|
||||||
this.parseWaterfall.addFirst(
|
this.parseWaterfall.addFirst(
|
||||||
|
@ -310,10 +318,9 @@ var Level = Sandbox.extend({
|
||||||
|
|
||||||
die: function() {
|
die: function() {
|
||||||
this.levelToolbar.die();
|
this.levelToolbar.die();
|
||||||
this.goalCanvasHolder.die();
|
|
||||||
|
|
||||||
|
this.goalDie();
|
||||||
this.mainVis.die();
|
this.mainVis.die();
|
||||||
this.goalVis.die();
|
|
||||||
this.releaseControl();
|
this.releaseControl();
|
||||||
|
|
||||||
this.clear();
|
this.clear();
|
||||||
|
@ -324,6 +331,11 @@ var Level = Sandbox.extend({
|
||||||
delete this.goalCanvasHolder;
|
delete this.goalCanvasHolder;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
goalDie: function() {
|
||||||
|
this.goalCanvasHolder.die();
|
||||||
|
this.goalVis.die();
|
||||||
|
},
|
||||||
|
|
||||||
getInstantCommands: function() {
|
getInstantCommands: function() {
|
||||||
var hintMsg = (this.level.hint) ?
|
var hintMsg = (this.level.hint) ?
|
||||||
this.level.hint :
|
this.level.hint :
|
||||||
|
|
|
@ -55,27 +55,6 @@ var regexMap = {
|
||||||
'iosAlert': /^iOS alert($|\s)/
|
'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.instantCommands = instantCommands;
|
||||||
exports.parse = parse;
|
exports.parse = util.genParseCommand(regexMap, 'processSandboxCommand');
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue