From 22605249cee8f170df869df23f5d5c42fe65ad9b Mon Sep 17 00:00:00 2001 From: Peter Cottle Date: Sat, 12 Jan 2013 23:15:13 -0800 Subject: [PATCH] new demo command --- build/bundle.js | 78 ++++++++++++++++++++++++++++++------------- src/js/app/index.js | 4 +-- src/js/level/index.js | 35 +++++++++++++------ 3 files changed, 81 insertions(+), 36 deletions(-) diff --git a/build/bundle.js b/build/bundle.js index b84c96c9..6f1374e6 100644 --- a/build/bundle.js +++ b/build/bundle.js @@ -6460,8 +6460,8 @@ var init = function() { "gc; git checkout HEAD~1; git commit; git checkout -b bugFix; gc;", "git rebase -i HEAD~3; git rebase master; git checkout master; gc;", "git merge bugFix; levels --noOutput; level rebase1 --noFinishDialog --noStartCommand;", - "show goal; delay 1000; hide goal;", - "git checkout -b win; git commit; help" + "show goal; delay 1000; hide goal; show solution --force --noReset;", + "help; levels" ].join('')); }); } @@ -6556,7 +6556,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'); @@ -6682,6 +6682,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: [ @@ -6693,15 +6712,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"); }) @@ -6836,6 +6847,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); @@ -18341,8 +18356,8 @@ var init = function() { "gc; git checkout HEAD~1; git commit; git checkout -b bugFix; gc;", "git rebase -i HEAD~3; git rebase master; git checkout master; gc;", "git merge bugFix; levels --noOutput; level rebase1 --noFinishDialog --noStartCommand;", - "show goal; delay 1000; hide goal;", - "git checkout -b win; git commit; help" + "show goal; delay 1000; hide goal; show solution --force --noReset;", + "help; levels" ].join('')); }); } @@ -21259,7 +21274,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'); @@ -21385,6 +21400,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: [ @@ -21396,15 +21430,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"); }) @@ -21539,6 +21565,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); diff --git a/src/js/app/index.js b/src/js/app/index.js index 50214ba3..424a59b4 100644 --- a/src/js/app/index.js +++ b/src/js/app/index.js @@ -125,8 +125,8 @@ var init = function() { "gc; git checkout HEAD~1; git commit; git checkout -b bugFix; gc;", "git rebase -i HEAD~3; git rebase master; git checkout master; gc;", "git merge bugFix; levels --noOutput; level rebase1 --noFinishDialog --noStartCommand;", - "show goal; delay 1000; hide goal;", - "git checkout -b win; git commit; help" + "show goal; delay 1000; hide goal; show solution --force --noReset;", + "help; levels" ].join('')); }); } diff --git a/src/js/level/index.js b/src/js/level/index.js index dbc89e3a..e1b2fba3 100644 --- a/src/js/level/index.js +++ b/src/js/level/index.js @@ -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);