improt random levle

This commit is contained in:
Peter Cottle 2013-01-13 11:27:23 -08:00
parent 45aa088796
commit 24139d8ec5
4 changed files with 192 additions and 24 deletions

View file

@ -4701,7 +4701,8 @@ var Sandbox = Backbone.View.extend({
'iosAlert': this.iosAlert, 'iosAlert': this.iosAlert,
'build level': this.buildLevel, 'build level': this.buildLevel,
'export tree': this.exportTree, 'export tree': this.exportTree,
'import tree': this.importTree 'import tree': this.importTree,
'import level': this.importLevel
}; };
var method = commandMap[command.get('method')]; var method = commandMap[command.get('method')];
@ -4755,6 +4756,51 @@ var Sandbox = Backbone.View.extend({
}); });
}, },
importLevel: function(command, deferred) {
var jsonGrabber = new BuilderViews.MarkdownPresenter({
previewText: 'Paste a level JSON blob in here!',
fillerText: ' '
});
jsonGrabber.deferred.promise
.then(_.bind(function(inputText) {
var Level = require('../level').Level;
try {
var levelJSON = JSON.parse(inputText);
var whenLevelOpen = Q.defer();
this.currentLevel = new Level({
level: levelJSON,
deferred: whenLevelOpen,
command: command
});
whenLevelOpen.promise.then(function() {
command.finishWith(deferred);
});
} catch(e) {
new MultiView({
childViews: [{
type: 'ModalAlert',
options: {
markdowns: [
'## Error!',
'',
'Something is wrong with that level JSON, this happened:',
'',
String(e)
]
}
}]
});
command.finishWith(deferred);
}
}, this))
.fail(function() {
command.finishWith(deferred);
})
.done();
},
exportTree: function(command, deferred) { exportTree: function(command, deferred) {
var treeJSON = JSON.stringify(this.mainVis.gitEngine.exportTree(), null, 2); var treeJSON = JSON.stringify(this.mainVis.gitEngine.exportTree(), null, 2);
@ -6680,7 +6726,7 @@ var Level = Sandbox.extend({
}, },
initName: function() { initName: function() {
if (!this.level.name || !this.level.id) { if (!this.level.name) {
this.level.name = 'Rebase Classic'; this.level.name = 'Rebase Classic';
console.warn('REALLY BAD FORM need ids and names'); console.warn('REALLY BAD FORM need ids and names');
} }
@ -6990,11 +7036,6 @@ var Level = Sandbox.extend({
throw new Errors.CommandResult({ throw new Errors.CommandResult({
msg: hintMsg msg: hintMsg
}); });
}],
[/^build level$/, function() {
throw new Errors.GitError({
msg: "You can't build a level inside a level! Please exit level first"
});
}] }]
]; ];
}, },
@ -7005,6 +7046,20 @@ var Level = Sandbox.extend({
Level.__super__.reset.apply(this, arguments); Level.__super__.reset.apply(this, arguments);
}, },
buildLevel: function(command, deferred) {
this.exitLevel();
setTimeout(function() {
Main.getSandbox().buildLevel(command, deferred);
}, this.getAnimationTime() * 1.5);
},
importLevel: function(command, deferred) {
this.exitLevel();
setTimeout(function() {
Main.getSandbox().importLevel(command, deferred);
}, this.getAnimationTime() * 1.5);
},
startLevel: function(command, deferred) { startLevel: function(command, deferred) {
this.exitLevel(); this.exitLevel();
@ -13219,7 +13274,8 @@ var regexMap = {
'iosAlert': /^iOS alert($|\s)/, 'iosAlert': /^iOS alert($|\s)/,
'build level': /^build level($|\s)/, 'build level': /^build level($|\s)/,
'export tree': /^export tree$/, 'export tree': /^export tree$/,
'import tree': /^import tree$/ 'import tree': /^import tree$/,
'import level': /^import level$/
}; };
exports.instantCommands = instantCommands; exports.instantCommands = instantCommands;
@ -21422,7 +21478,7 @@ var Level = Sandbox.extend({
}, },
initName: function() { initName: function() {
if (!this.level.name || !this.level.id) { if (!this.level.name) {
this.level.name = 'Rebase Classic'; this.level.name = 'Rebase Classic';
console.warn('REALLY BAD FORM need ids and names'); console.warn('REALLY BAD FORM need ids and names');
} }
@ -21732,11 +21788,6 @@ var Level = Sandbox.extend({
throw new Errors.CommandResult({ throw new Errors.CommandResult({
msg: hintMsg msg: hintMsg
}); });
}],
[/^build level$/, function() {
throw new Errors.GitError({
msg: "You can't build a level inside a level! Please exit level first"
});
}] }]
]; ];
}, },
@ -21747,6 +21798,20 @@ var Level = Sandbox.extend({
Level.__super__.reset.apply(this, arguments); Level.__super__.reset.apply(this, arguments);
}, },
buildLevel: function(command, deferred) {
this.exitLevel();
setTimeout(function() {
Main.getSandbox().buildLevel(command, deferred);
}, this.getAnimationTime() * 1.5);
},
importLevel: function(command, deferred) {
this.exitLevel();
setTimeout(function() {
Main.getSandbox().importLevel(command, deferred);
}, this.getAnimationTime() * 1.5);
},
startLevel: function(command, deferred) { startLevel: function(command, deferred) {
this.exitLevel(); this.exitLevel();
@ -22122,7 +22187,8 @@ var Sandbox = Backbone.View.extend({
'iosAlert': this.iosAlert, 'iosAlert': this.iosAlert,
'build level': this.buildLevel, 'build level': this.buildLevel,
'export tree': this.exportTree, 'export tree': this.exportTree,
'import tree': this.importTree 'import tree': this.importTree,
'import level': this.importLevel
}; };
var method = commandMap[command.get('method')]; var method = commandMap[command.get('method')];
@ -22176,6 +22242,51 @@ var Sandbox = Backbone.View.extend({
}); });
}, },
importLevel: function(command, deferred) {
var jsonGrabber = new BuilderViews.MarkdownPresenter({
previewText: 'Paste a level JSON blob in here!',
fillerText: ' '
});
jsonGrabber.deferred.promise
.then(_.bind(function(inputText) {
var Level = require('../level').Level;
try {
var levelJSON = JSON.parse(inputText);
var whenLevelOpen = Q.defer();
this.currentLevel = new Level({
level: levelJSON,
deferred: whenLevelOpen,
command: command
});
whenLevelOpen.promise.then(function() {
command.finishWith(deferred);
});
} catch(e) {
new MultiView({
childViews: [{
type: 'ModalAlert',
options: {
markdowns: [
'## Error!',
'',
'Something is wrong with that level JSON, this happened:',
'',
String(e)
]
}
}]
});
command.finishWith(deferred);
}
}, this))
.fail(function() {
command.finishWith(deferred);
})
.done();
},
exportTree: function(command, deferred) { exportTree: function(command, deferred) {
var treeJSON = JSON.stringify(this.mainVis.gitEngine.exportTree(), null, 2); var treeJSON = JSON.stringify(this.mainVis.gitEngine.exportTree(), null, 2);
@ -22300,7 +22411,8 @@ var regexMap = {
'iosAlert': /^iOS alert($|\s)/, 'iosAlert': /^iOS alert($|\s)/,
'build level': /^build level($|\s)/, 'build level': /^build level($|\s)/,
'export tree': /^export tree$/, 'export tree': /^export tree$/,
'import tree': /^import tree$/ 'import tree': /^import tree$/,
'import level': /^import level$/
}; };
exports.instantCommands = instantCommands; exports.instantCommands = instantCommands;

View file

@ -91,7 +91,7 @@ var Level = Sandbox.extend({
}, },
initName: function() { initName: function() {
if (!this.level.name || !this.level.id) { if (!this.level.name) {
this.level.name = 'Rebase Classic'; this.level.name = 'Rebase Classic';
console.warn('REALLY BAD FORM need ids and names'); console.warn('REALLY BAD FORM need ids and names');
} }
@ -401,11 +401,6 @@ var Level = Sandbox.extend({
throw new Errors.CommandResult({ throw new Errors.CommandResult({
msg: hintMsg msg: hintMsg
}); });
}],
[/^build level$/, function() {
throw new Errors.GitError({
msg: "You can't build a level inside a level! Please exit level first"
});
}] }]
]; ];
}, },
@ -416,6 +411,20 @@ var Level = Sandbox.extend({
Level.__super__.reset.apply(this, arguments); Level.__super__.reset.apply(this, arguments);
}, },
buildLevel: function(command, deferred) {
this.exitLevel();
setTimeout(function() {
Main.getSandbox().buildLevel(command, deferred);
}, this.getAnimationTime() * 1.5);
},
importLevel: function(command, deferred) {
this.exitLevel();
setTimeout(function() {
Main.getSandbox().importLevel(command, deferred);
}, this.getAnimationTime() * 1.5);
},
startLevel: function(command, deferred) { startLevel: function(command, deferred) {
this.exitLevel(); this.exitLevel();

View file

@ -208,7 +208,8 @@ var Sandbox = Backbone.View.extend({
'iosAlert': this.iosAlert, 'iosAlert': this.iosAlert,
'build level': this.buildLevel, 'build level': this.buildLevel,
'export tree': this.exportTree, 'export tree': this.exportTree,
'import tree': this.importTree 'import tree': this.importTree,
'import level': this.importLevel
}; };
var method = commandMap[command.get('method')]; var method = commandMap[command.get('method')];
@ -262,6 +263,51 @@ var Sandbox = Backbone.View.extend({
}); });
}, },
importLevel: function(command, deferred) {
var jsonGrabber = new BuilderViews.MarkdownPresenter({
previewText: 'Paste a level JSON blob in here!',
fillerText: ' '
});
jsonGrabber.deferred.promise
.then(_.bind(function(inputText) {
var Level = require('../level').Level;
try {
var levelJSON = JSON.parse(inputText);
var whenLevelOpen = Q.defer();
this.currentLevel = new Level({
level: levelJSON,
deferred: whenLevelOpen,
command: command
});
whenLevelOpen.promise.then(function() {
command.finishWith(deferred);
});
} catch(e) {
new MultiView({
childViews: [{
type: 'ModalAlert',
options: {
markdowns: [
'## Error!',
'',
'Something is wrong with that level JSON, this happened:',
'',
String(e)
]
}
}]
});
command.finishWith(deferred);
}
}, this))
.fail(function() {
command.finishWith(deferred);
})
.done();
},
exportTree: function(command, deferred) { exportTree: function(command, deferred) {
var treeJSON = JSON.stringify(this.mainVis.gitEngine.exportTree(), null, 2); var treeJSON = JSON.stringify(this.mainVis.gitEngine.exportTree(), null, 2);

View file

@ -56,7 +56,8 @@ var regexMap = {
'iosAlert': /^iOS alert($|\s)/, 'iosAlert': /^iOS alert($|\s)/,
'build level': /^build level($|\s)/, 'build level': /^build level($|\s)/,
'export tree': /^export tree$/, 'export tree': /^export tree$/,
'import tree': /^import tree$/ 'import tree': /^import tree$/,
'import level': /^import level$/
}; };
exports.instantCommands = instantCommands; exports.instantCommands = instantCommands;