ok optimistic parsing going

This commit is contained in:
Peter Cottle 2013-01-11 12:35:42 -08:00
parent 8a1986a923
commit f8b9c8b583
9 changed files with 1509 additions and 1317 deletions

File diff suppressed because it is too large Load diff

View file

@ -116,11 +116,18 @@ var init = function() {
$('#commandTextField').on('keyup', makeKeyListener('keyup')); $('#commandTextField').on('keyup', makeKeyListener('keyup'));
$(window).trigger('resize'); $(window).trigger('resize');
/* hacky demo functionality */ // demo functionality
if (/\?demo/.test(window.location.href)) { if (/\?demo/.test(window.location.href)) {
setTimeout(function() { sandbox.mainVis.customEvents.on('gitEngineReady', function() {
eventBaton.trigger('commandSubmitted', "gc; git checkout HEAD~1; git commit; git checkout -b bugFix; gc; gc; git rebase -i HEAD~2; git rebase master; git checkout master; gc; gc; git merge bugFix; help"); eventBaton.trigger(
}, 500); 'commandSubmitted',
[
"gc; git checkout HEAD~1; git commit; git checkout -b bugFix; gc;",
"git rebase -i HEAD~3; git rebase master; git checkout master; gc;",
"git merge bugFix; levels; level rebase1; delay 3000;",
"git checkout -b win; git commit; help"
].join(''));
});
} }
if (/(iPhone|iPod|iPad).*AppleWebKit/i.test(navigator.userAgent)) { if (/(iPhone|iPod|iPad).*AppleWebKit/i.test(navigator.userAgent)) {
setTimeout(function() { setTimeout(function() {

View file

@ -351,3 +351,4 @@ var LevelBuilder = Level.extend({
}); });
exports.LevelBuilder = LevelBuilder; exports.LevelBuilder = LevelBuilder;
exports.regexMap = regexMap;

View file

@ -427,4 +427,4 @@ var Level = Sandbox.extend({
}); });
exports.Level = Level; exports.Level = Level;
exports.regexMap = regexMap;

View file

@ -4,8 +4,9 @@ var GitCommands = require('../git/commands');
var SandboxCommands = require('../level/SandboxCommands'); var SandboxCommands = require('../level/SandboxCommands');
// more or less a static class // more or less a static class
function ParseWaterfall(options) { var ParseWaterfall = function(options) {
options = options || {}; options = options || {};
this.options = options;
this.shortcutWaterfall = options.shortcutWaterfall || [ this.shortcutWaterfall = options.shortcutWaterfall || [
GitCommands.shortcutMap GitCommands.shortcutMap
]; ];
@ -15,11 +16,19 @@ function ParseWaterfall(options) {
SandboxCommands.instantCommands SandboxCommands.instantCommands
]; ];
this.parseWaterfall = options.parseWaterfall || [ // defer the parse waterfall until later...
};
ParseWaterfall.prototype.initParseWaterfall = function() {
// by deferring the initialization here, we dont require()
// level too early (which barfs our init)
this.parseWaterfall = this.options.parseWaterfall || [
GitCommands.parse, GitCommands.parse,
SandboxCommands.parse SandboxCommands.parse,
SandboxCommands.getOptimisticLevelParse(),
SandboxCommands.getOptimisticLevelBuilderParse()
]; ];
} };
ParseWaterfall.prototype.clone = function() { ParseWaterfall.prototype.clone = function() {
return new ParseWaterfall({ return new ParseWaterfall({
@ -30,6 +39,9 @@ ParseWaterfall.prototype.clone = function() {
}; };
ParseWaterfall.prototype.getWaterfallMap = function() { ParseWaterfall.prototype.getWaterfallMap = function() {
if (!this.parseWaterfall) {
this.initParseWaterfall();
}
return { return {
shortcutWaterfall: this.shortcutWaterfall, shortcutWaterfall: this.shortcutWaterfall,
instantWaterfall: this.instantWaterfall, instantWaterfall: this.instantWaterfall,
@ -83,6 +95,10 @@ ParseWaterfall.prototype.processInstant = function(commandStr, instantCommands)
}; };
ParseWaterfall.prototype.parseAll = function(commandStr) { ParseWaterfall.prototype.parseAll = function(commandStr) {
if (!this.parseWaterfall) {
this.initParseWaterfall();
}
var toReturn = false; var toReturn = false;
_.each(this.parseWaterfall, function(parseFunc) { _.each(this.parseWaterfall, function(parseFunc) {
var results = parseFunc(commandStr); var results = parseFunc(commandStr);

View file

@ -60,3 +60,23 @@ var regexMap = {
exports.instantCommands = instantCommands; exports.instantCommands = instantCommands;
exports.parse = util.genParseCommand(regexMap, 'processSandboxCommand'); exports.parse = util.genParseCommand(regexMap, 'processSandboxCommand');
// optimistically parse some level and level builder commands; we do this
// so you can enter things like "level intro1; show goal" and not
// have it barf. when the
// command fires the event, it will check if there is a listener and if not throw
// an error
// note: these are getters / setters because the require kills us
exports.getOptimisticLevelParse = function() {
return util.genParseCommand(
require('../level').regexMap,
'processLevelCommand'
);
};
exports.getOptimisticLevelBuilderParse = function() {
return util.genParseCommand(
require('../level/builder').regexMap,
'processLevelBuilderCommand'
);
};

View file

@ -91,6 +91,19 @@ var CommandBuffer = Backbone.Model.extend({
} }
var Main = require('../app'); var Main = require('../app');
var eventBaton = Main.getEventBaton();
var numListeners = eventBaton.getNumListeners(eventName);
if (!numListeners) {
var Errors = require('../util/errors');
command.set('error', new Errors.GitError({
msg: 'That command is valid, but not supported in this current environment!' +
' Try entering a level or level builder to use that command'
}));
deferred.resolve();
return;
}
Main.getEventBaton().trigger(eventName, command, deferred); Main.getEventBaton().trigger(eventName, command, deferred);
}, },

View file

@ -42,6 +42,11 @@ EventBaton.prototype.trigger = function(name) {
toCall.func.apply(toCall.context, argsToApply); toCall.func.apply(toCall.context, argsToApply);
}; };
EventBaton.prototype.getNumListeners = function(name) {
var listeners = this.eventMap[name] || [];
return listeners.length;
};
EventBaton.prototype.getListenersThrow = function(name) { EventBaton.prototype.getListenersThrow = function(name) {
var listeners = this.eventMap[name]; var listeners = this.eventMap[name];
if (!listeners || !listeners.length) { if (!listeners || !listeners.length) {

View file

@ -457,9 +457,11 @@ var NextLevelConfirm = ConfirmCancelTerminal.extend({
]); ]);
} }
options.modalAlert = { options = _.extend(
markdowns: markdowns {},
}; options,
{ markdowns: markdowns }
);
NextLevelConfirm.__super__.initialize.apply(this, [options]); NextLevelConfirm.__super__.initialize.apply(this, [options]);
} }