Editing levels in the builder :D Resolves #187

This commit is contained in:
Peter Cottle 2014-11-29 18:13:53 -08:00
parent 7fc33541cc
commit 0aba56ef15
3 changed files with 30 additions and 14 deletions

View file

@ -42,19 +42,31 @@ var parse = util.genParseCommand(regexMap, 'processLevelBuilderCommand');
var LevelBuilder = Level.extend({
initialize: function(options) {
options = options || {};
options.level = options.level || {};
options.level = {};
var locale = intl.getLocale();
options.level.startDialog = {};
options.level.startDialog[locale] = {
childViews: intl.getDialog(require('../dialogs/levelBuilder'))
};
// if we are editing a level our behavior is a bit different
var editLevelJSON;
if (options.editLevel) {
editLevelJSON = Main.getLevelArbiter().getLevel(options.editLevel);
options.level = editLevelJSON;
}
LevelBuilder.__super__.initialize.apply(this, [options]);
if (!options.editLevel) {
this.startDialogObj = undefined;
this.definedGoal = false;
} else {
this.startDialogObj = editLevelJSON.startDialog[locale];
this.definedGoal = true;
}
this.startDialogObj = undefined;
this.definedGoal = false;
// we wont be using this stuff, and its to delete to ensure we overwrite all functions that
// we wont be using this stuff, and it is deleted to ensure we overwrite all functions that
// include that functionality
delete this.treeCompare;
delete this.solved;
@ -68,9 +80,11 @@ var LevelBuilder = Level.extend({
},
initGoalData: function() {
// add some default behavior in the beginning
this.level.goalTreeString = '{"branches":{"master":{"target":"C1","id":"master"},"makeLevel":{"target":"C2","id":"makeLevel"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"makeLevel","id":"HEAD"}}';
this.level.solutionCommand = 'git checkout -b makeLevel; git commit';
// add some default behavior in the beginning if we are not editing
if (!this.options.editLevel) {
this.level.goalTreeString = '{"branches":{"master":{"target":"C1","id":"master"},"makeLevel":{"target":"C2","id":"makeLevel"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"makeLevel","id":"HEAD"}}';
this.level.solutionCommand = 'git checkout -b makeLevel; git commit';
}
LevelBuilder.__super__.initGoalData.apply(this, arguments);
},
@ -272,7 +286,7 @@ var LevelBuilder = Level.extend({
},
finish: function(command, deferred) {
if (!this.gitCommandsIssued.length || !this.definedGoal) {
if (!this.options.editLevel && (!this.gitCommandsIssued.length || !this.definedGoal)) {
command.set('error', new Errors.GitError({
msg: intl.str('solution-empty')
}));