mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-29 09:20:03 +02:00
vis branch fix
This commit is contained in:
parent
13b616bd04
commit
0c7ff70b14
9 changed files with 501 additions and 21 deletions
|
@ -21,7 +21,8 @@ var LevelToolbar = require('../views').LevelToolbar;
|
|||
var regexMap = {
|
||||
'define goal': /^define goal$/,
|
||||
'define start': /^define start$/,
|
||||
'show start': /^show start$/
|
||||
'show start': /^show start$/,
|
||||
'hide start': /^hide start$/
|
||||
};
|
||||
|
||||
var parse = util.genParseCommand(regexMap, 'processLevelBuilderCommand');
|
||||
|
@ -75,7 +76,9 @@ var LevelBuilder = Level.extend({
|
|||
},
|
||||
|
||||
initStartVisualization: function() {
|
||||
this.startCanvasHolder = new CanvasTerminalHolder();
|
||||
this.startCanvasHolder = new CanvasTerminalHolder({
|
||||
additionalClass: 'startTree'
|
||||
});
|
||||
|
||||
this.startVis = new Visualization({
|
||||
el: this.startCanvasHolder.getCanvasLocation(),
|
||||
|
@ -111,12 +114,20 @@ var LevelBuilder = Level.extend({
|
|||
);
|
||||
},
|
||||
|
||||
buildLevel: function(command, deferred) {
|
||||
this.exitLevel();
|
||||
|
||||
setTimeout(function() {
|
||||
Main.getSandbox().buildLevel(command, deferred);
|
||||
}, this.getAnimationTime() * 1.5);
|
||||
},
|
||||
|
||||
getInstantCommands: function() {
|
||||
return [];
|
||||
},
|
||||
|
||||
takeControl: function() {
|
||||
Main.getEventBaton().stealBaton('processLevelBuilderCommand', this.processLevelCommand, this);
|
||||
Main.getEventBaton().stealBaton('processLevelBuilderCommand', this.processLevelBuilderCommand, this);
|
||||
|
||||
LevelBuilder.__super__.takeControl.apply(this);
|
||||
},
|
||||
|
@ -127,6 +138,70 @@ var LevelBuilder = Level.extend({
|
|||
LevelBuilder.__super__.releaseControl.apply(this);
|
||||
},
|
||||
|
||||
showGoal: function() {
|
||||
this.startCanvasHolder.slideOut();
|
||||
LevelBuilder.__super__.showGoal.apply(this, arguments);
|
||||
},
|
||||
|
||||
showStart: function(command, deferred) {
|
||||
this.goalCanvasHolder.slideOut();
|
||||
this.startCanvasHolder.slideIn();
|
||||
|
||||
setTimeout(function() {
|
||||
command.finishWith(deferred);
|
||||
}, this.startCanvasHolder.getAnimationTime());
|
||||
},
|
||||
|
||||
hideStart: function(command, deferred) {
|
||||
this.startCanvasHolder.slideOut();
|
||||
|
||||
setTimeout(function() {
|
||||
command.finishWith(deferred);
|
||||
}, this.startCanvasHolder.getAnimationTime());
|
||||
},
|
||||
|
||||
defineStart: function(command, deferred) {
|
||||
this.startDie();
|
||||
|
||||
command.addWarning(
|
||||
'Defining start point... solution and goal will be overwritten if they were defined earlier'
|
||||
);
|
||||
this.reset();
|
||||
this.solutionCommand = undefined;
|
||||
|
||||
this.level.startTree = this.mainVis.gitEngine.printTree();
|
||||
this.initStartVisualization();
|
||||
|
||||
this.showStart(command, deferred);
|
||||
},
|
||||
|
||||
defineGoal: function(command, deferred) {
|
||||
this.goalDie();
|
||||
|
||||
if (!this.gitCommandsIssued.length) {
|
||||
command.addWarning(
|
||||
'Your solution is empty!! something is amiss'
|
||||
);
|
||||
}
|
||||
|
||||
this.solutionCommand = this.gitCommandsIssued.join(';');
|
||||
this.goalTreeString = this.mainVis.gitEngine.printTree();
|
||||
this.initGoalVisualization();
|
||||
|
||||
this.showGoal(command, deferred);
|
||||
},
|
||||
|
||||
processLevelBuilderCommand: function(command, deferred) {
|
||||
var methodMap = {
|
||||
'define goal': this.defineGoal,
|
||||
'define start': this.defineStart,
|
||||
'show start': this.showStart,
|
||||
'hide start': this.hideStart
|
||||
};
|
||||
|
||||
methodMap[command.get('method')].apply(this, arguments);
|
||||
},
|
||||
|
||||
afterCommandDefer: function(defer, command) {
|
||||
// we dont need to compare against the goal anymore
|
||||
defer.resolve();
|
||||
|
|
|
@ -118,10 +118,10 @@ var Level = Sandbox.extend({
|
|||
treeString: options.level.startTree
|
||||
});
|
||||
|
||||
this.initGoalVisualization(options);
|
||||
this.initGoalVisualization();
|
||||
},
|
||||
|
||||
initGoalVisualization: function(options) {
|
||||
initGoalVisualization: function() {
|
||||
// first we make the goal visualization holder
|
||||
this.goalCanvasHolder = new CanvasTerminalHolder();
|
||||
|
||||
|
@ -172,6 +172,8 @@ var Level = Sandbox.extend({
|
|||
|
||||
showGoal: function(command, defer) {
|
||||
this.goalCanvasHolder.slideIn();
|
||||
|
||||
if (!command || !defer) { return; }
|
||||
setTimeout(function() {
|
||||
command.finishWith(defer);
|
||||
}, this.goalCanvasHolder.getAnimationTime());
|
||||
|
|
|
@ -148,6 +148,22 @@ var Sandbox = Backbone.View.extend({
|
|||
});
|
||||
},
|
||||
|
||||
buildLevel: function(command, deferred) {
|
||||
this.hide();
|
||||
this.clear();
|
||||
|
||||
var whenBuilderOpen = Q.defer();
|
||||
|
||||
var LevelBuilder = require('../level/builder').LevelBuilder;
|
||||
var levelBuilder = new LevelBuilder({
|
||||
deferred: whenBuilderOpen
|
||||
});
|
||||
|
||||
whenBuilderOpen.promise.then(function() {
|
||||
command.finishWith(deferred);
|
||||
});
|
||||
},
|
||||
|
||||
exitLevel: function(command, deferred) {
|
||||
command.addWarning(
|
||||
"You aren't in a level! You are in a sandbox, start a level with `level [id]`"
|
||||
|
@ -174,7 +190,8 @@ var Sandbox = Backbone.View.extend({
|
|||
'level': this.startLevel,
|
||||
'sandbox': this.exitLevel,
|
||||
'levels': this.showLevels,
|
||||
'iosAlert': this.iosAlert
|
||||
'iosAlert': this.iosAlert,
|
||||
'build level': this.buildLevel
|
||||
};
|
||||
|
||||
var method = commandMap[command.get('method')];
|
||||
|
|
|
@ -35,7 +35,7 @@ var instantCommands = [
|
|||
msg: 'Commands combined!'
|
||||
});
|
||||
}],
|
||||
[/^echo "([a-zA-Z0-9 ]+)"$|^echo ([a-zA-Z0-9 ]+)$/, function(bits) {
|
||||
[/^echo "(.*?)"$|^echo (.*?)$/, function(bits) {
|
||||
var msg = bits[1] || bits[2];
|
||||
console.log(bits, msg);
|
||||
throw new CommandResult({
|
||||
|
@ -53,7 +53,8 @@ var regexMap = {
|
|||
'sandbox': /^sandbox($|\s)/,
|
||||
'level': /^level\s?([a-zA-Z0-9]*)/,
|
||||
'levels': /^levels($|\s)/,
|
||||
'iosAlert': /^iOS alert($|\s)/
|
||||
'iosAlert': /^iOS alert($|\s)/,
|
||||
'build level': /^build level($|\s)/
|
||||
};
|
||||
|
||||
exports.instantCommands = instantCommands;
|
||||
|
|
|
@ -526,6 +526,10 @@ var CanvasTerminalHolder = BaseView.extend({
|
|||
};
|
||||
|
||||
this.render();
|
||||
|
||||
if (options.additionalClass) {
|
||||
this.$el.addClass(options.additionalClass);
|
||||
}
|
||||
},
|
||||
|
||||
getAnimationTime: function() { return 700; },
|
||||
|
|
|
@ -724,6 +724,10 @@ GitVisuals.prototype.visBranchesFront = function() {
|
|||
vBranch.nonTextToFront();
|
||||
vBranch.textToFront();
|
||||
});
|
||||
|
||||
this.visBranchCollection.each(function(visBranch) {
|
||||
vBranch.textToFrontIfInStack();
|
||||
});
|
||||
};
|
||||
|
||||
GitVisuals.prototype.drawTreeFromReload = function() {
|
||||
|
|
|
@ -273,6 +273,12 @@ var VisBranch = VisBase.extend({
|
|||
this.get('text').toFront();
|
||||
},
|
||||
|
||||
textToFrontIfInStack: function() {
|
||||
if (this.getBranchStackIndex() !== 0) {
|
||||
this.get('text').toFront();
|
||||
}
|
||||
},
|
||||
|
||||
getFill: function() {
|
||||
// in the easy case, just return your own fill if you are:
|
||||
// - the HEAD ref
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue