WOW REALLY NICE with level switching

This commit is contained in:
Peter Cottle 2013-01-05 22:53:05 -08:00
parent 9460c4b4c6
commit 8e98c4d457
7 changed files with 154 additions and 61 deletions

View file

@ -4583,15 +4583,30 @@ var Sandbox = Backbone.View.extend({
}, },
startLevel: function(command, deferred) { startLevel: function(command, deferred) {
var Level = require('../level').Level; var regexResults = command.get('regexResults') || [];
var desiredID = regexResults[1] || '';
var levelJSON = Main.getLevelArbiter().getLevel(desiredID);
// handle the case where that level is not found...
if (!levelJSON) {
command.addWarning(
'A level for that id "' + desiredID + '" was not found!!'
);
command.set('status', 'error');
deferred.resolve();
return;
}
// we are good to go!! lets prep a bit visually
this.hide(); this.hide();
this.clear(); this.clear();
console.log(command.get('regexResults'));
// we don't even need a reference to this, // we don't even need a reference to this,
// everything will be handled via event baton :DDDDDDDDD // everything will be handled via event baton :DDDDDDDDD
var a = new Level(); var Level = require('../level').Level;
var currentLevel = new Level({
level: levelJSON
});
setTimeout(function() { setTimeout(function() {
command.finishWith(deferred); command.finishWith(deferred);
}, this.getAnimationTime()); }, this.getAnimationTime());
@ -6413,6 +6428,8 @@ var Level = Sandbox.extend({
initialize: function(options) { initialize: function(options) {
options = options || {}; options = options || {};
options.level = options.level || {}; options.level = options.level || {};
console.log('the level im receiving is', options.level);
this.level = options.level; this.level = options.level;
this.gitCommandsIssued = 0; this.gitCommandsIssued = 0;
@ -6430,21 +6447,19 @@ var Level = Sandbox.extend({
}, },
initName: function(options) { initName: function(options) {
this.name = options.name; if (!this.level.name || !this.level.id) {
this.id = options.id; this.level.name = 'Rebase Classic';
if (!this.name || !this.id) {
this.name = 'Rebase Classic';
console.warn('REALLY BAD FORM need ids and names'); console.warn('REALLY BAD FORM need ids and names');
} }
this.levelToolbar = new LevelToolbar({ this.levelToolbar = new LevelToolbar({
name: this.name name: this.level.name
}); });
}, },
initGoalData: function(options) { initGoalData: function(options) {
this.goalTreeString = options.level.goalTree; this.goalTreeString = this.level.goalTreeString;
this.solutionCommand = options.level.solutionCommand; this.solutionCommand = this.level.solutionCommand;
if (!this.goalTreeString) { if (!this.goalTreeString) {
console.warn('woah no goal, using random other one'); console.warn('woah no goal, using random other one');
@ -6471,7 +6486,7 @@ var Level = Sandbox.extend({
startOffCommand: function() { startOffCommand: function() {
Main.getEventBaton().trigger( Main.getEventBaton().trigger(
'commandSubmitted', 'commandSubmitted',
'hint; show goal; delay 2000; hide goal' 'hint; delay 3000; show goal'
); );
}, },
@ -6719,12 +6734,10 @@ var Level = Sandbox.extend({
startLevel: function(command, deferred) { startLevel: function(command, deferred) {
this.exitLevel(); this.exitLevel();
setTimeout(function() {
Main.getSandbox().startLevel(command, deferred); Main.getSandbox().startLevel(command, deferred);
/* }, this.getAnimationTime() * 1.5);
Main.getEventBaton().trigger('commandSubmitted', // wow! that was simple :D
'delay 3000; exit level; delay 500;' + command.get('rawStr')
);
deferred.resolve();*/
}, },
exitLevel: function(command, deferred) { exitLevel: function(command, deferred) {
@ -9866,7 +9879,7 @@ var CanvasTerminalHolder = BaseView.extend({
this.destination = $('body'); this.destination = $('body');
this.JSON = { this.JSON = {
title: options.title || 'Goal To Reach', title: options.title || 'Goal To Reach',
text: options.text || 'You can hide this modal with "hide goal"' text: options.text || 'You can hide this window with "hide goal"'
}; };
this.render(); this.render();
@ -12764,6 +12777,12 @@ function GitVisuals(options) {
this.branchCollection.on('remove', this.removeBranch, this); this.branchCollection.on('remove', this.removeBranch, this);
this.deferred = []; this.deferred = [];
// eventually have origin support here
this.posBoundaries = {
min: 0,
max: 1
};
var Main = require('../app'); var Main = require('../app');
Main.getEvents().on('refreshTree', this.refreshTree, this); Main.getEvents().on('refreshTree', this.refreshTree, this);
} }
@ -13179,7 +13198,11 @@ GitVisuals.prototype.calcBranchStacks = function() {
GitVisuals.prototype.calcWidth = function() { GitVisuals.prototype.calcWidth = function() {
this.maxWidthRecursive(this.rootCommit); this.maxWidthRecursive(this.rootCommit);
this.assignBoundsRecursive(this.rootCommit, 0, 1); this.assignBoundsRecursive(
this.rootCommit,
this.posBoundaries.min,
this.posBoundaries.max
);
}; };
GitVisuals.prototype.maxWidthRecursive = function(commit) { GitVisuals.prototype.maxWidthRecursive = function(commit) {
@ -14073,6 +14096,14 @@ var VisBranch = VisBase.extend({
getCommitPosition: function() { getCommitPosition: function() {
var commit = this.gitEngine.getCommitFromRef(this.get('branch')); var commit = this.gitEngine.getCommitFromRef(this.get('branch'));
var visNode = commit.get('visNode'); var visNode = commit.get('visNode');
var threshold = this.get('gitVisuals').posBoundaries.max;
// somewhat tricky flip management here
if (visNode.get('pos').x > threshold) {
this.set('flip', -1);
} else {
this.set('flip', 1);
}
return visNode.getScreenCoords(); return visNode.getScreenCoords();
}, },
@ -18203,6 +18234,8 @@ var Level = Sandbox.extend({
initialize: function(options) { initialize: function(options) {
options = options || {}; options = options || {};
options.level = options.level || {}; options.level = options.level || {};
console.log('the level im receiving is', options.level);
this.level = options.level; this.level = options.level;
this.gitCommandsIssued = 0; this.gitCommandsIssued = 0;
@ -18220,21 +18253,19 @@ var Level = Sandbox.extend({
}, },
initName: function(options) { initName: function(options) {
this.name = options.name; if (!this.level.name || !this.level.id) {
this.id = options.id; this.level.name = 'Rebase Classic';
if (!this.name || !this.id) {
this.name = 'Rebase Classic';
console.warn('REALLY BAD FORM need ids and names'); console.warn('REALLY BAD FORM need ids and names');
} }
this.levelToolbar = new LevelToolbar({ this.levelToolbar = new LevelToolbar({
name: this.name name: this.level.name
}); });
}, },
initGoalData: function(options) { initGoalData: function(options) {
this.goalTreeString = options.level.goalTree; this.goalTreeString = this.level.goalTreeString;
this.solutionCommand = options.level.solutionCommand; this.solutionCommand = this.level.solutionCommand;
if (!this.goalTreeString) { if (!this.goalTreeString) {
console.warn('woah no goal, using random other one'); console.warn('woah no goal, using random other one');
@ -18261,7 +18292,7 @@ var Level = Sandbox.extend({
startOffCommand: function() { startOffCommand: function() {
Main.getEventBaton().trigger( Main.getEventBaton().trigger(
'commandSubmitted', 'commandSubmitted',
'hint; show goal; delay 2000; hide goal' 'hint; delay 3000; show goal'
); );
}, },
@ -18509,12 +18540,10 @@ var Level = Sandbox.extend({
startLevel: function(command, deferred) { startLevel: function(command, deferred) {
this.exitLevel(); this.exitLevel();
setTimeout(function() {
Main.getSandbox().startLevel(command, deferred); Main.getSandbox().startLevel(command, deferred);
/* }, this.getAnimationTime() * 1.5);
Main.getEventBaton().trigger('commandSubmitted', // wow! that was simple :D
'delay 3000; exit level; delay 500;' + command.get('rawStr')
);
deferred.resolve();*/
}, },
exitLevel: function(command, deferred) { exitLevel: function(command, deferred) {
@ -18772,15 +18801,30 @@ var Sandbox = Backbone.View.extend({
}, },
startLevel: function(command, deferred) { startLevel: function(command, deferred) {
var Level = require('../level').Level; var regexResults = command.get('regexResults') || [];
var desiredID = regexResults[1] || '';
var levelJSON = Main.getLevelArbiter().getLevel(desiredID);
// handle the case where that level is not found...
if (!levelJSON) {
command.addWarning(
'A level for that id "' + desiredID + '" was not found!!'
);
command.set('status', 'error');
deferred.resolve();
return;
}
// we are good to go!! lets prep a bit visually
this.hide(); this.hide();
this.clear(); this.clear();
console.log(command.get('regexResults'));
// we don't even need a reference to this, // we don't even need a reference to this,
// everything will be handled via event baton :DDDDDDDDD // everything will be handled via event baton :DDDDDDDDD
var a = new Level(); var Level = require('../level').Level;
var currentLevel = new Level({
level: levelJSON
});
setTimeout(function() { setTimeout(function() {
command.finishWith(deferred); command.finishWith(deferred);
}, this.getAnimationTime()); }, this.getAnimationTime());
@ -20440,7 +20484,7 @@ var CanvasTerminalHolder = BaseView.extend({
this.destination = $('body'); this.destination = $('body');
this.JSON = { this.JSON = {
title: options.title || 'Goal To Reach', title: options.title || 'Goal To Reach',
text: options.text || 'You can hide this modal with "hide goal"' text: options.text || 'You can hide this window with "hide goal"'
}; };
this.render(); this.render();
@ -21223,6 +21267,12 @@ function GitVisuals(options) {
this.branchCollection.on('remove', this.removeBranch, this); this.branchCollection.on('remove', this.removeBranch, this);
this.deferred = []; this.deferred = [];
// eventually have origin support here
this.posBoundaries = {
min: 0,
max: 1
};
var Main = require('../app'); var Main = require('../app');
Main.getEvents().on('refreshTree', this.refreshTree, this); Main.getEvents().on('refreshTree', this.refreshTree, this);
} }
@ -21638,7 +21688,11 @@ GitVisuals.prototype.calcBranchStacks = function() {
GitVisuals.prototype.calcWidth = function() { GitVisuals.prototype.calcWidth = function() {
this.maxWidthRecursive(this.rootCommit); this.maxWidthRecursive(this.rootCommit);
this.assignBoundsRecursive(this.rootCommit, 0, 1); this.assignBoundsRecursive(
this.rootCommit,
this.posBoundaries.min,
this.posBoundaries.max
);
}; };
GitVisuals.prototype.maxWidthRecursive = function(commit) { GitVisuals.prototype.maxWidthRecursive = function(commit) {
@ -22096,6 +22150,14 @@ var VisBranch = VisBase.extend({
getCommitPosition: function() { getCommitPosition: function() {
var commit = this.gitEngine.getCommitFromRef(this.get('branch')); var commit = this.gitEngine.getCommitFromRef(this.get('branch'));
var visNode = commit.get('visNode'); var visNode = commit.get('visNode');
var threshold = this.get('gitVisuals').posBoundaries.max;
// somewhat tricky flip management here
if (visNode.get('pos').x > threshold) {
this.set('flip', -1);
} else {
this.set('flip', 1);
}
return visNode.getScreenCoords(); return visNode.getScreenCoords();
}, },

View file

@ -26,6 +26,8 @@ var Level = Sandbox.extend({
initialize: function(options) { initialize: function(options) {
options = options || {}; options = options || {};
options.level = options.level || {}; options.level = options.level || {};
console.log('the level im receiving is', options.level);
this.level = options.level; this.level = options.level;
this.gitCommandsIssued = 0; this.gitCommandsIssued = 0;
@ -43,21 +45,19 @@ var Level = Sandbox.extend({
}, },
initName: function(options) { initName: function(options) {
this.name = options.name; if (!this.level.name || !this.level.id) {
this.id = options.id; this.level.name = 'Rebase Classic';
if (!this.name || !this.id) {
this.name = 'Rebase Classic';
console.warn('REALLY BAD FORM need ids and names'); console.warn('REALLY BAD FORM need ids and names');
} }
this.levelToolbar = new LevelToolbar({ this.levelToolbar = new LevelToolbar({
name: this.name name: this.level.name
}); });
}, },
initGoalData: function(options) { initGoalData: function(options) {
this.goalTreeString = options.level.goalTree; this.goalTreeString = this.level.goalTreeString;
this.solutionCommand = options.level.solutionCommand; this.solutionCommand = this.level.solutionCommand;
if (!this.goalTreeString) { if (!this.goalTreeString) {
console.warn('woah no goal, using random other one'); console.warn('woah no goal, using random other one');
@ -84,7 +84,7 @@ var Level = Sandbox.extend({
startOffCommand: function() { startOffCommand: function() {
Main.getEventBaton().trigger( Main.getEventBaton().trigger(
'commandSubmitted', 'commandSubmitted',
'hint; show goal; delay 2000; hide goal' 'hint; delay 3000; show goal'
); );
}, },
@ -332,12 +332,10 @@ var Level = Sandbox.extend({
startLevel: function(command, deferred) { startLevel: function(command, deferred) {
this.exitLevel(); this.exitLevel();
setTimeout(function() {
Main.getSandbox().startLevel(command, deferred); Main.getSandbox().startLevel(command, deferred);
/* }, this.getAnimationTime() * 1.5);
Main.getEventBaton().trigger('commandSubmitted', // wow! that was simple :D
'delay 3000; exit level; delay 500;' + command.get('rawStr')
);
deferred.resolve();*/
}, },
exitLevel: function(command, deferred) { exitLevel: function(command, deferred) {

View file

@ -115,15 +115,30 @@ var Sandbox = Backbone.View.extend({
}, },
startLevel: function(command, deferred) { startLevel: function(command, deferred) {
var Level = require('../level').Level; var regexResults = command.get('regexResults') || [];
var desiredID = regexResults[1] || '';
var levelJSON = Main.getLevelArbiter().getLevel(desiredID);
// handle the case where that level is not found...
if (!levelJSON) {
command.addWarning(
'A level for that id "' + desiredID + '" was not found!!'
);
command.set('status', 'error');
deferred.resolve();
return;
}
// we are good to go!! lets prep a bit visually
this.hide(); this.hide();
this.clear(); this.clear();
console.log(command.get('regexResults'));
// we don't even need a reference to this, // we don't even need a reference to this,
// everything will be handled via event baton :DDDDDDDDD // everything will be handled via event baton :DDDDDDDDD
var a = new Level(); var Level = require('../level').Level;
var currentLevel = new Level({
level: levelJSON
});
setTimeout(function() { setTimeout(function() {
command.finishWith(deferred); command.finishWith(deferred);
}, this.getAnimationTime()); }, this.getAnimationTime());

View file

@ -399,7 +399,7 @@ var CanvasTerminalHolder = BaseView.extend({
this.destination = $('body'); this.destination = $('body');
this.JSON = { this.JSON = {
title: options.title || 'Goal To Reach', title: options.title || 'Goal To Reach',
text: options.text || 'You can hide this modal with "hide goal"' text: options.text || 'You can hide this window with "hide goal"'
}; };
this.render(); this.render();

View file

@ -38,6 +38,12 @@ function GitVisuals(options) {
this.branchCollection.on('remove', this.removeBranch, this); this.branchCollection.on('remove', this.removeBranch, this);
this.deferred = []; this.deferred = [];
// eventually have origin support here
this.posBoundaries = {
min: 0,
max: 1
};
var Main = require('../app'); var Main = require('../app');
Main.getEvents().on('refreshTree', this.refreshTree, this); Main.getEvents().on('refreshTree', this.refreshTree, this);
} }
@ -453,7 +459,11 @@ GitVisuals.prototype.calcBranchStacks = function() {
GitVisuals.prototype.calcWidth = function() { GitVisuals.prototype.calcWidth = function() {
this.maxWidthRecursive(this.rootCommit); this.maxWidthRecursive(this.rootCommit);
this.assignBoundsRecursive(this.rootCommit, 0, 1); this.assignBoundsRecursive(
this.rootCommit,
this.posBoundaries.min,
this.posBoundaries.max
);
}; };
GitVisuals.prototype.maxWidthRecursive = function(commit) { GitVisuals.prototype.maxWidthRecursive = function(commit) {

View file

@ -77,6 +77,14 @@ var VisBranch = VisBase.extend({
getCommitPosition: function() { getCommitPosition: function() {
var commit = this.gitEngine.getCommitFromRef(this.get('branch')); var commit = this.gitEngine.getCommitFromRef(this.get('branch'));
var visNode = commit.get('visNode'); var visNode = commit.get('visNode');
var threshold = this.get('gitVisuals').posBoundaries.max;
// somewhat tricky flip management here
if (visNode.get('pos').x > threshold) {
this.set('flip', -1);
} else {
this.set('flip', 1);
}
return visNode.getScreenCoords(); return visNode.getScreenCoords();
}, },

View file

@ -9,7 +9,6 @@ Big Graphic things:
Medium things: Medium things:
~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ ] level arbiter (has everything by ID) [ ] level arbiter (has everything by ID)
[ ] flip branches on the sides!! i wonder how to determine...
Small things to implement: Small things to implement:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -29,6 +28,7 @@ Big Bugs to fix:
Done things: Done things:
(I only started this on Dec 17th 2012 to get a better sense of what was done) (I only started this on Dec 17th 2012 to get a better sense of what was done)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[x] flip branches on the sides!! i wonder how to determine...
[x] click handlers on goal visualization for the actual canvas elements [x] click handlers on goal visualization for the actual canvas elements
[x] sandbox can launch and takedown levels [x] sandbox can launch and takedown levels
[x] TWO epic bugs squashed: [x] TWO epic bugs squashed: