diff --git a/build/bundle.js b/build/bundle.js index 2476eb27..88aeed54 100644 --- a/build/bundle.js +++ b/build/bundle.js @@ -4501,9 +4501,13 @@ var Sandbox = Backbone.View.extend({ } }, + getDefaultVisEl: function() { + return $('#canvasWrapper')[0]; + }, + initVisualization: function(options) { this.mainVis = new Visualization({ - el: options.el || $('#canvasWrapper')[0] + el: options.el || this.getDefaultVisEl() }); }, @@ -4515,11 +4519,6 @@ var Sandbox = Backbone.View.extend({ initParseWaterfall: function(options) { this.parseWaterfall = new ParseWaterfall(); - /* DISBALED MAP example!!! - this.parseWaterfall.addFirst( - 'instantWaterfall', - new DisabledMap().getInstantCommands() - );*/ }, initGitShim: function(options) { @@ -4617,11 +4616,12 @@ var init = function() { * - handling window.focus and zoom events **/ var Sandbox = require('../level/sandbox').Sandbox; + var Level = require('../level').Level; var EventBaton = require('../util/eventBaton').EventBaton; eventBaton = new EventBaton(); commandUI = new CommandUI(); - sandbox = new Sandbox(); + sandbox = new Level(); // we always want to focus the text area to collect input var focusTextArea = function() { @@ -4723,146 +4723,4272 @@ exports.init = init; }); -require.define("/src/js/util/eventBaton.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore'); +require.define("/src/js/level/index.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore'); +var Backbone = require('backbone'); +var Q = require('q'); -function EventBaton() { - this.eventMap = {}; -} +var util = require('../util'); +var Main = require('../app'); -// this method steals the "baton" -- aka, only this method will now -// get called. analogous to events.on -// 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 Sandbox = require('../level/sandbox').Sandbox; - var listeners = this.eventMap[name] || []; - listeners.push({ - func: func, - context: context - }); - this.eventMap[name] = listeners; -}; +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 GitShim = require('../git/gitShim').GitShim; -EventBaton.prototype.sliceOffArgs = function(num, args) { - var newArgs = []; - for (var i = num; i < args.length; i++) { - newArgs.push(args[i]); - } - return newArgs; -}; +var ModalTerminal = require('../views').ModalTerminal; +var ModalAlert = require('../views').ModalAlert; +var MultiView = require('../views/multiView').MultiView; -EventBaton.prototype.trigger = function(name) { - // arguments is weird and doesnt do slice right - var argsToApply = this.sliceOffArgs(1, arguments); +var TreeCompare = require('../git/treeCompare').TreeCompare; - var listeners = this.eventMap[name]; - if (!listeners || !listeners.length) { - console.warn('no listeners for', name); - return; - } +var Level = Sandbox.extend({ + initialize: function(options) { + options = options || {}; + options.level = options.level || {}; - // call the top most listener with context and such - var toCall = listeners.slice(-1)[0]; - toCall.func.apply(toCall.context, argsToApply); -}; + this.gitCommandsIssued = 0; + this.solved = false; + // possible options on how stringent to be go here + this.treeCompare = new TreeCompare(); -EventBaton.prototype.getListenersThrow = function(name) { - var listeners = this.eventMap[name]; - if (!listeners || !listeners.length) { - throw new Error('no one has that baton!' + name); - } - return listeners; -}; - -EventBaton.prototype.passBatonBack = function(name, func, context, args) { - // this method will call the listener BEFORE the name/func pair. this - // basically allows you to put in shims, where you steal batons but pass - // them back if they don't meet certain conditions - var listeners = this.getListenersThrow(name); - - var indexBefore; - _.each(listeners, function(listenerObj, index) { - // skip the first - if (index === 0) { return; } - if (listenerObj.func === func && listenerObj.context === context) { - indexBefore = index - 1; + this.goalTreeString = options.level.goalTree; + if (!this.goalTreeString) { + console.warn('woah no goal, using random other one'); + this.goalTreeString = '{"branches":{"master":{"target":"C2","id":"master"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"master","id":"HEAD"}}'; } - }, this); - if (indexBefore === undefined) { - throw new Error('you are the last baton holder! or i didnt find you'); - } - var toCallObj = listeners[indexBefore]; - toCallObj.func.apply(toCallObj.context, args); -}; + Sandbox.prototype.initialize.apply(this, [options]); + }, -EventBaton.prototype.releaseBaton = function(name, func, context) { - // might be in the middle of the stack, so we have to loop instead of - // just popping blindly - var listeners = this.getListenersThrow(name); - - var newListeners = []; - var found = false; - _.each(listeners, function(listenerObj) { - if (listenerObj.func === func && listenerObj.context === context) { - if (found) { console.warn('woah duplicates!!!'); } - found = true; - } else { - newListeners.push(listenerObj); + initVisualization: function(options) { + if (!options.level.startTree) { + console.warn('No start tree specified for this level!!! using default...'); } - }, this); + this.mainVis = new Visualization({ + el: options.el || this.getDefaultVisEl(), + treeString: options.level.startTree + }); + }, - if (!found) { - console.log('did not find that function', func, context, name, arguments); - throw new Error('cant releasebaton if yu dont have it'); + initParseWaterfall: function(options) { + this.parseWaterfall = new ParseWaterfall(); + + // if we want to disable certain commands... + if (options.level.disabledMap) { + // disable these other commands + this.parseWaterfall.addFirst( + new DisabledMap({ + disabledMap: options.level.disabledMap + }).getInstantCommands() + ); + } + }, + + initGitShim: function(options) { + // ok we definitely want a shim here + this.gitShim = new GitShim({ + afterCB: _.bind(this.afterCommandCB, this), + afterDeferHandler: _.bind(this.afterCommandDefer, this) + }); + }, + + afterCommandCB: function(command) { + // TODO check if error, but not warning + this.gitCommandsIssued++; + }, + + afterCommandDefer: function(defer) { + if (this.solved) { return; } + // ok so lets see if they solved it... + var current = this.mainVis.gitEngine.exportTree(); + var solved = this.treeCompare.compareTrees(current, this.goalTreeString); + + if (!solved) { + defer.resolve(); + return; + } + + // woohoo!!! they solved the level, lets animate and such + this.levelSolved(defer); + }, + + levelSolved: function(defer) { + this.mainVis.gitVisuals.finishAnimation() + .then(function() { + defer.resolve(); + }); } - this.eventMap[name] = newListeners; -}; +}); -exports.EventBaton = EventBaton; +exports.Level = Level; }); -require.define("/src/js/util/zoomLevel.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore'); +require.define("/node_modules/q/package.json",function(require,module,exports,__dirname,__filename,process,global){module.exports = {"main":"q.js"} +}); -var warnOnce = true; +require.define("/node_modules/q/q.js",function(require,module,exports,__dirname,__filename,process,global){// vim:ts=4:sts=4:sw=4: +/*! + * + * Copyright 2009-2012 Kris Kowal under the terms of the MIT + * license found at http://github.com/kriskowal/q/raw/master/LICENSE + * + * With parts by Tyler Close + * Copyright 2007-2009 Tyler Close under the terms of the MIT X license found + * at http://www.opensource.org/licenses/mit-license.html + * Forked at ref_send.js version: 2009-05-11 + * + * With parts by Mark Miller + * Copyright (C) 2011 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ -function detectZoom() { - /** - * Note: this method has only been tested on Chrome - * but seems to work. A much more elaborate library is available here: - * https://github.com/yonran/detect-zoom - * but seems to return a "2" zoom level for my computer (who knows) - * so I can't use it. The ecosystem for zoom level detection is a mess - */ - if (!window.outerWidth || !window.innerWidth) { - if (warnOnce) { - console.warn("Can't detect zoom level correctly :-/"); - warnOnce = false; +(function (definition) { + // Turn off strict mode for this function so we can assign to global.Q + /*jshint strict: false*/ + + // This file will function properly as a