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);

View file

@ -85,10 +85,7 @@ var Level = Sandbox.extend({
},
initGoalData: function(options) {
this.goalTreeString = this.level.goalTreeString;
this.solutionCommand = this.level.solutionCommand;
if (!this.goalTreeString || !this.solutionCommand) {
if (!this.level.goalTreeString || !this.level.solutionCommand) {
throw new Error('need goal tree and solution');
}
},
@ -130,7 +127,7 @@ var Level = Sandbox.extend({
this.goalVis = new Visualization({
el: this.goalCanvasHolder.getCanvasLocation(),
containerElement: this.goalCanvasHolder.getCanvasLocation(),
treeString: this.goalTreeString,
treeString: this.level.goalTreeString,
noKeyboardInput: true,
noClick: true
});
@ -154,7 +151,7 @@ var Level = Sandbox.extend({
// ok great add the solution command
Main.getEventBaton().trigger(
'commandSubmitted',
'reset;' + this.solutionCommand
'reset;' + this.level.solutionCommand
);
this.hideGoal();
command.setResult('Solution command added to the command queue...');
@ -265,7 +262,7 @@ var Level = Sandbox.extend({
// ok so lets see if they solved it...
var current = this.mainVis.gitEngine.exportTree();
var solved = this.treeCompare.compareAllBranchesWithinTrees(current, this.goalTreeString);
var solved = this.treeCompare.compareAllBranchesWithinTrees(current, this.level.goalTreeString);
if (!solved) {
defer.resolve();
@ -348,6 +345,11 @@ var Level = Sandbox.extend({
throw new Errors.CommandResult({
msg: hintMsg
});
}],
[/^build level$/, function() {
throw new Errors.GitError({
msg: "You can't build a level inside a level! Please exit level first"
});
}]
];
},

View file

@ -155,7 +155,7 @@ var Sandbox = Backbone.View.extend({
var whenBuilderOpen = Q.defer();
var LevelBuilder = require('../level/builder').LevelBuilder;
var levelBuilder = new LevelBuilder({
this.levelBuilder = new LevelBuilder({
deferred: whenBuilderOpen
});
@ -234,6 +234,7 @@ var Sandbox = Backbone.View.extend({
reset: function(command, deferred) {
this.mainVis.reset();
setTimeout(function() {
command.finishWith(deferred);
}, this.mainVis.getAnimationTime());

View file

@ -725,7 +725,7 @@ GitVisuals.prototype.visBranchesFront = function() {
vBranch.textToFront();
});
this.visBranchCollection.each(function(visBranch) {
this.visBranchCollection.each(function(vBranch) {
vBranch.textToFrontIfInStack();
});
};

View file

@ -127,6 +127,10 @@ var Visualization = Backbone.View.extend({
this.setTreeOpacity(1);
},
resetFromThisTreeNow: function(treeString) {
this.treeString = treeString;
},
reset: function() {
this.setTreeOpacity(0);
if (this.treeString) {