Merge branch 'mediator' of https://github.com/rubenvereecken/codecombat into rubenvereecken-mediator

Conflicts:
	bower.json
This commit is contained in:
Scott Erickson 2014-04-11 12:44:29 -07:00
commit d11b6a5751
17 changed files with 519 additions and 1353 deletions

View file

@ -1,5 +1,22 @@
app = require 'application'
channelSchemas =
'app': require './schemas/subscriptions/app'
'bus': require './schemas/subscriptions/bus'
'editor': require './schemas/subscriptions/editor'
'errors': require './schemas/subscriptions/errors'
'level': require './schemas/subscriptions/level'
'misc': require './schemas/subscriptions/misc'
'play': require './schemas/subscriptions/play'
'surface': require './schemas/subscriptions/surface'
'tome': require './schemas/subscriptions/tome'
'user': require './schemas/subscriptions/user'
'world': require './schemas/subscriptions/world'
definitionSchemas =
'bus': require './schemas/definitions/bus'
'misc': require './schemas/definitions/misc'
init = ->
app.initialize()
Backbone.history.start({ pushState: true })
@ -9,6 +26,10 @@ init = ->
treemaExt.setup()
filepicker.setKey('AvlkNoldcTOU4PvKi2Xm7z')
# Set up Backbone.Mediator schemas
setUpDefinitions()
setUpChannels()
$ -> init()
handleNormalUrls = ->
@ -32,3 +53,10 @@ handleNormalUrls = ->
return false
setUpChannels = ->
for channel of channelSchemas
Backbone.Mediator.addChannelSchemas channelSchemas[channel]
setUpDefinitions = ->
for definition of definitionSchemas
Backbone.Mediator.addDefSchemas definitionSchemas[definition]

View file

@ -0,0 +1,14 @@
module.exports =
bus:
title: "Bus"
id: "bus"
$schema: "http://json-schema.org/draft-04/schema#"
description: "Bus" # TODO
type: "object"
properties: # TODO
joined:
type: "boolean"
players:
type: "object"
required: ["joined", "players"]
additionalProperties: false

View file

@ -0,0 +1,12 @@
module.exports =
jQueryEvent:
title: "jQuery Event"
id: "jQueryEvent"
$schema: "http://json-schema.org/draft-04/schema#"
description: "A standard jQuery Event"
type: "object"
properties: # TODO schema complete
altKey:
type: "boolean"
required: []
additionalProperties: true

View file

@ -0,0 +1,18 @@
module.exports =
"application:idle-changed":
{} # TODO schema
"logging-in-with-facebook":
{} # TODO schema
"facebook-logged-in":
{} # TODO schema
"gapi-loaded":
{} # TODO schema
"logging-in-with-gplus":
{} # TODO schema
"gplus-logged-in":
{} # TODO schema

View file

@ -0,0 +1,27 @@
module.exports =
"bus:connecting":
title: "Bus Connecting"
$schema: "http://json-schema.org/draft-04/schema#"
description: "Published when a Bus starts connecting"
type: "object"
properties:
bus:
$ref: "bus"
"bus:connected":
{} # TODO schema
"bus:disconnected":
{} # TODO schema
"bus:new-message":
{} # TODO schema
"bus:player-joined":
{} # TODO schema
"bus:player-left":
{} # TODO schema
"bus:player-states-changed":
{} # TODO schema

View file

@ -0,0 +1,78 @@
module.exports =
"save-new-version":
title: "Save New Version"
$schema: "http://json-schema.org/draft-04/schema#"
description: "Published when a version gets saved"
type: "object"
properties:
major:
type: "boolean"
commitMessage:
type: "string"
required: ["major", "commitMessage"]
additionalProperties: false
# TODO all these events starting with 'level:' should have 'editor' in their name
# to avoid confusion with level play events
"level:view-switched":
title: "Level View Switched"
$schema: "http://json-schema.org/draft-04/schema#"
description: "Published whenever the view switches"
$ref: "jQueryEvent"
"level-components-changed":
{} # TODO schema
"edit-level-component":
{} # TODO schema
"level-component-edited":
{} # TODO schema
"level-component-editing-ended":
{} # TODO schema
"level-systems-changed":
{} # TODO schema
"edit-level-system":
{} # TODO schema
"level-system-added":
{} # TODO schema
"level-system-edited":
{} # TODO schema
"level-system-editing-ended":
{} # TODO schema
"level-thangs-changed":
title: "Level Thangs Changed"
$schema: "http://json-schema.org/draft-04/schema#"
description: "Published when a Thang changes"
type: "object"
properties:
thangsData:
type: "array"
required: ["thangsData"]
additionalProperties: false
"edit-level-thang":
{} # TODO schema
"level-thang-edited":
{} # TODO schema
"level-thang-done-editing":
{} # TODO schema
"level-loaded":
{} # TODO schema
"level-reload-from-data":
{} # TODO schema
"save-new-version":
{} # TODO schema

View file

@ -0,0 +1,5 @@
module.exports =
# app/lib/errors
"server-error":
{} # TODO schema

View file

@ -0,0 +1,20 @@
module.exports =
"audio-played:loaded":
{} # TODO schema
# TODO location is debatable
"note-group-started":
{} # TODO schema
"note-group-ended":
{} # TODO schema
"modal-closed":
{} # TODO schema
# TODO I propose prepending 'modal:'
"save-new-version":
{} # TODO schema
"router:navigate":
{} # TODO schema

View file

@ -0,0 +1,118 @@
module.exports =
# TODO There should be a better way to divide these channels into smaller ones
# TODO location is debatable
"echo-self-wizard-sprite":
{} # TODO schema
"level:session-will-save":
{} # TODO schema
"level-loader:progress-changed":
{} # TODO schema
"level:shift-space-pressed":
{} # TODO schema
"level:escape-pressed":
{} # TODO schema
"level-enable-controls":
{} # TODO schema
"level-set-letterbox":
{} # TODO schema
"level:started":
{} # TODO schema
"level-set-debug":
{} # TODO schema
"level-set-grid":
{} # TODO schema
"tome:cast-spell":
{} # TODO schema
"level:restarted":
{} # TODO schema
"level-set-volume":
{} # TODO schema
"level-set-time":
{} # TODO schema
"level-select-sprite":
{} # TODO schema
"level-set-playing":
{} # TODO schema
"level:team-set":
{} # TODO schema
"level:docs-hidden":
{} # TODO schema
"level:victory-hidden":
{} # TODO schema
"next-game-pressed":
{} # TODO schema
"focus-editor":
{} # TODO schema
"end-current-script":
{} # TODO schema
"script:reset":
{} # TODO schema
"script:ended":
{} # TODO schema
"script:state-changed":
{} # TODO schema
"play-sound":
{} # TODO schema
# TODO refactor name
"onLoadingViewUnveiled":
{} # TODO schema
"playback:manually-scrubbed":
{} # TODO schema
"change:editor-config":
{} # TODO schema
"restart-level":
{} # TODO schema
"play-next-level":
{} # TODO schema
"level-select-sprite":
{} # TODO schema
"level-toggle-grid":
{} # TODO schema
"level-toggle-debug":
{} # TODO schema
"level-toggle-pathfinding":
{} # TODO schema
"level-scrub-forward":
{} # TODO schema
"level-scrub-back":
{} # TODO schema
"goal-manager:new-goal-states":
{} # TODO schema

View file

@ -0,0 +1,96 @@
module.exports = # /app/lib/surface
"camera-dragged":
{} # TODO schema
"camera-zoom-in":
{} # TODO schema
"camera-zoom-out":
{} # TODO schema
"camera-zoom-to":
{} # TODO schema
"camera:zoom-updated":
{} # TODO schema
"sprite:speech-updated":
{} # TODO schema
"dialogue-sound-completed":
{} # TODO schema
"surface:gold-changed":
{} # TODO schema
"surface:coordinate-selected":
{} # TODO schema
"surface:coordinates-shown":
{} # TODO schema
"level-sprite-clear-dialogue":
{} # TODO schema
"sprite:loaded":
{} # TODO schema
"choose-point":
{} # TODO schema
"choose-region":
{} # TODO schema
"surface:new-thang-added":
{} # TODO schema
"surface:sprite-selected":
{} # TODO schema
"thang-began-talking":
{} # TODO schema
"thang-finished-talking":
{} # TODO schema
"surface:world-set-up":
{} # TODO schema
"surface:frame-changed":
{} # TODO schema
"surface:playback-ended":
{} # TODO schema
"surface:playback-restarted":
{} # TODO schema
"level-set-playing":
{} # TODO schema
"registrar-echo-states":
{} # TODO schema
"surface:mouse-moved":
{} # TODO schema
"surface:stage-mouse-down":
{} # TODO schema
"surface:mouse-scrolled":
{} # TODO schema
"surface:ticked":
{} # TODO schema
"surface:mouse-over":
{} # TODO schema
"surface:mouse-out":
{} # TODO schema
"self-wizard:target-changed":
{} # TODO schema
"echo-all-wizard-sprites":
{} # TODO schema

View file

@ -0,0 +1,73 @@
module.exports =
"tome:cast-spell":
{} # TODO schema
# TODO do we really need both 'cast-spell' and 'cast-spells'?
"tome:cast-spells":
{} # TODO schema
"tome:manual-cast":
{} # TODO schema
"tome:spell-created":
{} # TODO schema
"tome:spell-debug-property-hovered":
{} # TODO schema
"tome:toggle-spell-list":
{} # TODO schema
"tome:reload-code":
{} # TODO schema
"tome:palette-hovered":
{} # TODO schema
"tome:palette-pin-toggled":
{} # TODO schema
"tome:palette-clicked":
{} # TODO schema
"tome:spell-statement-index-updated":
{} # TODO schema
# TODO proposition: refactor 'tome' into spell events
"spell-beautify":
{} # TODO schema
"spell-step-forward":
{} # TODO schema
"spell-step-backward":
{} # TODO schema
"tome:spell-loaded":
{} # TODO schema
"tome:cast-spell":
{} # TODO schema
"tome:spell-changed":
{} # TODO schema
"tome:editing-ended":
{} # TODO schema
"tome:editing-began":
{} # TODO schema
"tome:problems-updated":
{} # TODO schema
"tome:thang-list-entry-popover-shown":
{} # TODO schema
"tome:spell-shown":
{} # TODO schema
# TODO proposition: add tome to name
"focus-editor":
{} # TODO schema

View file

@ -0,0 +1,9 @@
module.exports =
"me:synced":
{} # TODO schema
"user-fetched":
{} # TODO schema
"edit-wizard-settings":
{} # TODO schema

View file

@ -0,0 +1,15 @@
module.exports =
"god:user-code-problem":
{} # TODO schema
"god:infinite-loop":
{} # TODO schema
"god:user-code-problem":
{} # TODO schema
"god:new-world-created":
{} # TODO schema
"god:world-load-progress-changed":
{} # TODO schema

View file

@ -38,9 +38,13 @@
"catiline": "~2.9.3",
"d3": "~3.4.4",
"nanoscroller": "~0.8.0",
<<<<<<< HEAD
"jquery.tablesorter": "~2.15.13",
"treema": "~0.0.1",
"bootstrap": "~3.1.1"
=======
"validated-backbone-mediator": "~0.1.3"
>>>>>>> a07457acacd24719568e5abecff2843f59ec97bb
},
"overrides": {
"backbone": {

View file

@ -52,6 +52,8 @@ exports.config =
'vendor/scripts/soundjs-NEXT.combined.js'
'vendor/scripts/tweenjs-NEXT.combined.js'
'vendor/scripts/movieclip-NEXT.min.js'
# Validated Backbone Mediator dependencies
'bower_components/tv4/tv4.js'
# Aether before box2d for some strange Object.defineProperty thing
'bower_components/aether/build/aether.js'

View file

@ -1,203 +0,0 @@
/**
* |-------------------|
* | Backbone-Mediator |
* |-------------------|
* Backbone-Mediator is freely distributable under the MIT license.
*
* <a href="https://github.com/chalbert/Backbone-Mediator">More details & documentation</a>
*
* @author Nicolas Gilbert
*
* @requires _
* @requires Backbone
*/
(function(factory){
'use strict';
if (typeof define === 'function' && define.amd) {
define(['underscore', 'backbone'], factory);
} else {
factory(_, Backbone);
}
})(function (_, Backbone){
'use strict';
/**
* @static
*/
var channels = {},
Subscriber,
/** @borrows Backbone.View#delegateEvents */
delegateEvents = Backbone.View.prototype.delegateEvents,
/** @borrows Backbone.View#delegateEvents */
undelegateEvents = Backbone.View.prototype.undelegateEvents;
/**
* @class
*/
Backbone.Mediator = {
/**
* Subscribe to a channel
*
* @param channel
*/
subscribe: function(channel, subscription, context, once) {
if (!channels[channel]) channels[channel] = [];
channels[channel].push({fn: subscription, context: context || this, once: once});
},
/**
* Trigger all callbacks for a channel
*
* @param channel
* @params N Extra parametter to pass to handler
*/
publish: function(channel) {
if (!channels[channel]) return;
var args = [].slice.call(arguments, 1),
subscription;
for (var i = 0; i < channels[channel].length; i++) {
subscription = channels[channel][i];
subscription.fn.apply(subscription.context, args);
if (subscription.once) {
Backbone.Mediator.unsubscribe(channel, subscription.fn, subscription.context);
i--;
}
}
},
/**
* Cancel subscription
*
* @param channel
* @param fn
* @param context
*/
unsubscribe: function(channel, fn, context){
if (!channels[channel]) return;
var subscription;
for (var i = 0; i < channels[channel].length; i++) {
subscription = channels[channel][i];
if (subscription.fn === fn && subscription.context === context) {
channels[channel].splice(i, 1);
i--;
}
}
},
/**
* Subscribing to one event only
*
* @param channel
* @param subscription
* @param context
*/
subscribeOnce: function (channel, subscription, context) {
Backbone.Mediator.subscribe(channel, subscription, context, true);
}
};
Backbone.Mediator.channels = channels;
/**
* Allow to define convention-based subscriptions
* as an 'subscriptions' hash on a view. Subscriptions
* can then be easily setup and cleaned.
*
* @class
*/
Subscriber = {
/**
* Extend delegateEvents() to set subscriptions
*/
delegateEvents: function(){
delegateEvents.apply(this, arguments);
this.setSubscriptions();
},
/**
* Extend undelegateEvents() to unset subscriptions
*/
undelegateEvents: function(){
undelegateEvents.apply(this, arguments);
this.unsetSubscriptions();
},
/** @property {Object} List of subscriptions, to be defined */
subscriptions: {},
/**
* Subscribe to each subscription
* @param {Object} [subscriptions] An optional hash of subscription to add
*/
setSubscriptions: function(subscriptions){
if (subscriptions) _.extend(this.subscriptions || {}, subscriptions);
subscriptions = subscriptions || this.subscriptions;
if (!subscriptions || _.isEmpty(subscriptions)) return;
// Just to be sure we don't set duplicate
this.unsetSubscriptions(subscriptions);
_.each(subscriptions, function(subscription, channel){
var once;
if (subscription.$once) {
subscription = subscription.$once;
once = true;
}
if (_.isString(subscription)) {
subscription = this[subscription];
}
Backbone.Mediator.subscribe(channel, subscription, this, once);
}, this);
},
/**
* Unsubscribe to each subscription
* @param {Object} [subscriptions] An optional hash of subscription to remove
*/
unsetSubscriptions: function(subscriptions){
subscriptions = subscriptions || this.subscriptions;
if (!subscriptions || _.isEmpty(subscriptions)) return;
_.each(subscriptions, function(subscription, channel){
if (_.isString(subscription)) {
subscription = this[subscription];
}
Backbone.Mediator.unsubscribe(channel, subscription.$once || subscription, this);
}, this);
}
};
/**
* @lends Backbone.View.prototype
*/
_.extend(Backbone.View.prototype, Subscriber);
/**
* @lends Backbone.Mediator
*/
_.extend(Backbone.Mediator, {
/**
* Shortcut for publish
* @function
*/
pub: Backbone.Mediator.publish,
/**
* Shortcut for subscribe
* @function
*/
sub: Backbone.Mediator.subscribe
});
return Backbone;
});

1150
vendor/scripts/tv4.js vendored

File diff suppressed because it is too large Load diff