pretty much got finish down

This commit is contained in:
Peter Cottle 2013-01-09 01:56:52 -08:00
parent 0c7ff70b14
commit 9381f42509
7 changed files with 183 additions and 49 deletions

View file

@ -22,7 +22,8 @@ var regexMap = {
'define goal': /^define goal$/,
'define start': /^define start$/,
'show start': /^show start$/,
'hide start': /^hide start$/
'hide start': /^hide start$/,
'finish': /^finish$/
};
var parse = util.genParseCommand(regexMap, 'processLevelBuilderCommand');
@ -152,6 +153,11 @@ var LevelBuilder = Level.extend({
}, this.startCanvasHolder.getAnimationTime());
},
resetSolution: function() {
this.gitCommandsIssued = [];
this.level.solutionCommand = undefined;
},
hideStart: function(command, deferred) {
this.startCanvasHolder.slideOut();
@ -166,10 +172,11 @@ var LevelBuilder = Level.extend({
command.addWarning(
'Defining start point... solution and goal will be overwritten if they were defined earlier'
);
this.reset();
this.solutionCommand = undefined;
this.resetSolution();
this.level.startTree = this.mainVis.gitEngine.printTree();
this.mainVis.resetFromThisTreeNow(this.level.startTree);
this.initStartVisualization();
this.showStart(command, deferred);
@ -184,19 +191,55 @@ var LevelBuilder = Level.extend({
);
}
this.solutionCommand = this.gitCommandsIssued.join(';');
this.goalTreeString = this.mainVis.gitEngine.printTree();
this.level.solutionCommand = this.gitCommandsIssued.join(';');
this.level.goalTreeString = this.mainVis.gitEngine.printTree();
this.initGoalVisualization();
this.showGoal(command, deferred);
},
setHint: function(command, deferred) {
this.level.hint = prompt('Enter a hint! Or blank if you dont want one');
if (command) { command.finishWith(deferred); }
},
setID: function(command, deferred) {
var id = prompt('Enter an ID');
while (!id || !id.length) {
id = prompt('Enter an ID... really this time');
}
this.level.id = id;
if (command) { command.finishWith(deferred); }
},
finish: function(command, deferred) {
if (!this.gitCommandsIssued.length) {
command.set('error', new GitError({
msg: 'Your solution is empty!'
});
deferred.resolve();
return;
}
if (!this.level.id) {
this.setID();
}
if (this.level.hint === undefined) {
this.setHint();
}
console.log(this.level);
command.finishWith(deferred);
},
processLevelBuilderCommand: function(command, deferred) {
var methodMap = {
'define goal': this.defineGoal,
'define start': this.defineStart,
'show start': this.showStart,
'hide start': this.hideStart
'hide start': this.hideStart,
'finish': this.finish
};
methodMap[command.get('method')].apply(this, arguments);