mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-29 09:20:03 +02:00
optimized CSS a bit
This commit is contained in:
parent
19b6038f55
commit
d5f456fa0c
10 changed files with 615 additions and 489 deletions
|
@ -5,6 +5,23 @@ function TreeCompare() {
|
|||
|
||||
}
|
||||
|
||||
TreeCompare.prototype.compareAllBranchesWithinTrees = function(treeA, treeB) {
|
||||
treeA = this.convertTreeSafe(treeA);
|
||||
treeB = this.convertTreeSafe(treeB);
|
||||
|
||||
var allBranches = _.extend(
|
||||
{},
|
||||
treeA.branches,
|
||||
treeB.branches
|
||||
);
|
||||
|
||||
var result = true;
|
||||
_.uniq(allBranches, function(info, branch) {
|
||||
result = result && this.compareBranchWithinTrees(treeA, treeB, branch);
|
||||
}, this);
|
||||
return result;
|
||||
};
|
||||
|
||||
TreeCompare.prototype.compareBranchesWithinTrees = function(treeA, treeB, branches) {
|
||||
var result = true;
|
||||
_.each(branches, function(branchName) {
|
||||
|
|
|
@ -36,6 +36,7 @@ var Level = Sandbox.extend({
|
|||
|
||||
this.initGoalData(options);
|
||||
Sandbox.prototype.initialize.apply(this, [options]);
|
||||
this.startOffCommand();
|
||||
},
|
||||
|
||||
initGoalData: function(options) {
|
||||
|
@ -58,6 +59,13 @@ var Level = Sandbox.extend({
|
|||
Sandbox.prototype.takeControl.apply(this);
|
||||
},
|
||||
|
||||
startOffCommand: function() {
|
||||
Main.getEventBaton().trigger(
|
||||
'commandSubmitted',
|
||||
'hint; show goal; delay 2000; hide goal'
|
||||
);
|
||||
},
|
||||
|
||||
initVisualization: function(options) {
|
||||
if (!options.level.startTree) {
|
||||
console.warn('No start tree specified for this level!!! using default...');
|
||||
|
@ -174,11 +182,10 @@ var Level = Sandbox.extend({
|
|||
require('../level/commands').parse
|
||||
);
|
||||
|
||||
/*
|
||||
this.parseWaterfall.addFirst(
|
||||
'instantWaterfall',
|
||||
this.getInstantCommands()
|
||||
);*/
|
||||
);
|
||||
|
||||
// if we want to disable certain commands...
|
||||
if (options.level.disabledMap) {
|
||||
|
@ -243,7 +250,7 @@ var Level = Sandbox.extend({
|
|||
|
||||
// ok so lets see if they solved it...
|
||||
var current = this.mainVis.gitEngine.exportTree();
|
||||
var solved = this.treeCompare.compareTrees(current, this.goalTreeString);
|
||||
var solved = this.treeCompare.compareAllBranchesWithinTrees(current, this.goalTreeString);
|
||||
|
||||
if (!solved) {
|
||||
defer.resolve();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var _ = require('underscore');
|
||||
var Q = require('q');
|
||||
// horrible hack to get localStorage Backbone plugin
|
||||
var Backbone = (!require('../util').isBrowser()) ? require('backbone') : window.Backbone;
|
||||
|
||||
|
@ -81,6 +82,7 @@ var Sandbox = Backbone.View.extend({
|
|||
Main.getEvents().trigger('commandSubmittedPassive', value);
|
||||
|
||||
util.splitTextCommand(value, function(command) {
|
||||
console.log('adding command', command);
|
||||
this.commandCollection.add(new Command({
|
||||
rawStr: command,
|
||||
parseWaterfall: this.parseWaterfall
|
||||
|
@ -91,7 +93,8 @@ var Sandbox = Backbone.View.extend({
|
|||
processSandboxCommand: function(command, deferred) {
|
||||
var commandMap = {
|
||||
help: this.helpDialog,
|
||||
reset: this.reset
|
||||
reset: this.reset,
|
||||
delay: this.delay
|
||||
};
|
||||
var method = commandMap[command.get('method')];
|
||||
if (!method) { throw new Error('no method for that wut'); }
|
||||
|
@ -99,6 +102,13 @@ var Sandbox = Backbone.View.extend({
|
|||
method.apply(this, [command, deferred]);
|
||||
},
|
||||
|
||||
delay: function(command, deferred) {
|
||||
var amount = parseInt(command.get('regexResults')[1], 10);
|
||||
setTimeout(function() {
|
||||
command.finishWith(deferred);
|
||||
}, amount);
|
||||
},
|
||||
|
||||
reset: function(command, deferred) {
|
||||
this.mainVis.reset();
|
||||
setTimeout(function() {
|
||||
|
|
|
@ -38,22 +38,27 @@ var instantCommands = [
|
|||
|
||||
var regexMap = {
|
||||
'help': /^help($|\s)|\?/,
|
||||
'reset': /^reset($|\s)/
|
||||
'reset': /^reset($|\s)/,
|
||||
'delay': /^delay (\d+)$/
|
||||
};
|
||||
|
||||
var parse = function(str) {
|
||||
var sandboxMethod;
|
||||
var regexResults;
|
||||
|
||||
_.each(regexMap, function(regex, method) {
|
||||
if (regex.test(str)) {
|
||||
var results = regex.exec(str);
|
||||
if (results) {
|
||||
sandboxMethod = method;
|
||||
regexResults = results;
|
||||
}
|
||||
});
|
||||
|
||||
return (!sandboxMethod) ? false : {
|
||||
toSet: {
|
||||
eventName: 'processSandboxCommand',
|
||||
method: sandboxMethod
|
||||
method: sandboxMethod,
|
||||
regexResults: regexResults
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
@ -67,7 +67,7 @@ var CommandBuffer = Backbone.Model.extend({
|
|||
|
||||
// find a command with no error (aka unprocessed)
|
||||
while (popped.get('error') && this.buffer.length) {
|
||||
popped = this.buffer.pop();
|
||||
popped = this.buffer.shift(0);
|
||||
}
|
||||
if (!popped.get('error')) {
|
||||
this.processCommand(popped);
|
||||
|
|
|
@ -199,6 +199,9 @@ var ModalView = Backbone.View.extend({
|
|||
},
|
||||
|
||||
toggleShow: function(value) {
|
||||
// this prevents releasing keyboard twice
|
||||
if (this.shown === value) { return; }
|
||||
|
||||
if (value) {
|
||||
this.stealKeyboard();
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue