mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-26 16:08:34 +02:00
improt random levle
This commit is contained in:
parent
45aa088796
commit
24139d8ec5
4 changed files with 192 additions and 24 deletions
|
@ -208,7 +208,8 @@ var Sandbox = Backbone.View.extend({
|
|||
'iosAlert': this.iosAlert,
|
||||
'build level': this.buildLevel,
|
||||
'export tree': this.exportTree,
|
||||
'import tree': this.importTree
|
||||
'import tree': this.importTree,
|
||||
'import level': this.importLevel
|
||||
};
|
||||
|
||||
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) {
|
||||
var treeJSON = JSON.stringify(this.mainVis.gitEngine.exportTree(), null, 2);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue