Added schema stubs for about everything

This commit is contained in:
Ruben Vereecken 2014-04-11 14:22:49 +02:00
parent 4776741ea7
commit c2c0496883
15 changed files with 629 additions and 20 deletions

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,66 @@
module.exports =
# 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
# TODO location is debatable
"goal-manager:new-goal-states":
{} # 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 subdivide these channels
# 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

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

View file

@ -7,11 +7,13 @@
* <a href="https://github.com/chalbert/Backbone-Mediator">More details & documentation</a>
*
* @author Nicolas Gilbert
* @author Ruben Vereecken
*
* @requires _
* @requires Backbone
* @requires tv4
*/
(function(factory){
(function (factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
@ -20,31 +22,78 @@
factory(_, Backbone);
}
})(function (_, Backbone){
})(function (_, Backbone) {
'use strict';
/**
* @static
*/
var channels = {},
Subscriber,
/** @borrows Backbone.View#delegateEvents */
Subscriber,
/** @borrows Backbone.View#delegateEvents */
delegateEvents = Backbone.View.prototype.delegateEvents,
/** @borrows Backbone.View#delegateEvents */
/** @borrows Backbone.View#delegateEvents */
undelegateEvents = Backbone.View.prototype.undelegateEvents;
/**
* @class
*/
Backbone.Mediator = {
tv4: window['tv4'].freshApi(),
validationEnabled: true,
defSchemas: {},
channelSchemas: {},
unvalidatedChannels: [],
addChannelSchema: function (channel, schema) {
if (schema && Object.keys(schema).length)
this.channelSchemas[channel] = schema;
},
addDefSchema: function (schema) {
this.tv4.addSchema(schema);
},
addChannelSchemas: function (schemas) {
for (var channel in schemas) {
var schema = schemas[channel];
if (schema && Object.keys(schema).length)
this.channelSchemas[channel] = schema;
}
},
addDefSchemas: function (schemas) {
for (var key in schemas) {
this.tv4.addSchema(schemas[key]);
}
},
/**
* Sets up the tv4 validator.
*/
setUpValidator: function () {
this.tv4 = window['tv4'].freshApi();
},
setValidationEnabled: function (enabled) {
this.validationEnabled = enabled;
},
/**
* Subscribe to a channel
*
* @param channel
*/
subscribe: function(channel, subscription, context, once) {
subscribe: function (channel, subscription, context, once) {
if (!channels[channel]) channels[channel] = [];
if (!(channel in this.defSchemas) && !_.contains(this.unvalidatedChannels, channel)) {
this.unvalidatedChannels.push(channel);
console.warn("Missing schema for channel '" + channel + "'.");
}
channels[channel].push({fn: subscription, context: context || this, once: once});
},
@ -54,15 +103,24 @@
* @param channel
* @params N Extra parametter to pass to handler
*/
publish: function(channel) {
publish: function (channel, arg) {
if (!channels[channel]) return;
var args = [].slice.call(arguments, 1),
subscription;
if (channel in this.channelSchemas && this.validationEnabled) {
var valid = this.tv4.validate(arg, this.channelSchemas[channel]);
if (!valid) {
console.error("Dropping publication because of validation error:", this.tv4.error);
return;
} else if (this.tv4.missing.length) {
console.warn("Missing schema reference to " + this.tv4.missing[0]);
}
}
var subscription;
for (var i = 0; i < channels[channel].length; i++) {
subscription = channels[channel][i];
subscription.fn.apply(subscription.context, args);
subscription.fn.call(subscription.context, arg);
if (subscription.once) {
Backbone.Mediator.unsubscribe(channel, subscription.fn, subscription.context);
i--;
@ -78,7 +136,7 @@
* @param context
*/
unsubscribe: function(channel, fn, context){
unsubscribe: function (channel, fn, context) {
if (!channels[channel]) return;
var subscription;
@ -103,8 +161,6 @@
}
};
Backbone.Mediator.channels = channels;
/**
* Allow to define convention-based subscriptions
@ -120,7 +176,7 @@
/**
* Extend delegateEvents() to set subscriptions
*/
delegateEvents: function(){
delegateEvents: function () {
delegateEvents.apply(this, arguments);
this.setSubscriptions();
},
@ -128,7 +184,7 @@
/**
* Extend undelegateEvents() to unset subscriptions
*/
undelegateEvents: function(){
undelegateEvents: function () {
undelegateEvents.apply(this, arguments);
this.unsetSubscriptions();
},
@ -141,14 +197,14 @@
* @param {Object} [subscriptions] An optional hash of subscription to add
*/
setSubscriptions: function(subscriptions){
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){
_.each(subscriptions, function (subscription, channel) {
var once;
if (subscription.$once) {
subscription = subscription.$once;
@ -165,10 +221,10 @@
* Unsubscribe to each subscription
* @param {Object} [subscriptions] An optional hash of subscription to remove
*/
unsetSubscriptions: function(subscriptions){
unsetSubscriptions: function (subscriptions) {
subscriptions = subscriptions || this.subscriptions;
if (!subscriptions || _.isEmpty(subscriptions)) return;
_.each(subscriptions, function(subscription, channel){
_.each(subscriptions, function (subscription, channel) {
if (_.isString(subscription)) {
subscription = this[subscription];
}
@ -200,4 +256,4 @@
return Backbone;
});
});