first level :DDDDDD

This commit is contained in:
Peter Cottle 2013-01-03 14:37:02 -08:00
parent d400158781
commit 984f139245
6 changed files with 5023 additions and 4758 deletions

File diff suppressed because it is too large Load diff

View file

@ -25,11 +25,12 @@ var init = function() {
* - handling window.focus and zoom events
**/
var Sandbox = require('../level/sandbox').Sandbox;
var Level = require('../level').Level;
var EventBaton = require('../util/eventBaton').EventBaton;
eventBaton = new EventBaton();
commandUI = new CommandUI();
sandbox = new Sandbox();
sandbox = new Level();
// we always want to focus the text area to collect input
var focusTextArea = function() {

View file

@ -5,6 +5,8 @@ var Q = require('q');
var util = require('../util');
var Main = require('../app');
var Sandbox = require('../level/sandbox').Sandbox;
var Visualization = require('../visuals/visualization').Visualization;
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
var DisabledMap = require('../level/disabledMap').DisabledMap;
@ -13,20 +15,88 @@ var GitShim = require('../git/gitShim').GitShim;
var ModalTerminal = require('../views').ModalTerminal;
var ModalAlert = require('../views').ModalAlert;
var MultiView = require('../views/multiView').MultiView;
/*
this.beforeDeferHandler = function(deferred) {
var view = new MultiView({
});
view.getPromise()
.then(function() {
return Q.delay(700);
})
.then(function() {
deferred.resolve();
})
.done();
};*/
var TreeCompare = require('../git/treeCompare').TreeCompare;
var Level = Sandbox.extend({
initialize: function(options) {
options = options || {};
options.level = options.level || {};
this.gitCommandsIssued = 0;
this.solved = false;
// possible options on how stringent to be go here
this.treeCompare = new TreeCompare();
this.goalTreeString = options.level.goalTree;
if (!this.goalTreeString) {
console.warn('woah no goal, using random other one');
this.goalTreeString = '{"branches":{"master":{"target":"C2","id":"master"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"master","id":"HEAD"}}';
}
Sandbox.prototype.initialize.apply(this, [options]);
},
initVisualization: function(options) {
if (!options.level.startTree) {
console.warn('No start tree specified for this level!!! using default...');
}
this.mainVis = new Visualization({
el: options.el || this.getDefaultVisEl(),
treeString: options.level.startTree
});
},
initParseWaterfall: function(options) {
this.parseWaterfall = new ParseWaterfall();
// if we want to disable certain commands...
if (options.level.disabledMap) {
// disable these other commands
this.parseWaterfall.addFirst(
new DisabledMap({
disabledMap: options.level.disabledMap
}).getInstantCommands()
);
}
},
initGitShim: function(options) {
// ok we definitely want a shim here
this.gitShim = new GitShim({
afterCB: _.bind(this.afterCommandCB, this),
afterDeferHandler: _.bind(this.afterCommandDefer, this)
});
},
afterCommandCB: function(command) {
// TODO check if error, but not warning
this.gitCommandsIssued++;
},
afterCommandDefer: function(defer) {
if (this.solved) { return; }
// ok so lets see if they solved it...
var current = this.mainVis.gitEngine.exportTree();
var solved = this.treeCompare.compareTrees(current, this.goalTreeString);
if (!solved) {
defer.resolve();
return;
}
// woohoo!!! they solved the level, lets animate and such
this.levelSolved(defer);
},
levelSolved: function(defer) {
this.mainVis.gitVisuals.finishAnimation()
.then(function() {
defer.resolve();
});
}
});
exports.Level = Level;

View file

@ -33,9 +33,13 @@ var Sandbox = Backbone.View.extend({
}
},
getDefaultVisEl: function() {
return $('#canvasWrapper')[0];
},
initVisualization: function(options) {
this.mainVis = new Visualization({
el: options.el || $('#canvasWrapper')[0]
el: options.el || this.getDefaultVisEl()
});
},
@ -47,11 +51,6 @@ var Sandbox = Backbone.View.extend({
initParseWaterfall: function(options) {
this.parseWaterfall = new ParseWaterfall();
/* DISBALED MAP example!!!
this.parseWaterfall.addFirst(
'instantWaterfall',
new DisabledMap().getInstantCommands()
);*/
},
initGitShim: function(options) {

View file

@ -138,6 +138,7 @@ GitVisuals.prototype.animateAllAttrKeys = function(keys, attr, speed, easing) {
GitVisuals.prototype.finishAnimation = function() {
var _this = this;
var deferred = Q.defer();
var animationDone = Q.defer();
var defaultTime = GRAPHICS.defaultAnimationTime;
var nodeRadius = GRAPHICS.nodeRadius;
@ -218,13 +219,17 @@ GitVisuals.prototype.finishAnimation = function() {
{}
);
}, this))
.then(function() {
animationDone.resolve();
})
.fail(function(reason) {
console.warn('Finish animation failed due to ', reason);
throw reason;
});
console.warn('animation error' + reason);
})
.done();
deferred.resolve(); // start right away
return deferred.promise;
// start our animation chain right away
deferred.resolve();
return animationDone.promise;
};
GitVisuals.prototype.explodeNodes = function() {

View file

@ -1,14 +1,16 @@
Big things:
~~~~~~~~~~~~~~~~~~~~~~~~
[ ] promise-based levels
Big Graphic things:
~~~~~~~~~~~~~~~~~~~~~~~~~
[ ] show goal
[ ] show solution
[ ] show which level you are in! with a little thing on the top
[ ] levels dropdown selection?
Medium things:
~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ ] do an after-paper-initialize type thing so we can insert git shim once
git engine is done.
[ ] move command history into sandbox / visualization?
Commands
========
@ -31,6 +33,9 @@ Big Bugs to fix:
Done things:
(I only started this on Dec 17th 2012 to get a better sense of what was done)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[x] do an after-paper-initialize type thing so we can insert git shim once
git engine is done.
[x] promise-based levels
[x] fixed that to-do entry with the toggle Z thing. now its much more consistent
[x] sandbox a real view now
[x] awesome before and after shims with event baton stealing and passing back