sandbox command reset

This commit is contained in:
Peter Cottle 2013-01-03 17:41:33 -08:00
parent d6e9b6a962
commit f4179e9723
9 changed files with 203 additions and 18 deletions

View file

@ -31,7 +31,10 @@ function GitEngine(options) {
this.commandOptions = {};
this.generalArgs = [];
this.initUniqueID();
}
GitEngine.prototype.initUniqueID = function() {
// backbone or something uses _.uniqueId, so we make our own here
this.uniqueId = (function() {
var n = 0;
@ -39,7 +42,7 @@ function GitEngine(options) {
return prepend? prepend + n++ : n++;
};
})();
}
};
GitEngine.prototype.defaultInit = function() {
var defaultTree = JSON.parse(unescape("%7B%22branches%22%3A%7B%22master%22%3A%7B%22target%22%3A%22C1%22%2C%22id%22%3A%22master%22%2C%22type%22%3A%22branch%22%7D%7D%2C%22commits%22%3A%7B%22C0%22%3A%7B%22type%22%3A%22commit%22%2C%22parents%22%3A%5B%5D%2C%22author%22%3A%22Peter%20Cottle%22%2C%22createTime%22%3A%22Mon%20Nov%2005%202012%2000%3A56%3A47%20GMT-0800%20%28PST%29%22%2C%22commitMessage%22%3A%22Quick%20Commit.%20Go%20Bears%21%22%2C%22id%22%3A%22C0%22%2C%22rootCommit%22%3Atrue%7D%2C%22C1%22%3A%7B%22type%22%3A%22commit%22%2C%22parents%22%3A%5B%22C0%22%5D%2C%22author%22%3A%22Peter%20Cottle%22%2C%22createTime%22%3A%22Mon%20Nov%2005%202012%2000%3A56%3A47%20GMT-0800%20%28PST%29%22%2C%22commitMessage%22%3A%22Quick%20Commit.%20Go%20Bears%21%22%2C%22id%22%3A%22C1%22%7D%7D%2C%22HEAD%22%3A%7B%22id%22%3A%22HEAD%22%2C%22target%22%3A%22master%22%2C%22type%22%3A%22general%20ref%22%7D%7D"));
@ -130,6 +133,7 @@ GitEngine.prototype.loadTree = function(tree) {
this.instantiateFromTree(tree);
this.reloadGraphics();
this.initUniqueID();
};
GitEngine.prototype.loadTreeFromString = function(treeString) {

View file

@ -26,7 +26,8 @@ var Level = Sandbox.extend({
this.gitCommandsIssued = 0;
this.solved = false;
// possible options on how stringent to be go here
// possible options on how stringent to be on comparisons go here
this.treeCompare = new TreeCompare();
this.goalTreeString = options.level.goalTree;

View file

@ -96,7 +96,8 @@ var Sandbox = Backbone.View.extend({
processSandboxCommand: function(command, deferred) {
var commandMap = {
help: this.helpDialog
help: this.helpDialog,
reset: this.reset
};
var method = commandMap[command.get('method')];
if (!method) { throw new Error('no method for that wut'); }
@ -104,6 +105,13 @@ var Sandbox = Backbone.View.extend({
method.apply(this, [command, deferred]);
},
reset: function(command, deferred) {
this.mainVis.reset();
setTimeout(function() {
command.finishWith(deferred);
}, this.mainVis.getAnimationTime());
},
helpDialog: function(command, deferred) {
var helpDialog = new MultiView({
childViews: require('../dialogs/sandbox').helpDialog

View file

@ -40,7 +40,8 @@ var instantCommands = [
];
var regexMap = {
'help': /^help($|\s)|\?/
'help': /^help($|\s)|\?/,
'reset': /^reset($|\s)/
};
var parse = function(str) {

View file

@ -76,6 +76,11 @@ GitVisuals.prototype.resetAll = function() {
this.commitMap = {};
};
GitVisuals.prototype.tearDown = function() {
this.resetAll();
this.paper.remove();
};
GitVisuals.prototype.assignGitEngine = function(gitEngine) {
this.gitEngine = gitEngine;
this.initHeadBranch();

View file

@ -58,18 +58,59 @@ var Visualization = Backbone.View.extend({
this.gitEngine.loadTreeFromString(this.treeString);
}
this.shown = false;
this.setTreeOpacity(0);
this.fadeTreeIn();
if (!options.wait) {
this.fadeTreeIn();
}
this.customEvents.trigger('gitEngineReady');
},
setTreeOpacity: function(level) {
if (level === 0) {
this.shown = false;
}
$(this.paper.canvas).css('opacity', 0);
},
getAnimationTime: function() { return 300; },
fadeTreeIn: function() {
$(this.paper.canvas).animate({opacity: 1}, 300);
this.shown = true;
$(this.paper.canvas).animate({opacity: 1}, this.getAnimationTime());
},
fadeTreeOut: function() {
this.shown = false;
$(this.paper.canvas).animate({opacity: 0}, this.getAnimationTime());
},
reset: function() {
this.setTreeOpacity(0);
if (this.treeString) {
this.gitEngine.loadTreeFromString(this.treeString);
} else {
this.gitEngine.defaultInit();
}
this.fadeTreeIn();
},
tearDown: function() {
// hmm -- dont think this will work to unbind the event listener...
$(window).off('resize', _.bind(this.myResize, this));
this.gitVisuals.tearDown();
},
die: function() {
this.fadeTreeOut();
setTimeout(_.bind(function() {
if (!this.shown) {
this.tearDown();
}
}, this), this.getAnimationTime());
},
myResize: function() {
@ -91,3 +132,4 @@ var Visualization = Backbone.View.extend({
});
exports.Visualization = Visualization;