new demo command

This commit is contained in:
Peter Cottle 2013-01-12 23:15:13 -08:00
parent 0cb6e43549
commit 22605249ce
3 changed files with 81 additions and 36 deletions

View file

@ -27,7 +27,7 @@ var regexMap = {
'start dialog': /^start dialog$/,
'show goal': /^show goal$/,
'hide goal': /^hide goal$/,
'show solution': /^show solution$/
'show solution': /^show solution($|\s)/
};
var parse = util.genParseCommand(regexMap, 'processLevelCommand');
@ -153,6 +153,25 @@ var Level = Sandbox.extend({
},
showSolution: function(command, deferred) {
var toIssue = this.level.solutionCommand;
var issueFunc = function() {
Main.getEventBaton().trigger(
'commandSubmitted',
toIssue
);
};
var commandStr = command.get('rawStr');
if (!this.testOptionOnString(commandStr, 'noReset')) {
toIssue = 'reset; ' + toIssue;
}
if (this.testOptionOnString(commandStr, 'force')) {
issueFunc();
command.finishWith(deferred);
return;
}
// allow them for force the solution
var confirmDefer = Q.defer();
var confirmView = new ConfirmCancelTerminal({
markdowns: [
@ -164,15 +183,7 @@ var Level = Sandbox.extend({
});
confirmDefer.promise
.then(_.bind(function() {
// ok great add the solution command
Main.getEventBaton().trigger(
'commandSubmitted',
'reset;' + this.level.solutionCommand
);
this.hideGoal();
command.setResult('Solution command added to the command queue...');
}, this))
.then(issueFunc)
.fail(function() {
command.setResult("Great! I'll let you get back to it");
})
@ -307,6 +318,10 @@ var Level = Sandbox.extend({
return this.options.command && new RegExp('--' + option).test(this.options.command.get('rawStr'));
},
testOptionOnString: function(str, option) {
return str && new RegExp('--' + option).test(str);
},
levelSolved: function(defer) {
this.solved = true;
Main.getEvents().trigger('levelSolved', this.level.id);