From 9381f425096a95eb5092b56b61b3ea7505339f24 Mon Sep 17 00:00:00 2001 From: Peter Cottle Date: Wed, 9 Jan 2013 01:56:52 -0800 Subject: [PATCH] pretty much got finish down --- build/bundle.js | 140 +++++++++++++++++++++++++------- src/js/level/builder.js | 55 +++++++++++-- src/js/level/index.js | 16 ++-- src/js/level/sandbox.js | 3 +- src/js/visuals/index.js | 2 +- src/js/visuals/visualization.js | 4 + todo.txt | 12 ++- 7 files changed, 183 insertions(+), 49 deletions(-) diff --git a/build/bundle.js b/build/bundle.js index cd3a7679..04bba5fc 100644 --- a/build/bundle.js +++ b/build/bundle.js @@ -4648,7 +4648,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 }); @@ -4727,6 +4727,7 @@ var Sandbox = Backbone.View.extend({ reset: function(command, deferred) { this.mainVis.reset(); + setTimeout(function() { command.finishWith(deferred); }, this.mainVis.getAnimationTime()); @@ -6593,10 +6594,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'); } }, @@ -6638,7 +6636,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 }); @@ -6662,7 +6660,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...'); @@ -6773,7 +6771,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(); @@ -6856,6 +6854,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" + }); }] ]; }, @@ -7103,6 +7106,10 @@ var Visualization = Backbone.View.extend({ this.setTreeOpacity(1); }, + resetFromThisTreeNow: function(treeString) { + this.treeString = treeString; + }, + reset: function() { this.setTreeOpacity(0); if (this.treeString) { @@ -13802,7 +13809,7 @@ GitVisuals.prototype.visBranchesFront = function() { vBranch.textToFront(); }); - this.visBranchCollection.each(function(visBranch) { + this.visBranchCollection.each(function(vBranch) { vBranch.textToFrontIfInStack(); }); }; @@ -16510,7 +16517,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'); @@ -16640,6 +16648,11 @@ var LevelBuilder = Level.extend({ }, this.startCanvasHolder.getAnimationTime()); }, + resetSolution: function() { + this.gitCommandsIssued = []; + this.level.solutionCommand = undefined; + }, + hideStart: function(command, deferred) { this.startCanvasHolder.slideOut(); @@ -16654,10 +16667,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); @@ -16672,19 +16686,45 @@ 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.level.id) { + this.setID(); + } + if (this.level.hint === undefined) { + this.setHint(); + } + console.log(this.level, this.startTree); + }, + 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); @@ -19351,7 +19391,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'); @@ -19481,6 +19522,11 @@ var LevelBuilder = Level.extend({ }, this.startCanvasHolder.getAnimationTime()); }, + resetSolution: function() { + this.gitCommandsIssued = []; + this.level.solutionCommand = undefined; + }, + hideStart: function(command, deferred) { this.startCanvasHolder.slideOut(); @@ -19495,10 +19541,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); @@ -19513,19 +19560,45 @@ 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.level.id) { + this.setID(); + } + if (this.level.hint === undefined) { + this.setHint(); + } + console.log(this.level, this.startTree); + }, + 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); @@ -19681,10 +19754,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'); } }, @@ -19726,7 +19796,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 }); @@ -19750,7 +19820,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...'); @@ -19861,7 +19931,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(); @@ -19944,6 +20014,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" + }); }] ]; }, @@ -20258,7 +20333,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 }); @@ -20337,6 +20412,7 @@ var Sandbox = Backbone.View.extend({ reset: function(command, deferred) { this.mainVis.reset(); + setTimeout(function() { command.finishWith(deferred); }, this.mainVis.getAnimationTime()); @@ -24098,7 +24174,7 @@ GitVisuals.prototype.visBranchesFront = function() { vBranch.textToFront(); }); - this.visBranchCollection.each(function(visBranch) { + this.visBranchCollection.each(function(vBranch) { vBranch.textToFrontIfInStack(); }); }; @@ -25426,6 +25502,10 @@ var Visualization = Backbone.View.extend({ this.setTreeOpacity(1); }, + resetFromThisTreeNow: function(treeString) { + this.treeString = treeString; + }, + reset: function() { this.setTreeOpacity(0); if (this.treeString) { diff --git a/src/js/level/builder.js b/src/js/level/builder.js index c2b821e1..c1cea2da 100644 --- a/src/js/level/builder.js +++ b/src/js/level/builder.js @@ -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); diff --git a/src/js/level/index.js b/src/js/level/index.js index a3475bf8..9aaa53e1 100644 --- a/src/js/level/index.js +++ b/src/js/level/index.js @@ -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" + }); }] ]; }, diff --git a/src/js/level/sandbox.js b/src/js/level/sandbox.js index 127048ef..d3f0ced8 100644 --- a/src/js/level/sandbox.js +++ b/src/js/level/sandbox.js @@ -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()); diff --git a/src/js/visuals/index.js b/src/js/visuals/index.js index a634df33..2fef89bf 100644 --- a/src/js/visuals/index.js +++ b/src/js/visuals/index.js @@ -725,7 +725,7 @@ GitVisuals.prototype.visBranchesFront = function() { vBranch.textToFront(); }); - this.visBranchCollection.each(function(visBranch) { + this.visBranchCollection.each(function(vBranch) { vBranch.textToFrontIfInStack(); }); }; diff --git a/src/js/visuals/visualization.js b/src/js/visuals/visualization.js index 57fd72bb..364944a6 100644 --- a/src/js/visuals/visualization.js +++ b/src/js/visuals/visualization.js @@ -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) { diff --git a/todo.txt b/todo.txt index 522cb2ed..8306317b 100644 --- a/todo.txt +++ b/todo.txt @@ -1,9 +1,8 @@ Big Things ~~~~~~~~~~~~~~~~~~~~~~~~~ -[ ] level builder? :OOO - * basically just an extension of level (or sandbox), that has commands like - ```save tree beginning``` or ```save tree goal``` and then a final - dialog typing area thingy +[ ] level builder finish +[ ] level builder dialog tester +[ ] level builder dialog builder Medium things: @@ -33,6 +32,11 @@ Ideas for cleaning Done things: (I only started this on Dec 17th 2012 to get a better sense of what was done) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +[x] level builder? :OOO + * basically just an extension of level (or sandbox), that has commands like + ```save tree beginning``` or ```save tree goal``` and then a final + dialog typing area thingy +[x] vis branch z index reflow bug [x] fix terminal input field in general [x] warning for window size [x] esc on multiview quits absolutely