diff --git a/build/bundle.js b/build/bundle.js index 04bba5fc..931e0cb1 100644 --- a/build/bundle.js +++ b/build/bundle.js @@ -15603,7 +15603,8 @@ LevelArbiter.prototype.validateLevel = function(level) { var optionalFields = [ 'hint', - 'disabledMap' + 'disabledMap', + 'startTree' ]; _.each(requiredFields, function(field) { @@ -16499,6 +16500,7 @@ var Q = require('q'); var util = require('../util'); var Main = require('../app'); +var Errors = require('../util/errors'); var Visualization = require('../visuals/visualization').Visualization; var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall; @@ -16526,11 +16528,9 @@ var parse = util.genParseCommand(regexMap, 'processLevelBuilderCommand'); var LevelBuilder = Level.extend({ initialize: function(options) { options = options || {}; + options.level = options.level || {}; - this.options = options; - this.level = {}; - - this.level.startDialog = { + options.level.startDialog = { childViews: [{ type: 'ModalAlert', options: { @@ -16539,10 +16539,10 @@ var LevelBuilder = Level.extend({ '', 'Here are the main steps:', '', - ' * Define the starting tree', - ' * Enter the series of git commands that compose of the (optimal) solution', - ' * Define the goal tree, which also defines the solution', - ' * Enter the command ```finish building``` to specify start dialogs and such' + ' * Define the starting tree with ```define start```', + ' * Enter the series of git commands that compose the (optimal) solution', + ' * Define the goal tree with ```define goal```. Defining the goal also defines the solution', + ' * Enter the command ```finish``` to output your level JSON!' ] } }] @@ -16709,13 +16709,20 @@ var LevelBuilder = Level.extend({ }, finish: function(command, deferred) { - if (!this.level.id) { - this.setID(); + if (!this.gitCommandsIssued.length) { + command.set('error', new Errors.GitError({ + msg: 'Your solution is empty!' + })); + deferred.resolve(); + return; } + if (this.level.hint === undefined) { this.setHint(); } - console.log(this.level, this.startTree); + console.log(this.level); + + command.finishWith(deferred); }, processLevelBuilderCommand: function(command, deferred) { @@ -19313,7 +19320,8 @@ LevelArbiter.prototype.validateLevel = function(level) { var optionalFields = [ 'hint', - 'disabledMap' + 'disabledMap', + 'startTree' ]; _.each(requiredFields, function(field) { @@ -19373,6 +19381,7 @@ var Q = require('q'); var util = require('../util'); var Main = require('../app'); +var Errors = require('../util/errors'); var Visualization = require('../visuals/visualization').Visualization; var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall; @@ -19400,11 +19409,9 @@ var parse = util.genParseCommand(regexMap, 'processLevelBuilderCommand'); var LevelBuilder = Level.extend({ initialize: function(options) { options = options || {}; + options.level = options.level || {}; - this.options = options; - this.level = {}; - - this.level.startDialog = { + options.level.startDialog = { childViews: [{ type: 'ModalAlert', options: { @@ -19413,10 +19420,10 @@ var LevelBuilder = Level.extend({ '', 'Here are the main steps:', '', - ' * Define the starting tree', - ' * Enter the series of git commands that compose of the (optimal) solution', - ' * Define the goal tree, which also defines the solution', - ' * Enter the command ```finish building``` to specify start dialogs and such' + ' * Define the starting tree with ```define start```', + ' * Enter the series of git commands that compose the (optimal) solution', + ' * Define the goal tree with ```define goal```. Defining the goal also defines the solution', + ' * Enter the command ```finish``` to output your level JSON!' ] } }] @@ -19583,13 +19590,20 @@ var LevelBuilder = Level.extend({ }, finish: function(command, deferred) { - if (!this.level.id) { - this.setID(); + if (!this.gitCommandsIssued.length) { + command.set('error', new Errors.GitError({ + msg: 'Your solution is empty!' + })); + deferred.resolve(); + return; } + if (this.level.hint === undefined) { this.setHint(); } - console.log(this.level, this.startTree); + console.log(this.level); + + command.finishWith(deferred); }, processLevelBuilderCommand: function(command, deferred) { diff --git a/src/js/level/arbiter.js b/src/js/level/arbiter.js index 62178578..1d8155d4 100644 --- a/src/js/level/arbiter.js +++ b/src/js/level/arbiter.js @@ -32,8 +32,11 @@ LevelArbiter.prototype.init = function() { this.validateLevel(level); this.levelMap[level.id] = _.extend( {}, - { index: index }, - level + level, + { + index: index, + id: levelSequenceName + String(index) + } ); // build up the chaining between levels @@ -68,7 +71,6 @@ LevelArbiter.prototype.syncToStorage = function() { LevelArbiter.prototype.validateLevel = function(level) { level = level || {}; var requiredFields = [ - 'id', 'name', 'goalTreeString', 'solutionCommand' diff --git a/src/js/level/builder.js b/src/js/level/builder.js index c1cea2da..0ec76e6f 100644 --- a/src/js/level/builder.js +++ b/src/js/level/builder.js @@ -4,6 +4,7 @@ var Q = require('q'); var util = require('../util'); var Main = require('../app'); +var Errors = require('../util/errors'); var Visualization = require('../visuals/visualization').Visualization; var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall; @@ -23,6 +24,7 @@ var regexMap = { 'define start': /^define start$/, 'show start': /^show start$/, 'hide start': /^hide start$/, + 'define hint': /^define hint$/, 'finish': /^finish$/ }; @@ -31,11 +33,9 @@ var parse = util.genParseCommand(regexMap, 'processLevelBuilderCommand'); var LevelBuilder = Level.extend({ initialize: function(options) { options = options || {}; + options.level = options.level || {}; - this.options = options; - this.level = {}; - - this.level.startDialog = { + options.level.startDialog = { childViews: [{ type: 'ModalAlert', options: { @@ -44,10 +44,11 @@ var LevelBuilder = Level.extend({ '', 'Here are the main steps:', '', - ' * Define the starting tree', - ' * Enter the series of git commands that compose of the (optimal) solution', - ' * Define the goal tree, which also defines the solution', - ' * Enter the command ```finish building``` to specify start dialogs and such' + ' * Define the starting tree with ```define start```', + ' * Enter the series of git commands that compose the (optimal) solution', + ' * Define the goal tree with ```define goal```. Defining the goal also defines the solution', + ' * Optionally define a hint with ```define hint```', + ' * Enter the command ```finish``` to output your level JSON!' ] } }] @@ -198,33 +199,20 @@ var LevelBuilder = Level.extend({ this.showGoal(command, deferred); }, - setHint: function(command, deferred) { + defineHint: 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({ + command.set('error', new Errors.GitError({ msg: 'Your solution is empty!' - }); + })); deferred.resolve(); return; } - if (!this.level.id) { - this.setID(); - } if (this.level.hint === undefined) { this.setHint(); } @@ -239,7 +227,8 @@ var LevelBuilder = Level.extend({ 'define start': this.defineStart, 'show start': this.showStart, 'hide start': this.hideStart, - 'finish': this.finish + 'finish': this.finish, + 'define hint': this.defineHint }; methodMap[command.get('method')].apply(this, arguments); diff --git a/src/js/views/levelDropdownView.js b/src/js/views/levelDropdownView.js index 050ba59e..594ef318 100644 --- a/src/js/views/levelDropdownView.js +++ b/src/js/views/levelDropdownView.js @@ -161,14 +161,7 @@ var LevelDropdownView = ContainedBase.extend({ }, getIndexForID: function(id) { - var index; - var levels = this.sequenceToLevels[this.selectedSequence]; - _.each(levels, function(level, _index) { - if (level.id == id) { - index = _index; - } - }); - return index; + return Main.getLevelArbiter().getLevel(id).index; }, selectFirst: function() { diff --git a/src/levels/intro/1.js b/src/levels/intro/1.js index d738ee5f..cf9e7dd1 100644 --- a/src/levels/intro/1.js +++ b/src/levels/intro/1.js @@ -1,5 +1,4 @@ exports.level = { - id: 'intro1', name: 'Introduction #1', startDialog: { childViews: [{ diff --git a/src/levels/intro/2.js b/src/levels/intro/2.js index fbeda24a..256b1c8d 100644 --- a/src/levels/intro/2.js +++ b/src/levels/intro/2.js @@ -1,5 +1,4 @@ exports.level = { - id: 'intro2', name: 'Introduction #1', goalTreeString: '{"branches":{"master":{"target":"C1","id":"master"},"win":{"target":"C2","id":"win"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"win","id":"HEAD"}}', solutionCommand: 'git checkout -b win; git commit', diff --git a/src/levels/rebase/1.js b/src/levels/rebase/1.js index d4b913cd..256b1c8d 100644 --- a/src/levels/rebase/1.js +++ b/src/levels/rebase/1.js @@ -1,5 +1,4 @@ exports.level = { - id: 'rebase1', name: 'Introduction #1', goalTreeString: '{"branches":{"master":{"target":"C1","id":"master"},"win":{"target":"C2","id":"win"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"win","id":"HEAD"}}', solutionCommand: 'git checkout -b win; git commit', diff --git a/src/levels/rebase/2.js b/src/levels/rebase/2.js index 3a688514..256b1c8d 100644 --- a/src/levels/rebase/2.js +++ b/src/levels/rebase/2.js @@ -1,5 +1,4 @@ exports.level = { - id: 'rebase2', name: 'Introduction #1', goalTreeString: '{"branches":{"master":{"target":"C1","id":"master"},"win":{"target":"C2","id":"win"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"win","id":"HEAD"}}', solutionCommand: 'git checkout -b win; git commit', diff --git a/src/levels/rebase/3.js b/src/levels/rebase/3.js index 251727bc..256b1c8d 100644 --- a/src/levels/rebase/3.js +++ b/src/levels/rebase/3.js @@ -1,5 +1,4 @@ exports.level = { - id: 'rebase3', name: 'Introduction #1', goalTreeString: '{"branches":{"master":{"target":"C1","id":"master"},"win":{"target":"C2","id":"win"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"win","id":"HEAD"}}', solutionCommand: 'git checkout -b win; git commit', diff --git a/todo.txt b/todo.txt index 8306317b..f635e205 100644 --- a/todo.txt +++ b/todo.txt @@ -1,6 +1,5 @@ Big Things ~~~~~~~~~~~~~~~~~~~~~~~~~ -[ ] level builder finish [ ] level builder dialog tester [ ] level builder dialog builder @@ -32,6 +31,7 @@ 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 finish [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