ok demonstraton view coming along

This commit is contained in:
Peter Cottle 2013-01-06 17:25:43 -08:00
parent c1813c346c
commit c5615fe15a
10 changed files with 444 additions and 64 deletions

View file

@ -47,6 +47,12 @@ var init = function() {
$(document).click(function(e) {
eventBaton.trigger('documentClick', e);
});
$(document).bind('keydown', function(e) {
eventBaton.trigger('keydown', e);
});
$(document).bind('keyup', function(e) {
eventBaton.trigger('keyup', e);
});
$(window).on('resize', function(e) {
events.trigger('resize', e);
});

View file

@ -97,10 +97,6 @@ var Level = Sandbox.extend({
this.initGoalVisualization(options);
},
getDefaultGoalVisEl: function() {
return $('#commandLineHistory');
},
initGoalVisualization: function(options) {
// first we make the goal visualization holder
this.goalCanvasHolder = new CanvasTerminalHolder();

View file

@ -19,7 +19,9 @@ function KeyboardListener(options) {
this.aliasMap = options.aliasMap || {};
this.keydownListener = _.bind(this.keydown, this);
this.listen();
if (!options.wait) {
this.listen();
}
}
KeyboardListener.prototype.listen = function() {

View file

@ -3,19 +3,28 @@ var Q = require('q');
// horrible hack to get localStorage Backbone plugin
var Backbone = (!require('../util').isBrowser()) ? require('backbone') : window.Backbone;
var util = require('../util');
var KeyboardListener = require('../util/keyboard').KeyboardListener;
var Command = require('../models/commandModel').Command;
var ModalTerminal = require('../views').ModalTerminal;
var ContainedBase = require('../views').ContainedBase;
var KeyboardListener = require('../util/keyboard').KeyboardListener;
var Visualization = require('../visuals/visualization').Visualization;
var GitDemonstrationView = ContainedBase.extend({
tagName: 'div',
className: 'gitDemonstrationView box horizontal',
template: _.template($('#git-demonstration-view').html()),
events: {
'click div.command > a.uiButton': 'positive'
},
initialize: function(options) {
options = options || {};
this.options = options;
this.JSON = _.extend(
options,
{
beforeMarkdowns: [
'## Git Commits',
@ -28,7 +37,8 @@ var GitDemonstrationView = ContainedBase.extend({
'',
'Go ahead and try the level!'
]
}
},
options
);
var convert = function(markdowns) {
@ -43,9 +53,106 @@ var GitDemonstrationView = ContainedBase.extend({
});
this.render();
this.navEvents = _.clone(Backbone.Events);
this.navEvents.on('positive', this.positive, this);
this.keyboardListener = new KeyboardListener({
events: this.navEvents,
aliasMap: {
enter: 'positive',
right: 'positive'
},
wait: true
});
if (!options.wait) {
this.show();
}
// show the canvas once we slide down
this.visFinished = false;
setTimeout(_.bind(this.initVis, this), this.getAnimationTime());
},
takeControl: function() {
this.hasControl = true;
this.keyboardListener.listen();
},
releaseControl: function() {
if (!this.hasControl) { return; }
this.hasControl = false;
this.keyboardListener.mute();
},
reset: function() {
this.mainVis.reset();
this.demonstrated = false;
this.$el.toggleClass('demonstrated', false);
},
positive: function() {
if (this.demonstrated) {
return;
}
this.$el.toggleClass('demonstrated', true);
this.dispatchCommand(this.JSON.command);
this.demonstrated = true;
this.releaseControl();
},
dispatchCommand: function(value) {
util.splitTextCommand(value, function(commandStr) {
var command = new Command({
rawStr: commandStr
});
this.mainVis.gitEngine.dispatch(command, Q.defer());
}, this);
},
hide: function() {
this.releaseControl();
if (this.visFinished) {
this.mainVis.setTreeIndex(-1);
this.mainVis.setTreeOpacity(0);
}
this.shown = false;
GitDemonstrationView.__super__.hide.apply(this);
},
show: function() {
this.takeControl();
if (this.visFinished) {
setTimeout(_.bind(function() {
if (this.shown) {
this.mainVis.setTreeIndex(300);
this.mainVis.showHarsh();
}
}, this), this.getAnimationTime() * 1);
}
this.shown = true;
GitDemonstrationView.__super__.show.apply(this);
},
die: function() {
if (!this.visFinished) { return; }
GitDemonstrationView.__super__.die.apply(this);
},
initVis: function() {
this.mainVis = new Visualization({
el: this.$('div.visHolder')[0],
noKeyboardInput: true,
noClick: true,
smallCanvas: true,
zIndex: 300
});
this.mainVis.customEvents.on('paperReady', _.bind(function() {
this.visFinished = true;
}, this));
}
});

View file

@ -445,9 +445,7 @@ var LevelToolbar = BaseView.extend({
this.render();
if (!options.wait) {
process.nextTick(_.bind(function() {
this.show();
}, this));
process.nextTick(_.bind(this.show, this));
}
},

View file

@ -615,9 +615,14 @@ GitVisuals.prototype.animateEdges = function(speed) {
}, this);
};
GitVisuals.prototype.getMinLayers = function() {
return (this.options.smallCanvas) ? 4 : 7;
};
GitVisuals.prototype.getDepthIncrement = function(maxDepth) {
// assume there are at least 7 layers until later
maxDepth = Math.max(maxDepth, 7);
// assume there are at least a number of layers until later
// to have better visuals
maxDepth = Math.max(maxDepth, this.getMinLayers());
var increment = 1.0 / maxDepth;
return increment;
};

View file

@ -48,7 +48,8 @@ var Visualization = Backbone.View.extend({
commitCollection: this.commitCollection,
branchCollection: this.branchCollection,
paper: this.paper,
noClick: this.options.noClick
noClick: this.options.noClick,
smallCanvas: this.options.smallCanvas
});
var GitEngine = require('../git').GitEngine;
@ -68,22 +69,26 @@ var Visualization = Backbone.View.extend({
}, this));
this.gitVisuals.drawTreeFirstTime();
if (this.treeString) {
this.gitEngine.loadTreeFromString(this.treeString);
}
if (this.options.zIndex) {
this.setTreeIndex(this.options.zIndex);
}
this.shown = false;
this.setTreeOpacity(0);
// reflow needed
process.nextTick(_.bind(function() {
this.fadeTreeIn();
}, this));
process.nextTick(_.bind(this.fadeTreeIn, this));
this.customEvents.trigger('gitEngineReady');
this.customEvents.trigger('paperReady');
},
setTreeIndex: function(level) {
$(this.paper.canvas).css('z-index', level);
},
setTreeOpacity: function(level) {
if (level === 0) {
this.shown = false;
@ -114,9 +119,12 @@ var Visualization = Backbone.View.extend({
show: function() {
$(this.paper.canvas).css('visibility', 'visible');
process.nextTick(_.bind(function() {
this.fadeTreeIn();
}, this));
setTimeout(_.bind(this.fadeTreeIn, this), 10);
},
showHarsh: function() {
$(this.paper.canvas).css('visibility', 'visible');
this.setTreeOpacity(1);
},
reset: function() {