mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-29 09:20:03 +02:00
awesome
This commit is contained in:
parent
764fbf63bc
commit
de9d91773a
8 changed files with 461 additions and 270 deletions
|
@ -124,7 +124,7 @@ exports.getEventBaton = function() {
|
|||
|
||||
exports.getCommandUI = function() {
|
||||
return commandUI;
|
||||
}
|
||||
};
|
||||
|
||||
exports.init = init;
|
||||
|
||||
|
|
28
src/js/dialogs/sandbox.js
Normal file
28
src/js/dialogs/sandbox.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
exports.helpDialog = [{
|
||||
type: 'ModalAlert',
|
||||
options: {
|
||||
markdowns: [
|
||||
'## Welcome to LearnGitBranching!',
|
||||
'',
|
||||
'This application is designed to help beginners grasp ',
|
||||
'the powerful concepts behind branching when working ',
|
||||
'with git. We hope you enjoy this application and maybe ',
|
||||
'even learn something!',
|
||||
''
|
||||
]
|
||||
}
|
||||
}, {
|
||||
type: 'ModalAlert',
|
||||
options: {
|
||||
markdowns: [
|
||||
'## The LearnGitBranching Interface',
|
||||
'',
|
||||
'There are features to use within the user interface behind ',
|
||||
'this modal dialog. A list:',
|
||||
'',
|
||||
' * git commands (to interact with git)',
|
||||
' * level commands (to get level hints or solutions)',
|
||||
' * sandbox commands (like this one)'
|
||||
]
|
||||
}
|
||||
}];
|
79
src/js/level/sandbox.js
Normal file
79
src/js/level/sandbox.js
Normal file
|
@ -0,0 +1,79 @@
|
|||
var _ = require('underscore');
|
||||
var Backbone = require('backbone');
|
||||
|
||||
var util = require('../util');
|
||||
var Main = require('../app');
|
||||
|
||||
var Visualization = require('../visuals/visualization').Visualization;
|
||||
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
|
||||
var DisabledMap = require('../level/disabledMap').DisabledMap;
|
||||
var Command = require('../models/commandModel').Command;
|
||||
|
||||
var ModalTerminal = require('../views').ModalTerminal;
|
||||
var ModalAlert = require('../views').ModalAlert;
|
||||
|
||||
var MultiView = require('../views/multiView').MultiView;
|
||||
|
||||
function Sandbox(options) {
|
||||
options = options || {};
|
||||
|
||||
this.mainVis = new Visualization({
|
||||
el: options.el || $('#canvasWrapper')[0]
|
||||
});
|
||||
|
||||
// don't add it to just any collection -- adding to the
|
||||
// CommandUI collection will put in history
|
||||
this.commandCollection = Main.getCommandUI().commandCollection;
|
||||
|
||||
this.parseWaterfall = new ParseWaterfall();
|
||||
this.parseWaterfall.addFirst(
|
||||
'instantWaterfall',
|
||||
new DisabledMap().getInstantCommands()
|
||||
);
|
||||
|
||||
if (!options.defer) {
|
||||
this.takeControl();
|
||||
}
|
||||
}
|
||||
|
||||
Sandbox.prototype.takeControl = function() {
|
||||
Main.getEventBaton().stealBaton('commandSubmitted', this.commandSubmitted, this);
|
||||
Main.getEvents().on('processSandboxCommand', this.processSandboxCommand, this);
|
||||
};
|
||||
|
||||
Sandbox.prototype.commandSubmitted = function(value) {
|
||||
// allow other things to see this command
|
||||
Main.getEvents().trigger('commandSubmittedPassive', value);
|
||||
|
||||
util.splitTextCommand(value, function(command) {
|
||||
this.commandCollection.add(new Command({
|
||||
rawStr: command,
|
||||
parseWaterfall: this.parseWaterfall
|
||||
}));
|
||||
}, this);
|
||||
};
|
||||
|
||||
Sandbox.prototype.processSandboxCommand = function(command, callback) {
|
||||
var commandMap = {
|
||||
help: this.helpDialog
|
||||
};
|
||||
var method = commandMap[command.get('method')];
|
||||
if (!method) { throw new Error('no method for that wut'); }
|
||||
|
||||
method.apply(this, [command, callback]);
|
||||
};
|
||||
|
||||
Sandbox.prototype.helpDialog = function(command, callback) {
|
||||
var helpDialog = new MultiView({
|
||||
childViews: require('../dialogs/sandbox').helpDialog
|
||||
});
|
||||
helpDialog.getPromise().then(_.bind(function() {
|
||||
// the view has been closed, lets go ahead and resolve our command
|
||||
command.set('status', 'finished');
|
||||
callback();
|
||||
}, this))
|
||||
.done();
|
||||
};
|
||||
|
||||
exports.Sandbox = Sandbox;
|
||||
|
|
@ -9,6 +9,7 @@ function EventBaton() {
|
|||
// EventBaton.prototype.on = function(name, func, context) {
|
||||
EventBaton.prototype.stealBaton = function(name, func, context) {
|
||||
if (!name) { throw new Error('need name'); }
|
||||
if (!func) { throw new Error('need func!'); }
|
||||
|
||||
var listeners = this.eventMap[name] || [];
|
||||
listeners.push({
|
||||
|
@ -46,7 +47,8 @@ EventBaton.prototype.releaseBaton = function(name, func, context) {
|
|||
var newListeners = [];
|
||||
var found = false;
|
||||
_.each(listeners, function(listenerObj) {
|
||||
if (listenerObj.func === func) {
|
||||
if (listenerObj.func === func && listenerObj.context === context) {
|
||||
if (found) { console.warn('woah duplicates!!!'); }
|
||||
found = true;
|
||||
} else {
|
||||
newListeners.push(listenerObj);
|
||||
|
@ -54,7 +56,8 @@ EventBaton.prototype.releaseBaton = function(name, func, context) {
|
|||
}, this);
|
||||
|
||||
if (!found) {
|
||||
throw new Error('did not find that function', func, context, name, arguments);
|
||||
console.log('did not find that function', func, context, name, arguments);
|
||||
throw new Error('cant releasebaton if yu dont have it');
|
||||
}
|
||||
this.eventMap[name] = newListeners;
|
||||
};
|
||||
|
|
|
@ -159,7 +159,7 @@ var ModalView = Backbone.View.extend({
|
|||
console.log('window focus doing nothing', e);
|
||||
},
|
||||
|
||||
documentClick: function(e) {
|
||||
onDocumentClick: function(e) {
|
||||
console.log('doc click doing nothing', e);
|
||||
},
|
||||
|
||||
|
|
|
@ -65,7 +65,9 @@ var MultiView = Backbone.View.extend({
|
|||
});
|
||||
|
||||
this.render();
|
||||
this.start();
|
||||
if (!options.wait) {
|
||||
this.start();
|
||||
}
|
||||
},
|
||||
|
||||
onWindowFocus: function() {
|
||||
|
@ -125,11 +127,9 @@ var MultiView = Backbone.View.extend({
|
|||
// other views will take if they need to
|
||||
this.keyboardListener.mute();
|
||||
|
||||
setTimeout(_.bind(function() {
|
||||
_.each(this.childViews, function(childView) {
|
||||
childView.tearDown();
|
||||
});
|
||||
}, this), this.deathTime);
|
||||
_.each(this.childViews, function(childView) {
|
||||
childView.die();
|
||||
});
|
||||
|
||||
this.deferred.resolve();
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue