diff --git a/app/Router.coffee b/app/Router.coffee index 9788b66c6..58f93b3b5 100644 --- a/app/Router.coffee +++ b/app/Router.coffee @@ -10,7 +10,7 @@ module.exports = class CocoRouter extends Backbone.Router initialize: -> # http://nerds.airbnb.com/how-to-add-google-analytics-page-tracking-to-57536 @bind 'route', @_trackPageView - Backbone.Mediator.subscribe 'gapi-loaded', @onGPlusAPILoaded, @ + Backbone.Mediator.subscribe 'auth:gplus-api-loaded', @onGPlusAPILoaded, @ Backbone.Mediator.subscribe 'router:navigate', @onNavigate, @ routes: diff --git a/app/initialize.coffee b/app/initialize.coffee index a27c1f7a2..11921b81b 100644 --- a/app/initialize.coffee +++ b/app/initialize.coffee @@ -2,7 +2,7 @@ Backbone.Mediator.setValidationEnabled false app = require 'application' channelSchemas = - 'app': require './schemas/subscriptions/app' + 'auth': require './schemas/subscriptions/auth' 'bus': require './schemas/subscriptions/bus' 'editor': require './schemas/subscriptions/editor' 'errors': require './schemas/subscriptions/errors' @@ -10,8 +10,8 @@ channelSchemas = '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' + 'god': require './schemas/subscriptions/god' + 'scripts': require './schemas/subscriptions/scripts' definitionSchemas = 'bus': require './schemas/definitions/bus' diff --git a/app/lib/Angel.coffee b/app/lib/Angel.coffee index 3e7a8efce..84a5dbf80 100644 --- a/app/lib/Angel.coffee +++ b/app/lib/Angel.coffee @@ -91,7 +91,7 @@ module.exports = class Angel extends CocoClass when 'user-code-problem' Backbone.Mediator.publish 'god:user-code-problem', problem: event.data.problem when 'world-load-progress-changed' - Backbone.Mediator.publish 'god:world-load-progress-changed', event.data + Backbone.Mediator.publish 'god:world-load-progress-changed', progress: event.data.progress unless event.data.progress is 1 or @work.preload or @work.headless or @work.synchronous or @deserializationQueue.length or @shared.firstWorld @worker.postMessage func: 'serializeFramesSoFar' # Stream it! diff --git a/app/lib/AudioPlayer.coffee b/app/lib/AudioPlayer.coffee index b0039cc25..8f752a226 100644 --- a/app/lib/AudioPlayer.coffee +++ b/app/lib/AudioPlayer.coffee @@ -33,7 +33,7 @@ class Media class AudioPlayer extends CocoClass subscriptions: - 'play-sound': (e) -> @playInterfaceSound e.trigger, e.volume + 'audio-player:play-sound': (e) -> @playInterfaceSound e.trigger, e.volume constructor: () -> super() diff --git a/app/lib/Bus.coffee b/app/lib/Bus.coffee index a79f6a67c..cd52e5f4d 100644 --- a/app/lib/Bus.coffee +++ b/app/lib/Bus.coffee @@ -19,11 +19,7 @@ module.exports = Bus = class Bus extends CocoClass Bus.activeBuses[@docName] = @ subscriptions: - 'level-bus-echo-states': 'onEchoStates' - 'me:synced': 'onMeSynced' - - onEchoStates: -> - @notifyStateChanges() + 'auth:me-synced': 'onMeSynced' connect: -> Backbone.Mediator.publish 'bus:connecting', {bus: @} @@ -99,7 +95,7 @@ module.exports = Bus = class Bus extends CocoClass @onPlayerJoined(snapshot) if player.connected and not wasConnected Backbone.Mediator.publish('bus:player-states-changed', {states: @players, bus: @}) - onMeSynced: => + onMeSynced: -> @myConnection?.child('name').set(me.get('name')) countPlayers: -> _.size(@players) diff --git a/app/lib/DefaultScripts.coffee b/app/lib/DefaultScripts.coffee index c1dd80277..8fbd50439 100644 --- a/app/lib/DefaultScripts.coffee +++ b/app/lib/DefaultScripts.coffee @@ -11,7 +11,7 @@ module.exports = [ scriptPrereqs: ["Introduction"] } { - channel: "level-set-playing" + channel: "level:set-playing" noteChain: [] scriptPrereqs: ["Victory Playback"] id: "Victory Playback Started" @@ -22,4 +22,4 @@ module.exports = [ scriptPrereqs: ["Victory Playback Started"] id: "Show Victory" } -] \ No newline at end of file +] diff --git a/app/lib/FacebookHandler.coffee b/app/lib/FacebookHandler.coffee index 61553d946..808a3acbf 100644 --- a/app/lib/FacebookHandler.coffee +++ b/app/lib/FacebookHandler.coffee @@ -14,10 +14,9 @@ userPropsToSave = module.exports = FacebookHandler = class FacebookHandler extends CocoClass subscriptions: - 'facebook-logged-in':'onFacebookLogin' - 'facebook-logged-out': 'onFacebookLogout' + 'auth:logged-in-with-facebook': 'onFacebookLoggedIn' - onFacebookLogin: (e) => + onFacebookLoggedIn: (e) -> # user is logged in also when the page first loads, so check to see # if we really need to do the lookup return if not me @@ -30,9 +29,6 @@ module.exports = FacebookHandler = class FacebookHandler extends CocoClass break FB.api('/me', @onReceiveMeInfo) if doIt - onFacebookLogout: (e) => - console.warn('On facebook logout not implemented.') - onReceiveMeInfo: (r) => unless r.email console.error('could not get data, since no email provided') @@ -45,7 +41,7 @@ module.exports = FacebookHandler = class FacebookHandler extends CocoClass me.set('email', r.email) if r.email me.set('facebookID', r.id) if r.id - Backbone.Mediator.publish('logging-in-with-facebook') + Backbone.Mediator.publish 'auth:logging-in-with-facebook', {} window.tracker?.trackEvent 'Facebook Login' window.tracker?.identify() me.patch({ diff --git a/app/lib/GPlusHandler.coffee b/app/lib/GPlusHandler.coffee index 997a25ab4..7abf8878b 100644 --- a/app/lib/GPlusHandler.coffee +++ b/app/lib/GPlusHandler.coffee @@ -23,8 +23,8 @@ module.exports = GPlusHandler = class GPlusHandler extends CocoClass super() subscriptions: - 'gplus-logged-in':'onGPlusLogin' - 'gapi-loaded':'onGPlusLoaded' + 'auth:logged-in-with-gplus':'onGPlusLogin' + 'auth:gplus-api-loaded':'onGPlusLoaded' onGPlusLoaded: -> session_state = null @@ -88,7 +88,7 @@ module.exports = GPlusHandler = class GPlusHandler extends CocoClass return unless @responsesComplete is 2 return unless me.get('email') and me.get('gplusID') - Backbone.Mediator.publish('logging-in-with-gplus') + Backbone.Mediator.publish 'auth:logging-in-with-gplus', {} gplusID = me.get('gplusID') window.tracker?.trackEvent 'Google Login' window.tracker?.identify() diff --git a/app/lib/GitHubHandler.coffee b/app/lib/GitHubHandler.coffee index 1ae7bd8c0..b0679c080 100644 --- a/app/lib/GitHubHandler.coffee +++ b/app/lib/GitHubHandler.coffee @@ -6,14 +6,14 @@ module.exports = class GitHubHandler extends CocoClass scopes: 'user:email' subscriptions: - 'github-login': 'commenceGitHubLogin' + 'auth:log-in-with-github': 'commenceGitHubLogin' constructor: -> super arguments... @clientID = if application.isProduction() then '9b405bf5fb84590d1f02' else 'fd5c9d34eb171131bc87' @redirectURI = if application.isProduction() then 'http://codecombat.com/github/auth_callback' else 'http://localhost:3000/github/auth_callback' - commenceGitHubLogin: -> + commenceGitHubLogin: (e) -> request = scope: @scopes client_id: @clientID diff --git a/app/lib/God.coffee b/app/lib/God.coffee index 8d1b90228..8574aff99 100644 --- a/app/lib/God.coffee +++ b/app/lib/God.coffee @@ -127,7 +127,7 @@ module.exports = class God extends CocoClass when 'debug-value-return' Backbone.Mediator.publish 'god:debug-value-return', event.data.serialized when 'debug-world-load-progress-changed' - Backbone.Mediator.publish 'god:debug-world-load-progress-changed', event.data + Backbone.Mediator.publish 'god:debug-world-load-progress-changed', progress: event.data.progress onNewWorldCreated: (e) -> @currentUserCodeMap = @filterUserCodeMapWhenFromWorld e.world.userCodeMap diff --git a/app/lib/LevelBus.coffee b/app/lib/LevelBus.coffee index 6fc3816e7..daaa779c8 100644 --- a/app/lib/LevelBus.coffee +++ b/app/lib/LevelBus.coffee @@ -11,6 +11,7 @@ module.exports = class LevelBus extends Bus subscriptions: 'self-wizard:target-changed': 'onSelfWizardTargetChanged' + 'self-wizard:created': 'onSelfWizardCreated' 'tome:editing-began': 'onEditingBegan' 'tome:editing-ended': 'onEditingEnded' 'script:state-changed': 'onScriptStateChanged' @@ -18,8 +19,8 @@ module.exports = class LevelBus extends Bus 'script:reset': 'onScriptReset' 'surface:frame-changed': 'onFrameChanged' 'surface:sprite-selected': 'onSpriteSelected' - 'level-set-playing': 'onSetPlaying' - 'level-show-victory': 'onVictory' + 'level:set-playing': 'onSetPlaying' + 'level:show-victory': 'onVictory' 'tome:spell-changed': 'onSpellChanged' 'tome:spell-created': 'onSpellCreated' 'application:idle-changed': 'onIdleChanged' @@ -51,10 +52,12 @@ module.exports = class LevelBus extends Bus return true unless @session?.get('multiplayer') super() - onSelfWizardTargetChanged: => - wizardSprite = @getSelfWizard() - @wizardRef?.child('targetPos').set(wizardSprite?.targetPos or null) - @wizardRef?.child('targetSprite').set(wizardSprite?.targetSprite?.thang.id or null) + onSelfWizardCreated: (e) -> + @selfWizardSprite = e.sprite + + onSelfWizardTargetChanged: (e) -> + @wizardRef?.child('targetPos').set(@selfWizardSprite?.targetPos or null) + @wizardRef?.child('targetSprite').set(@selfWizardSprite?.targetSprite?.thang.id or null) onMeSynced: => super() @@ -63,9 +66,8 @@ module.exports = class LevelBus extends Bus join: -> super() @wizardRef = @myConnection.child('wizard') - wizardSprite = @getSelfWizard() - @wizardRef?.child('targetPos').set(wizardSprite?.targetPos or null) - @wizardRef?.child('targetSprite').set(wizardSprite?.targetSprite?.thang.id or null) + @wizardRef?.child('targetPos').set(@selfWizardSprite?.targetPos or null) + @wizardRef?.child('targetSprite').set(@selfWizardSprite?.targetSprite?.thang.id or null) @wizardRef?.child('wizardColor1').set(me.get('wizardColor1') or 0.0) disconnect: -> @@ -81,11 +83,6 @@ module.exports = class LevelBus extends Bus @fireRef.remove() @onDisconnect.cancel(-> callback?()) - getSelfWizard: -> - e = {} - Backbone.Mediator.publish('echo-self-wizard-sprite', e) - return e.payload - # UPDATING FIREBASE AND SESSION onEditingBegan: -> @wizardRef?.child('editing').set(true) diff --git a/app/lib/LinkedInHandler.coffee b/app/lib/LinkedInHandler.coffee index 2a6be9a9e..a1a7d0b5a 100644 --- a/app/lib/LinkedInHandler.coffee +++ b/app/lib/LinkedInHandler.coffee @@ -9,7 +9,7 @@ module.exports = LinkedInHandler = class LinkedInHandler extends CocoClass super() subscriptions: - 'linkedin-loaded': 'onLinkedInLoaded' + 'auth:linkedin-api-loaded': 'onLinkedInLoaded' onLinkedInLoaded: (e) -> IN.Event.on IN, 'auth', @onLinkedInAuth diff --git a/app/lib/auth.coffee b/app/lib/auth.coffee index 6d218608d..18cf4f661 100644 --- a/app/lib/auth.coffee +++ b/app/lib/auth.coffee @@ -12,7 +12,7 @@ init = -> me.set 'testGroupNumber', Math.floor(Math.random() * 256) me.patch() - Backbone.listenTo(me, 'sync', -> Backbone.Mediator.publish('me:synced', {me: me})) + Backbone.listenTo me, 'sync', -> Backbone.Mediator.publish('auth:me-synced', me: me) module.exports.createUser = (userObject, failure=backboneFailure, nextURL=null) -> user = new User(userObject) @@ -57,7 +57,7 @@ onSetVolume = (e) -> me.set('volume', e.volume) me.save() -Backbone.Mediator.subscribe('level-set-volume', onSetVolume, module.exports) +Backbone.Mediator.subscribe('level:set-volume', onSetVolume, module.exports) trackFirstArrival = -> # will have to filter out users who log in with existing accounts separately diff --git a/app/lib/scripts/DOMScriptModule.coffee b/app/lib/scripts/DOMScriptModule.coffee index 041dbcc7c..ca87988c7 100644 --- a/app/lib/scripts/DOMScriptModule.coffee +++ b/app/lib/scripts/DOMScriptModule.coffee @@ -15,8 +15,8 @@ module.exports = class DOMScriptModule extends ScriptModule endNotes: -> notes = [] - notes.push({'channel': 'end-level-highlight-dom'}) if @noteGroup.dom.highlight? - notes.push({'channel': 'level-enable-controls'}) if @noteGroup.dom.lock? + notes.push({'channel': 'level:end-highlight-dom'}) if @noteGroup.dom.highlight? + notes.push({'channel': 'level:enable-controls'}) if @noteGroup.dom.lock? return notes skipNotes: -> @@ -28,7 +28,7 @@ module.exports = class DOMScriptModule extends ScriptModule highlightNote: -> dom = @noteGroup.dom note = - channel: 'level-highlight-dom' + channel: 'level:highlight-dom' event: selector: dom.highlight.target delay: dom.highlight.delay @@ -41,7 +41,7 @@ module.exports = class DOMScriptModule extends ScriptModule focusNote: -> note = - channel: 'level-focus-dom' + channel: 'level:focus-dom' event: selector: @noteGroup.dom.focus note @@ -51,7 +51,7 @@ module.exports = class DOMScriptModule extends ScriptModule e.showModal = @noteGroup.dom.showVictory in [true, 'Done Button And Modal'] e.showModal = showModal if showModal? note = - channel: 'level-show-victory' + channel: 'level:show-victory' event: e note @@ -59,8 +59,8 @@ module.exports = class DOMScriptModule extends ScriptModule event = {} lock = @noteGroup.dom.lock event.controls = lock if _.isArray lock # array: subset of controls - channel = if lock then 'level-disable-controls' else 'level-enable-controls' + channel = if lock then 'level:disable-controls' else 'level:enable-controls' return {channel: channel, event: event} letterboxNote: -> - return {channel: 'level-set-letterbox', event: {on: @noteGroup.dom.letterbox}} + return {channel: 'level:set-letterbox', event: {on: @noteGroup.dom.letterbox}} diff --git a/app/lib/scripts/GoalsScriptModule.coffee b/app/lib/scripts/GoalsScriptModule.coffee deleted file mode 100644 index 0e6737b92..000000000 --- a/app/lib/scripts/GoalsScriptModule.coffee +++ /dev/null @@ -1,31 +0,0 @@ -ScriptModule = require './ScriptModule' - -module.exports = class GoalsScriptModule extends ScriptModule - @neededFor: (noteGroup) -> - return noteGroup.goals? - - startNotes: -> - notes = [] - notes.push(@addNote()) if @noteGroup.goals.add? - notes.push(@removeNote()) if @noteGroup.goals.remove? - return notes - - endNotes: -> - return [] - - skipNotes: -> - return @startNotes() - - addNote: -> - note = - channel: 'level-add-goals' - event: - goals: @noteGroup.goals.add - return note - - removeNote: -> - note = - channel: 'level-remove-goals' - event: - goals: @noteGroup.goals.remove - return note diff --git a/app/lib/scripts/PlaybackScriptModule.coffee b/app/lib/scripts/PlaybackScriptModule.coffee index 40487be16..fb0543629 100644 --- a/app/lib/scripts/PlaybackScriptModule.coffee +++ b/app/lib/scripts/PlaybackScriptModule.coffee @@ -25,18 +25,17 @@ module.exports = class PlaybackScriptModule extends ScriptModule playingNote: -> note = - channel: 'level-set-playing' + channel: 'level:set-playing' event: {playing: @noteGroup.playback.playing} return note scrubNote: (instant=false) -> scrub = @noteGroup.playback.scrub note = - channel: 'level-set-time' + channel: 'level:set-time' event: frameOffset: scrub.frameOffset or 2 scrubDuration: if instant then 0 else scrub.duration note.event.time = scrub.toTime if scrub.toTime? note.event.ratio = scrub.toRatio if scrub.toRatio? return note - diff --git a/app/lib/scripts/ScriptManager.coffee b/app/lib/scripts/ScriptManager.coffee index 6983ac199..9892e0201 100644 --- a/app/lib/scripts/ScriptManager.coffee +++ b/app/lib/scripts/ScriptManager.coffee @@ -1,6 +1,3 @@ -# * search for how various places handle or call 'end-current-script' event - - CocoClass = require 'lib/CocoClass' CocoView = require 'views/kinds/CocoView' {scriptMatchesEventPrereqs} = require './../world/script_event_prereqs' @@ -10,8 +7,6 @@ allScriptModules.push(require './SpriteScriptModule') allScriptModules.push(require './DOMScriptModule') allScriptModules.push(require './SurfaceScriptModule') allScriptModules.push(require './PlaybackScriptModule') -GoalScriptsModule = require './GoalsScriptModule' -allScriptModules.push(GoalScriptsModule) allScriptModules.push(require './SoundScriptModule') @@ -32,16 +27,15 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass originalScripts: [] # use these later when you want to revert to an original state subscriptions: - 'end-current-script': 'onEndNoteGroup' - 'end-all-scripts': 'onEndAll' + 'script:end-current-script': 'onEndNoteGroup' 'level:started': -> @setWorldLoading(false) 'level:restarted': 'onLevelRestarted' 'level:shift-space-pressed': 'onEndNoteGroup' 'level:escape-pressed': 'onEndAll' shortcuts: - '⇧+space, space, enter': -> Backbone.Mediator.publish 'level:shift-space-pressed' - 'escape': -> Backbone.Mediator.publish 'level:escape-pressed' + '⇧+space, space, enter': -> Backbone.Mediator.publish 'level:shift-space-pressed', {} + 'escape': -> Backbone.Mediator.publish 'level:escape-pressed', {} # SETUP / TEARDOWN @@ -94,13 +88,14 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass scriptStates: scriptStates timeSinceLastScriptEnded: (if @lastScriptEnded then now - @lastScriptEnded else 0) / 1000 - Backbone.Mediator.publish 'script-manager:tick', stateEvent + Backbone.Mediator.publish 'script:tick', stateEvent # Is this even needed? loadFromSession: -> # load the queue with note groups to skip through @addEndedScriptsFromSession() @addPartiallyEndedScriptFromSession() - @fireGoalNotesEarly() + for noteGroup in @noteGroupQueue + @processNoteGroup(noteGroup) addPartiallyEndedScriptFromSession: -> scripts = @session.get('state').scripts @@ -133,14 +128,6 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass noteGroup.skipMe = true for noteGroup in noteChain @addNoteChain(noteChain, false) - fireGoalNotesEarly: -> - for noteGroup in @noteGroupQueue - @processNoteGroup(noteGroup) - for module in noteGroup.modules - if module instanceof GoalScriptsModule - notes = module.skipNotes() - @processNote(note, noteGroup) for note in notes - setWorldLoading: (@worldLoading) -> @run() unless @worldLoading @@ -238,7 +225,7 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass if nextNoteGroup.script.duration f = => @onNoteGroupTimeout? nextNoteGroup setTimeout(f, nextNoteGroup.script.duration) - Backbone.Mediator.publish('note-group-started') + Backbone.Mediator.publish 'script:note-group-started', {} skipAhead: -> return if @worldLoading @@ -270,7 +257,7 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass publishNote: (note) -> Backbone.Mediator.publish 'playback:real-time-playback-ended', {} - Backbone.Mediator.publish(note.channel, note.event) + Backbone.Mediator.publish note.channel, note.event ? {} # ENDING NOTES @@ -279,7 +266,7 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass @endAll({force:true}) @initProperties() @resetThings() - Backbone.Mediator.publish 'script:reset' + Backbone.Mediator.publish 'script:reset', {} @quiet = false @run() @@ -298,7 +285,7 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass clearTimeout(timeout) for timeout in @currentTimeouts for module in @currentNoteGroup.modules @processNote(note, @currentNoteGroup) for note in module.endNotes() - Backbone.Mediator.publish 'note-group-ended' unless @quiet + Backbone.Mediator.publish 'script:note-group-ended' unless @quiet @scriptInProgress = false @trackScriptCompletionsFromNoteGroup(@currentNoteGroup) @currentNoteGroup = null @@ -307,8 +294,8 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass @resetThings() @ending = false - onEndAll: -> - # press escape + onEndAll: (e) -> + # Escape was pressed. @endAll() endAll: (options) -> @@ -341,8 +328,8 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass @run() resetThings: -> - Backbone.Mediator.publish 'level-enable-controls', {} - Backbone.Mediator.publish 'level-set-letterbox', { on: false } + Backbone.Mediator.publish 'level:enable-controls', {} + Backbone.Mediator.publish 'level:set-letterbox', { on: false } trackScriptCompletionsFromNoteGroup: (noteGroup) -> return unless noteGroup.isLast diff --git a/app/lib/scripts/SoundScriptModule.coffee b/app/lib/scripts/SoundScriptModule.coffee index 616c07f88..ce8d54661 100644 --- a/app/lib/scripts/SoundScriptModule.coffee +++ b/app/lib/scripts/SoundScriptModule.coffee @@ -23,12 +23,12 @@ module.exports = class SoundScriptModule extends ScriptModule addSuppressSelectionSoundsNote: -> note = - channel: 'level-suppress-selection-sounds' + channel: 'level:suppress-selection-sounds' event: {suppress: @noteGroup.sound.suppressSelectionSounds} return note addMusicNote: -> note = - channel: 'level-play-music' + channel: 'music-player:play-music' event: @noteGroup.sound.music return note diff --git a/app/lib/scripts/SpriteScriptModule.coffee b/app/lib/scripts/SpriteScriptModule.coffee index bff0d3c28..7a61ff474 100644 --- a/app/lib/scripts/SpriteScriptModule.coffee +++ b/app/lib/scripts/SpriteScriptModule.coffee @@ -20,7 +20,7 @@ module.exports = class SpritesScriptModule extends ScriptModule spriteMoveNote: (sprite, instant=false) -> duration = if instant then 0 else sprite.move.duration note = - channel: 'level-sprite-move' + channel: 'sprite:move' event: pos: sprite.move.target duration: duration @@ -41,7 +41,7 @@ module.exports = class SpritesScriptModule extends ScriptModule blurb = utils.i18n sprite.say, 'blurb' sound = sprite.say.sound # TODO support sound i18n note = - channel: 'level-sprite-dialogue' + channel: 'level:sprite-dialogue' event: message: text blurb: blurb @@ -54,7 +54,7 @@ module.exports = class SpritesScriptModule extends ScriptModule spriteSelectNote: (sprite) -> note = - channel: 'level-select-sprite' + channel: 'level:select-sprite' event: thangID: if sprite.select then sprite.id else null return note @@ -64,7 +64,7 @@ module.exports = class SpritesScriptModule extends ScriptModule for sprite in @noteGroup.sprites or [] notes[sprite.id] ?= {} notes[sprite.id]['move'] = (@spriteMoveNote sprite, true) if sprite.move? - notes[sprite.id]['say'] = { channel: 'level-sprite-clear-dialogue' } if sprite.say? + notes[sprite.id]['say'] = { channel: 'level:sprite-clear-dialogue' } if sprite.say? noteArray = [] for spriteID of notes for type of notes[spriteID] diff --git a/app/lib/scripts/SurfaceScriptModule.coffee b/app/lib/scripts/SurfaceScriptModule.coffee index d6c3b3016..3f95e3f9b 100644 --- a/app/lib/scripts/SurfaceScriptModule.coffee +++ b/app/lib/scripts/SurfaceScriptModule.coffee @@ -13,7 +13,7 @@ module.exports = class SurfaceScriptModule extends ScriptModule endNotes: -> notes = [] - notes.push({channel:'level-highlight-sprites', event: {thangIDs: []}}) if @noteGroup.surface.highlight? + notes.push({channel:'sprite:highlight-sprites', event: {thangIDs: []}}) if @noteGroup.surface.highlight? notes.push(@surfaceCameraNote(true)) if @noteGroup.surface.focus? notes.push(@surfaceLockSelectNote()) if @noteGroup.surface.lockSelect? return notes @@ -33,12 +33,12 @@ module.exports = class SurfaceScriptModule extends ScriptModule e.duration = if focus.duration? then focus.duration else 1500 e.duration = 0 if instant e.bounds = focus.bounds if focus.bounds? - return { channel: 'level-set-surface-camera', event: e } + return { channel: 'camera:set-camera', event: e } surfaceHighlightNote: -> highlight = @noteGroup.surface.highlight note = - channel: 'level-highlight-sprites' + channel: 'sprite:highlight-sprites' event: thangIDs: highlight.targets delay: highlight.delay @@ -46,4 +46,4 @@ module.exports = class SurfaceScriptModule extends ScriptModule return note surfaceLockSelectNote: -> - return { channel: 'level-lock-select', event: {lock: @noteGroup.surface.lockSelect} } + return { channel: 'level:lock-select', event: {lock: @noteGroup.surface.lockSelect} } diff --git a/app/lib/services/facebook.coffee b/app/lib/services/facebook.coffee index e4e08d52d..5114ba2a1 100644 --- a/app/lib/services/facebook.coffee +++ b/app/lib/services/facebook.coffee @@ -8,7 +8,7 @@ module.exports = initializeFacebook = -> cookie: true # enable cookies to allow the server to access the session xfbml: true # parse XFBML - Backbone.Mediator.publish 'fbapi-loaded' + Backbone.Mediator.publish 'auth:facebook-api-loaded', {} # This is fired for any auth related change, such as login, logout or session refresh. FB.Event.subscribe 'auth.authResponseChange', (response) -> @@ -17,13 +17,12 @@ module.exports = initializeFacebook = -> if response.status is 'connected' # They have logged in to the app. - Backbone.Mediator.publish 'facebook-logged-in', - response: response + Backbone.Mediator.publish 'facebook-logged-in', response: response else if response.status is 'not_authorized' # else - # + # # Load the SDK asynchronously ((d) -> diff --git a/app/lib/services/google.coffee b/app/lib/services/google.coffee index 0e470a375..bda5d1d24 100644 --- a/app/lib/services/google.coffee +++ b/app/lib/services/google.coffee @@ -1,9 +1,9 @@ module.exports = initializeGoogle = -> window.onGPlusLoaded = -> - Backbone.Mediator.publish 'gapi-loaded' + Backbone.Mediator.publish 'auth:gplus-api-loaded', {} return window.signinCallback = (authResult) -> - Backbone.Mediator.publish 'gplus-logged-in', authResult if authResult['access_token'] + Backbone.Mediator.publish 'auth:logged-in-with-gplus', authResult if authResult.access_token return (-> po = document.createElement('script') diff --git a/app/lib/services/linkedin.coffee b/app/lib/services/linkedin.coffee index 9134d77bb..7c1a22a63 100644 --- a/app/lib/services/linkedin.coffee +++ b/app/lib/services/linkedin.coffee @@ -1,7 +1,7 @@ module.exports = initializeLinkedIn = -> window.linkedInAsyncInit = -> #console.log 'Linkedin async init success!' - Backbone.Mediator.publish 'linkedin-loaded' + Backbone.Mediator.publish 'auth:linkedin-api-loaded', {} linkedInSnippet = '' diff --git a/app/lib/surface/Camera.coffee b/app/lib/surface/Camera.coffee index 4a65f52db..d359561cc 100644 --- a/app/lib/surface/Camera.coffee +++ b/app/lib/surface/Camera.coffee @@ -40,9 +40,9 @@ module.exports = class Camera extends CocoClass # INIT subscriptions: - 'camera-zoom-in': 'onZoomIn' - 'camera-zoom-out': 'onZoomOut' - 'camera-zoom-to': 'onZoomTo' + 'camera:zoom-in': 'onZoomIn' + 'camera:zoom-out': 'onZoomOut' + 'camera:zoom-to': 'onZoomTo' 'level:restarted': 'onLevelRestarted' 'surface:mouse-scrolled': 'onMouseScrolled' 'sprite:mouse-down': 'onMouseDown' @@ -187,7 +187,7 @@ module.exports = class Camera extends CocoClass y: target.y + (@lastPos.y - e.originalEvent.rawY) / @zoom @zoomTo newPos, @zoom, 0 @lastPos = {x: e.originalEvent.rawX, y: e.originalEvent.rawY} - Backbone.Mediator.publish 'camera:dragged' + Backbone.Mediator.publish 'camera:dragged', {} onLevelRestarted: -> @setBounds(@firstBounds, false) @@ -322,5 +322,5 @@ module.exports = class Camera extends CocoClass createjs.Tween.removeTweens @ super() - onZoomTo: (pos, time) -> - @zoomTo @worldToSurface(pos), @zoom, time + onZoomTo: (e) -> + @zoomTo @worldToSurface(e.pos), @zoom, e.duration diff --git a/app/lib/surface/CocoSprite.coffee b/app/lib/surface/CocoSprite.coffee index 711b0cca0..23e16cec8 100644 --- a/app/lib/surface/CocoSprite.coffee +++ b/app/lib/surface/CocoSprite.coffee @@ -57,11 +57,11 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass currentAction: null # related action that is right now playing subscriptions: - 'level-sprite-dialogue': 'onDialogue' - 'level-sprite-clear-dialogue': 'onClearDialogue' - 'level-set-letterbox': 'onSetLetterbox' + 'level:sprite-dialogue': 'onDialogue' + 'level:sprite-clear-dialogue': 'onClearDialogue' + 'level:set-letterbox': 'onSetLetterbox' 'surface:ticked': 'onSurfaceTicked' - 'level-sprite-move': 'onMove' + 'sprite:move': 'onMove' constructor: (@thangType, options) -> super() @@ -519,14 +519,11 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass @imageObject.on 'pressmove', @onMouseEvent, @, false, 'sprite:dragged' @imageObject.on 'pressup', @onMouseEvent, @, false, 'sprite:mouse-up' - onSetLetterbox: (e) -> - @letterboxOn = e.on - onMouseEvent: (e, ourEventName) -> return if @letterboxOn or not @imageObject p = @imageObject p = p.parent while p.parent - newEvent = sprite: @, thang: @thang, originalEvent: e, canvas:p.canvas + newEvent = sprite: @, thang: @thang, originalEvent: e, canvas: p.canvas @trigger ourEventName, newEvent Backbone.Mediator.publish ourEventName, newEvent @@ -680,7 +677,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass sound = e.sound ? AudioPlayer.soundForDialogue e.message, @thangType.get 'soundTriggers' @dialogueSoundInstance?.stop() if @dialogueSoundInstance = @playSound sound, false - @dialogueSoundInstance.addEventListener 'complete', -> Backbone.Mediator.publish 'dialogue-sound-completed' + @dialogueSoundInstance.addEventListener 'complete', -> Backbone.Mediator.publish 'sprite:dialogue-sound-completed', {} @notifySpeechUpdated e onClearDialogue: (e) -> @@ -688,6 +685,9 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass @dialogueSoundInstance?.stop() @notifySpeechUpdated {} + onSetLetterbox: (e) -> + @letterboxOn = e.on + setNameLabel: (name) -> label = @addLabel 'name', Label.STYLE_NAME label.setText name @@ -750,7 +750,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass distance = @thang.pos.distance target.pos offset = Math.max(target.width, target.height, 2) / 2 + 3 pos = Vector.add(@thang.pos, heading.multiply(distance - offset)) - Backbone.Mediator.publish 'level-sprite-clear-dialogue', {} + Backbone.Mediator.publish 'level:sprite-clear-dialogue', {} @onClearDialogue() args = [pos] args.push(e.duration) if e.duration? diff --git a/app/lib/surface/CoordinateGrid.coffee b/app/lib/surface/CoordinateGrid.coffee index 1d796ada2..113731141 100644 --- a/app/lib/surface/CoordinateGrid.coffee +++ b/app/lib/surface/CoordinateGrid.coffee @@ -2,7 +2,7 @@ CocoClass = require 'lib/CocoClass' module.exports = class CoordinateGrid extends CocoClass subscriptions: - 'level-toggle-grid': 'onToggleGrid' + 'level:toggle-grid': 'onToggleGrid' shortcuts: 'ctrl+g, ⌘+g': 'onToggleGrid' diff --git a/app/lib/surface/DebugDisplay.coffee b/app/lib/surface/DebugDisplay.coffee index da287e6ed..cb4eee996 100644 --- a/app/lib/surface/DebugDisplay.coffee +++ b/app/lib/surface/DebugDisplay.coffee @@ -1,7 +1,7 @@ module.exports = class DebugDisplay extends createjs.Container layerPriority: 20 subscriptions: - 'level-set-debug': 'onSetDebug' + 'level:set-debug': 'onSetDebug' constructor: (options) -> super() diff --git a/app/lib/surface/Dimmer.coffee b/app/lib/surface/Dimmer.coffee index a34740468..2d902fb0f 100644 --- a/app/lib/surface/Dimmer.coffee +++ b/app/lib/surface/Dimmer.coffee @@ -2,9 +2,9 @@ CocoClass = require 'lib/CocoClass' module.exports = class Dimmer extends CocoClass subscriptions: - 'level-disable-controls': 'onDisableControls' - 'level-enable-controls': 'onEnableControls' - 'level-highlight-sprites': 'onHighlightSprites' + 'level:disable-controls': 'onDisableControls' + 'level:enable-controls': 'onEnableControls' + 'sprite:highlight-sprites': 'onHighlightSprites' 'sprite:speech-updated': 'onSpriteSpeechUpdated' 'surface:frame-changed': 'onFrameChanged' 'camera:zoom-updated': 'onZoomUpdated' diff --git a/app/lib/surface/IndieSprite.coffee b/app/lib/surface/IndieSprite.coffee index a914a96fb..833b360e2 100644 --- a/app/lib/surface/IndieSprite.coffee +++ b/app/lib/surface/IndieSprite.coffee @@ -4,8 +4,8 @@ CocoSprite = require 'lib/surface/CocoSprite' module.exports = IndieSprite = class IndieSprite extends CocoSprite notOfThisWorld: true subscriptions: - 'note-group-started': 'onNoteGroupStarted' - 'note-group-ended': 'onNoteGroupEnded' + 'script:note-group-started': 'onNoteGroupStarted' + 'script:note-group-ended': 'onNoteGroupEnded' constructor: (thangType, options) -> options.thang = @makeIndieThang thangType, options diff --git a/app/lib/surface/Letterbox.coffee b/app/lib/surface/Letterbox.coffee index 1e829d3df..a29815e48 100644 --- a/app/lib/surface/Letterbox.coffee +++ b/app/lib/surface/Letterbox.coffee @@ -1,6 +1,6 @@ module.exports = class Letterbox extends createjs.Container subscriptions: - 'level-set-letterbox': 'onSetLetterbox' + 'level:set-letterbox': 'onSetLetterbox' constructor: (options) -> super() diff --git a/app/lib/surface/Mark.coffee b/app/lib/surface/Mark.coffee index bce9d84be..b730cabd8 100644 --- a/app/lib/surface/Mark.coffee +++ b/app/lib/surface/Mark.coffee @@ -216,7 +216,7 @@ module.exports = class Mark extends CocoClass onLoadedThangType: -> @build() @toggle(@toggleTo) if @toggleTo? - Backbone.Mediator.publish 'sprite:loaded' + Backbone.Mediator.publish 'sprite:loaded', {sprite: @} update: (pos=null) -> return false unless @on and @mark diff --git a/app/lib/surface/MusicPlayer.coffee b/app/lib/surface/MusicPlayer.coffee index e01f32372..4d3e8b47d 100644 --- a/app/lib/surface/MusicPlayer.coffee +++ b/app/lib/surface/MusicPlayer.coffee @@ -9,7 +9,7 @@ module.exports = class MusicPlayer extends CocoClass standingBy: null subscriptions: - 'level-play-music': 'onPlayMusic' + 'music-player:play-music': 'onPlayMusic' 'audio-player:loaded': 'onAudioLoaded' constructor: -> diff --git a/app/lib/surface/PointChooser.coffee b/app/lib/surface/PointChooser.coffee index 88c61db98..16bacd5c6 100644 --- a/app/lib/surface/PointChooser.coffee +++ b/app/lib/surface/PointChooser.coffee @@ -24,10 +24,9 @@ module.exports = class PointChooser extends CocoClass @shape.layerIndex = 100 onMouseDown: (e) => - console.log 'got stagemousedown', e, key.shift return unless key.shift @setPoint @options.camera.screenToWorld {x: e.stageX, y: e.stageY} - Backbone.Mediator.publish 'choose-point', point: @point + Backbone.Mediator.publish 'surface:choose-point', point: @point updateShape: -> sup = @options.camera.worldToSurface @point diff --git a/app/lib/surface/RegionChooser.coffee b/app/lib/surface/RegionChooser.coffee index 3b15ec4f7..c5147b25c 100644 --- a/app/lib/surface/RegionChooser.coffee +++ b/app/lib/surface/RegionChooser.coffee @@ -27,7 +27,7 @@ module.exports = class RegionChooser extends CocoClass onMouseUp: (e) => return unless @firstPoint - Backbone.Mediator.publish 'choose-region', points: [@firstPoint, @secondPoint] + Backbone.Mediator.publish 'surface:choose-region', points: [@firstPoint, @secondPoint] @firstPoint = null @secondPoint = null @options.camera.dragDisabled = false diff --git a/app/lib/surface/SpriteBoss.coffee b/app/lib/surface/SpriteBoss.coffee index c7e22b56c..1a912b555 100644 --- a/app/lib/surface/SpriteBoss.coffee +++ b/app/lib/surface/SpriteBoss.coffee @@ -12,12 +12,12 @@ module.exports = class SpriteBoss extends CocoClass subscriptions: 'bus:player-joined': 'onPlayerJoined' 'bus:player-left': 'onPlayerLeft' - 'level-set-debug': 'onSetDebug' - 'level-highlight-sprites': 'onHighlightSprites' + 'level:set-debug': 'onSetDebug' + 'sprite:highlight-sprites': 'onHighlightSprites' 'surface:stage-mouse-down': 'onStageMouseDown' - 'level-select-sprite': 'onSelectSprite' - 'level-suppress-selection-sounds': 'onSuppressSelectionSounds' - 'level-lock-select': 'onSetLockSelect' + 'level:select-sprite': 'onSelectSprite' + 'level:suppress-selection-sounds': 'onSuppressSelectionSounds' + 'level:lock-select': 'onSetLockSelect' 'level:restarted': 'onLevelRestarted' 'god:new-world-created': 'onNewWorld' 'god:streaming-world-updated': 'onNewWorld' @@ -198,7 +198,7 @@ module.exports = class SpriteBoss extends CocoClass sprite.setThang thang # make sure Sprite has latest Thang else sprite = @addThangToSprites(thang) - Backbone.Mediator.publish 'surface:new-thang-added', thang:thang, sprite:sprite + Backbone.Mediator.publish 'surface:new-thang-added', thang: thang, sprite: sprite updateCache = updateCache or sprite.imageObject.parent is @spriteLayers['Obstacle'] sprite.playSounds() item.modifyStats() for item in itemsJustEquipped @@ -319,9 +319,9 @@ module.exports = class SpriteBoss extends CocoClass if alive and not @suppressSelectionSounds instance = sprite.playSound 'selected' if instance?.playState is 'playSucceeded' - Backbone.Mediator.publish 'thang-began-talking', thang: sprite?.thang + Backbone.Mediator.publish 'sprite:thang-began-talking', thang: sprite?.thang instance.addEventListener 'complete', -> - Backbone.Mediator.publish 'thang-finished-talking', thang: sprite?.thang + Backbone.Mediator.publish 'sprite:thang-finished-talking', thang: sprite?.thang onFlagColorSelected: (e) -> @removeSprite @flagCursorSprite if @flagCursorSprite diff --git a/app/lib/surface/Surface.coffee b/app/lib/surface/Surface.coffee index 9ba6ab0b6..73fef4d89 100644 --- a/app/lib/surface/Surface.coffee +++ b/app/lib/surface/Surface.coffee @@ -52,19 +52,19 @@ module.exports = Surface = class Surface extends CocoClass frameRate: 30 # Best as a divisor of 60, like 15, 30, 60, with RAF_SYNCHED timing. subscriptions: - 'level-disable-controls': 'onDisableControls' - 'level-enable-controls': 'onEnableControls' - 'level-set-playing': 'onSetPlaying' - 'level-set-debug': 'onSetDebug' - 'level-toggle-debug': 'onToggleDebug' - 'level-toggle-pathfinding': 'onTogglePathFinding' - 'level-set-time': 'onSetTime' - 'level-set-surface-camera': 'onSetCamera' + 'level:disable-controls': 'onDisableControls' + 'level:enable-controls': 'onEnableControls' + 'level:set-playing': 'onSetPlaying' + 'level:set-debug': 'onSetDebug' + 'level:toggle-debug': 'onToggleDebug' + 'level:toggle-pathfinding': 'onTogglePathFinding' + 'level:set-time': 'onSetTime' + 'camera:set-camera': 'onSetCamera' 'level:restarted': 'onLevelRestarted' 'god:new-world-created': 'onNewWorld' 'god:streaming-world-updated': 'onNewWorld' 'tome:cast-spells': 'onCastSpells' - 'level-set-letterbox': 'onSetLetterbox' + 'level:set-letterbox': 'onSetLetterbox' 'application:idle-changed': 'onIdleChanged' 'camera:zoom-updated': 'onZoomUpdated' 'playback:real-time-playback-started': 'onRealTimePlaybackStarted' @@ -127,7 +127,7 @@ module.exports = Surface = class Surface extends CocoClass @showLevel() @updateState true if @loaded @onFrameChanged() - Backbone.Mediator.publish 'surface:world-set-up' + Backbone.Mediator.publish 'surface:world-set-up', {world: @world} onTogglePathFinding: (e) -> e?.preventDefault?() @@ -311,7 +311,6 @@ module.exports = Surface = class Surface extends CocoClass return if @currentFrame is @lastFrame and not force progress = @getProgress() Backbone.Mediator.publish('surface:frame-changed', - type: 'frame-changed' selectedThang: @spriteBoss.selectedSprite?.thang progress: progress frame: @currentFrame @@ -321,11 +320,11 @@ module.exports = Surface = class Surface extends CocoClass if @lastFrame < @world.frames.length and @currentFrame >= @world.totalFrames - 1 @ended = true @setPaused true - Backbone.Mediator.publish 'surface:playback-ended' + Backbone.Mediator.publish 'surface:playback-ended', {} else if @currentFrame < @world.totalFrames and @ended @ended = false @setPaused false - Backbone.Mediator.publish 'surface:playback-restarted' + Backbone.Mediator.publish 'surface:playback-restarted', {} @lastFrame = @currentFrame @@ -368,7 +367,7 @@ module.exports = Surface = class Surface extends CocoClass # This has a tendency to break scripts that are waiting for playback to change when the level is loaded # so only run it after the first world is created. - Backbone.Mediator.publish 'level-set-playing', {playing: true} unless event.firstWorld or @setPlayingCalled + Backbone.Mediator.publish 'level:set-playing', {playing: true} unless event.firstWorld or @setPlayingCalled @setWorld event.world @onFrameChanged(true) @@ -450,11 +449,10 @@ module.exports = Surface = class Surface extends CocoClass @loaded = true @spriteBoss.createMarks() @spriteBoss.createIndieSprites @world.indieSprites, @options.wizards - Backbone.Mediator.publish 'registrar-echo-states' @updateState true @drawCurrentFrame() createjs.Ticker.addEventListener 'tick', @tick - Backbone.Mediator.publish 'level:started' + Backbone.Mediator.publish 'level:started', {} createOpponentWizard: (opponent) -> @spriteBoss.createOpponentWizard opponent @@ -464,7 +462,7 @@ module.exports = Surface = class Surface extends CocoClass onToggleDebug: (e) -> e?.preventDefault?() - Backbone.Mediator.publish 'level-set-debug', {debug: not @debug} + Backbone.Mediator.publish 'level:set-debug', {debug: not @debug} onSetDebug: (e) -> return if e.debug is @debug @@ -488,6 +486,7 @@ module.exports = Surface = class Surface extends CocoClass onMouseUp: (e) => return if @disabled + console.log 'yo on mouse up', e onBackground = not @stage.hitTest e.stageX, e.stageY Backbone.Mediator.publish 'surface:stage-mouse-up', onBackground: onBackground, x: e.stageX, y: e.stageY, originalEvent: e diff --git a/app/lib/surface/WizardSprite.coffee b/app/lib/surface/WizardSprite.coffee index e0cb356f1..c577dae28 100644 --- a/app/lib/surface/WizardSprite.coffee +++ b/app/lib/surface/WizardSprite.coffee @@ -16,10 +16,9 @@ module.exports = class WizardSprite extends IndieSprite subscriptions: 'bus:player-states-changed': 'onPlayerStatesChanged' - 'me:synced': 'onMeSynced' + 'auth:me-synced': 'onMeSynced' 'surface:sprite-selected': 'onSpriteSelected' - 'echo-self-wizard-sprite': 'onEchoSelfWizardSprite' - 'echo-all-wizard-sprites': 'onEchoAllWizardSprites' + 'sprite:echo-all-wizard-sprites': 'onEchoAllWizardSprites' shortcuts: 'up': 'onMoveKey' @@ -36,6 +35,7 @@ module.exports = class WizardSprite extends IndieSprite @setNameLabel me.displayName() else if options.name @setNameLabel options.name + Backbone.Mediator.publish 'self-wizard:created', sprite: @ makeIndieThang: (thangType, options) -> thang = super thangType, options @@ -112,7 +112,6 @@ module.exports = class WizardSprite extends IndieSprite @targetPos = @getPosFromTarget(@targetSprite or targetPos) @endMoveTween() - onEchoSelfWizardSprite: (e) -> e.payload = @ if @isSelf onEchoAllWizardSprites: (e) -> e.payload.push @ defaultPos: -> x: 35, y: 24, z: @thang.depth / 2 + @thang.bobHeight move: (pos, duration) -> @setTarget(pos, duration) @@ -132,7 +131,7 @@ module.exports = class WizardSprite extends IndieSprite @targetPos = @boundWizard targetPos @beginMoveTween(duration, isLinear) @shoveOtherWizards() - Backbone.Mediator.publish('self-wizard:target-changed', {sender: @}) if @isSelf + Backbone.Mediator.publish('self-wizard:target-changed', {sprite: @}) if @isSelf boundWizard: (target) -> # Passed an {x, y} in world coordinates, returns {x, y} within world bounds @@ -179,7 +178,7 @@ module.exports = class WizardSprite extends IndieSprite shoveOtherWizards: (removeMe) -> return unless @targetSprite allWizards = [] - Backbone.Mediator.publish('echo-all-wizard-sprites', {payload: allWizards}) + Backbone.Mediator.publish 'sprite:echo-all-wizard-sprites', payload: allWizards allOfUs = (wizard for wizard in allWizards when wizard.targetSprite is @targetSprite) allOfUs = (wizard for wizard in allOfUs when wizard isnt @) if removeMe @@ -271,4 +270,4 @@ module.exports = class WizardSprite extends IndieSprite position = {x: @targetPos.x + x, y: @targetPos.y + y} @setTarget(position, interval, true) @updatePosition() - Backbone.Mediator.publish 'camera-zoom-to', position, interval + Backbone.Mediator.publish 'camera:zoom-to', pos: position, duration: interval diff --git a/app/models/CocoModel.coffee b/app/models/CocoModel.coffee index 759505283..952d807e6 100644 --- a/app/models/CocoModel.coffee +++ b/app/models/CocoModel.coffee @@ -312,7 +312,7 @@ class CocoModel extends Backbone.Model achievements = new NewAchievementCollection achievements.fetch success: (collection) -> - me.fetch (success: -> Backbone.Mediator.publish('achievements:new', collection)) unless _.isEmpty(collection.models) + me.fetch (success: -> Backbone.Mediator.publish('achievements:new', earnedAchievements: collection)) unless _.isEmpty(collection.models) error: -> console.error 'Miserably failed to fetch unnotified achievements', arguments diff --git a/app/schemas/models/level.coffee b/app/schemas/models/level.coffee index 2fa229ee1..7a8fd713c 100644 --- a/app/schemas/models/level.coffee +++ b/app/schemas/models/level.coffee @@ -65,7 +65,7 @@ GoalSchema = c.object {title: 'Goal', description: 'A goal that the player can a ResponseSchema = c.object {title: 'Dialogue Button', description: 'A button to be shown to the user with the dialogue.', required: ['text']}, text: {title: 'Title', description: 'The text that will be on the button', 'default': 'Okay', type: 'string', maxLength: 30} - channel: c.shortString(title: 'Channel', format: 'event-channel', description: 'Channel that this event will be broadcast over, like "level-set-playing".') + channel: c.shortString(title: 'Channel', format: 'event-channel', description: 'Channel that this event will be broadcast over, like "level:set-playing".') event: {type: 'object', title: 'Event', description: 'Event that will be broadcast when this button is pressed, like {playing: true}.'} buttonClass: c.shortString(title: 'Button Class', description: 'CSS class that will be added to the button, like "btn-primary".') i18n: {type: 'object', format: 'i18n', props: ['text'], description: 'Help translate this button'} diff --git a/app/schemas/subscriptions/app.coffee b/app/schemas/subscriptions/app.coffee deleted file mode 100644 index f107935c4..000000000 --- a/app/schemas/subscriptions/app.coffee +++ /dev/null @@ -1,45 +0,0 @@ -module.exports = - 'application: idle-changed': - {} # TODO schema - - 'fbapi-loaded': - {} # TODO schema - - 'logging-in-with-facebook': - {} # TODO schema - - 'facebook-logged-in': - title: 'Facebook logged in' - $schema: 'http://json-schema.org/draft-04/schema#' - description: 'Published when you successfully logged in with facebook' - type: 'object' - properties: - response: - type: 'object' - properties: - status: {type: 'string'} - authResponse: - type: 'object' - properties: - accessToken: {type: 'string'} - expiresIn: {type: 'number'} - signedRequest: {type: 'string'} - userID: {type: 'string'} - required: ['response'] - - 'facebook-logged-out': {} - - 'linkedin-loaded': {} - - 'gapi-loaded': - {} # TODO schema - - 'logging-in-with-gplus': - {} # TODO schema - - 'gplus-logged-in': - title: 'G+ logged in' - $schema: 'http://json-schema.org/draft-04/schema#' - description: 'Published when you successfully logged in with G+' - type: 'object' - required: ['access_token'] diff --git a/app/schemas/subscriptions/auth.coffee b/app/schemas/subscriptions/auth.coffee new file mode 100644 index 000000000..2c19aac0c --- /dev/null +++ b/app/schemas/subscriptions/auth.coffee @@ -0,0 +1,39 @@ +c = require 'schemas/schemas' + +module.exports = + 'auth:me-synced': c.object {required: ['me']}, + me: {type: 'object'} + + 'auth:facebook-api-loaded': c.object {} + + 'auth:logging-in-with-facebook': c.object {} + + 'auth:logged-in-with-facebook': c.object {title: 'Facebook logged in', description: 'Published when you successfully logged in with Facebook', required: ['response']}, + response: + type: 'object' + properties: + status: {type: 'string'} + authResponse: + type: 'object' + properties: + accessToken: {type: 'string'} + expiresIn: {type: 'number'} + signedRequest: {type: 'string'} + userID: {type: 'string'} + + 'auth:linkedin-api-loaded': c.object {} + + 'auth:gplus-api-loaded': c.object {} + + 'auth:logging-in-with-gplus': c.object {} + + 'auth:logged-in-with-gplus': + title: 'G+ logged in' + description: 'Published when you successfully logged in with G+' + type: 'object' + required: ['access_token'] + properties: + access_token: {type: 'string'} + # Could be some other stuff + + 'auth:log-in-with-github': c.object {} diff --git a/app/schemas/subscriptions/bus.coffee b/app/schemas/subscriptions/bus.coffee index 72bdd6b07..f56c18170 100644 --- a/app/schemas/subscriptions/bus.coffee +++ b/app/schemas/subscriptions/bus.coffee @@ -1,71 +1,27 @@ +c = require 'schemas/schemas' + 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:connecting': c.object {title: 'Bus Connecting', description: 'Published when a Bus starts connecting'}, + bus: {$ref: 'bus'} - 'bus:connected': - title: 'Bus Connected' - $schema: 'http://json-schema.org/draft-04/schema#' - description: 'Published when a Bus has connected' - type: 'object' - properties: - bus: - $ref: 'bus' + 'bus:connected': c.object {title: 'Bus Connected', description: 'Published when a Bus has connected'}, + bus: {$ref: 'bus'} - 'bus:disconnected': - title: 'Bus Disconnected' - $schema: 'http://json-schema.org/draft-04/schema#' - description: 'Published when a Bus has disconnected' - type: 'object' - properties: - bus: - $ref: 'bus' + 'bus:disconnected': c.object {title: 'Bus Disconnected', description: 'Published when a Bus has disconnected'}, + bus: {$ref: 'bus'} - 'bus:new-message': - title: 'Message sent' - $schema: 'http://json-schema.org/draft-04/schema#' - description: 'A new message was sent' - type: 'object' - properties: - message: - type: 'object' - bus: - $ref: 'bus' + 'bus:new-message': c.object {title: 'Message sent', description: 'A new message was sent'}, + message: {type: 'object'} + bus: {$ref: 'bus'} - 'bus:player-joined': - title: 'Player joined' - $schema: 'http://json-schema.org/draft-04/schema#' - description: 'A new player has joined' - type: 'object' - properties: - player: - type: 'object' - bus: - $ref: 'bus' + 'bus:player-joined': c.object {title: 'Player joined', description: 'A new player has joined'}, + player: {type: 'object'} + bus: {$ref: 'bus'} - 'bus:player-left': - title: 'Player left' - $schema: 'http://json-schema.org/draft-04/schema#' - description: 'A player has left' - type: 'object' - properties: - player: - type: 'object' - bus: - $ref: 'bus' + 'bus:player-left': c.object {title: 'Player left', description: 'A player has left'}, + player: {type: 'object'} + bus: {$ref: 'bus'} - 'bus:player-states-changed': - title: 'Player state changes' - $schema: 'http://json-schema.org/draft-04/schema#' - description: 'State of the players has changed' - type: 'object' - properties: - player: - type: 'array' - bus: - $ref: 'bus' + 'bus:player-states-changed': c.object {title: 'Player state changes', description: 'State of the players has changed'}, + states: c.array {}, {type: 'object'} + bus: {$ref: 'bus'} diff --git a/app/schemas/subscriptions/editor.coffee b/app/schemas/subscriptions/editor.coffee index b75649c9e..04ee81e13 100644 --- a/app/schemas/subscriptions/editor.coffee +++ b/app/schemas/subscriptions/editor.coffee @@ -1,78 +1,43 @@ +c = require 'schemas/schemas' + 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 + 'editor:save-new-version': c.object {title: 'Save New Version', description: 'Published when a version gets saved', required: ['major', 'commitMessage']}, + major: {type: 'boolean'} + commitMessage: {type: 'string'} - # TODO all these events starting with 'level:' should have 'editor' in their name - # to avoid confusion with level play events + 'editor:view-switched': c.object {title: 'Level View Switched', description: 'Published whenever the view switches'} - 'level:view-switched': - title: 'Level View Switched' - $schema: 'http://json-schema.org/draft-04/schema#' - description: 'Published whenever the view switches' - $ref: 'jQueryEvent' + 'editor:level-component-editing-ended': c.object {required: ['component']}, + component: {type: 'object'} - 'level-components-changed': - {} # TODO schema + 'editor:edit-level-system': c.object {required: ['original', 'majorVersion']}, + original: {type: 'string'} + majorVersion: {type: 'integer', minimum: 0} - 'edit-level-component': - {} # TODO schema + 'editor:level-system-added': c.object {required: ['system']}, + system: {type: 'object'} - 'level-component-edited': - {} # TODO schema + 'editor:level-system-editing-ended': c.object {required: ['system']}, + system: {type: 'object'} - 'level-component-editing-ended': - {} # TODO schema + 'editor:edit-level-thang': c.object {required: ['thangID']}, + thangID: {type: 'string'} - 'level-systems-changed': - {} # TODO schema + 'editor:level-thang-edited': c.object {required: ['thangID', 'thangData']}, + thangID: {type: 'string'} + thangData: {type: 'object'} - 'edit-level-system': - {} # TODO schema + 'editor:level-thang-done-editing': c.object {} - 'level-system-added': - {} # TODO schema + 'editor:level-loaded': c.object {required: ['level']}, + level: {type: 'object'} - 'level-system-edited': - {} # TODO schema + 'level:reload-from-data': c.object {required: ['level', 'supermodel']}, + level: {type: 'object'} + supermodel: {type: 'object'} - 'level-system-editing-ended': - {} # TODO schema + 'level:reload-thang-type': c.object {required: ['thangType']}, + thangType: {type: 'object'} - '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 + 'editor:random-terrain-generated': c.object {required: ['thangs']}, + thangs: c.array {}, {type: 'object'} diff --git a/app/schemas/subscriptions/errors.coffee b/app/schemas/subscriptions/errors.coffee index 598dfc6d9..c50c4fe20 100644 --- a/app/schemas/subscriptions/errors.coffee +++ b/app/schemas/subscriptions/errors.coffee @@ -1,4 +1,6 @@ +c = require 'schemas/schemas' + module.exports = # app/lib/errors - 'server-error': - {} # TODO schema + 'errors:server-error': c.object {required: ['response']}, + response: {type: 'object'} diff --git a/app/schemas/subscriptions/god.coffee b/app/schemas/subscriptions/god.coffee new file mode 100644 index 000000000..5a8f0f09f --- /dev/null +++ b/app/schemas/subscriptions/god.coffee @@ -0,0 +1,53 @@ +c = require 'schemas/schemas' + +goalStatesSchema = + type: 'object' + additionalProperties: + type: 'object' + required: ['status'] + properties: + status: + oneOf: [ + {type: 'null'} + {type: 'string', enum: ['success', 'failure', 'incomplete']} + ] + keyFrame: + oneOf: [ + {type: 'integer', minimum: 0} + {type: 'string', enum: ['end']} + ] + team: {type: ['null', 'string']} + +worldUpdatedEventSchema = c.object {required: ['world', 'firstWorld', 'goalStates', 'team', 'firstChangedFrame']}, + world: {type: 'object'} + firstWorld: {type: 'boolean'} + goalStates: goalStatesSchema + team: {type: 'string'} + firstChangedFrame: {type: 'integer', minimum: 0} + +module.exports = + 'god:user-code-problem': c.object {required: ['problem']}, + problem: {type: 'object'} + + 'god:non-user-code-problem': c.object {required: ['problem']}, + problem: {type: 'object'} + + 'god:infinite-loop': c.object {required: ['firstWorld']}, + firstWorld: {type: 'boolean'} + + 'god:new-world-created': worldUpdatedEventSchema + + 'god:streaming-world-updated': worldUpdatedEventSchema + + 'god:goals-calculated': c.object {required: ['goalStates']}, + goalStates: goalStatesSchema + + 'god:world-load-progress-changed': c.object {required: ['progress']}, + progress: {type: 'number', minimum: 0, maximum: 1} + + 'god:debug-world-load-progress-changed': c.object {required: ['progress']}, + progress: {type: 'number', minimum: 0, maximum: 1} + + 'god:debug-value-return': c.object {required: ['key']}, + key: {type: 'string'} + value: {type: 'any'} diff --git a/app/schemas/subscriptions/misc.coffee b/app/schemas/subscriptions/misc.coffee index 439464851..bb41e1e7a 100644 --- a/app/schemas/subscriptions/misc.coffee +++ b/app/schemas/subscriptions/misc.coffee @@ -1,23 +1,29 @@ +c = require 'schemas/schemas' + module.exports = - 'audio-played:loaded': - {} # TODO schema + 'application:idle-changed': c.object {}, + idle: {type: 'boolean'} - # TODO location is debatable - 'note-group-started': - {} # TODO schema + 'audio-player:loaded': c.object {required: ['sender']}, + sender: {type: 'object'} - 'note-group-ended': - {} # TODO schema + 'audio-player:play-sound': c.object {required: ['trigger']}, + trigger: {type: 'string'} + volume: {type: 'number', minimum: 0, maximum: 1} - 'modal-opened': - {} # TODO schema + 'music-player:play-music': c.object {required: ['play']}, + play: {type: 'boolean'} + file: {type: 'string'} - 'modal-closed': - {} # TODO schema + 'modal:opened': c.object {} - # TODO I propose prepending 'modal:' - 'save-new-version': - {} # TODO schema + 'modal:closed': c.object {} - 'router:navigate': - {} # TODO schema + 'router:navigate': c.object {required: ['route']}, + route: {type: 'string'} + view: {type: 'object'} + viewClass: {type: 'object'} + viewArgs: {type: 'array'} + + 'achievements:new': c.object {required: 'earnedAchievements'}, + earnedAchievements: {type: 'object'} diff --git a/app/schemas/subscriptions/play.coffee b/app/schemas/subscriptions/play.coffee index ee52d5fd3..3575cc1fc 100644 --- a/app/schemas/subscriptions/play.coffee +++ b/app/schemas/subscriptions/play.coffee @@ -1,203 +1,153 @@ +c = require 'schemas/schemas' + 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': c.object {required: ['session']}, + session: {type: 'object'} - 'level:session-will-save': - {} # TODO schema + 'level:shift-space-pressed': c.object {} - 'level-loader:progress-changed': - {} # TODO schema + 'level:escape-pressed': c.object {} - 'level:shift-space-pressed': - {} # TODO schema + 'level:enable-controls': c.object {}, + controls: c.array {}, + c.shortString() - 'level:escape-pressed': - {} # TODO schema + 'level:disable-controls': c.object {}, + controls: c.array {}, + c.shortString() - 'level-enable-controls': - {} # TODO schema - 'level-set-letterbox': - {} # TODO schema + 'level:set-letterbox': c.object {}, + on: {type: 'boolean'} - 'level:started': - {} # TODO schema + 'level:started': c.object {} - 'level-set-debug': - {} # TODO schema + 'level:set-debug': c.object {required: ['debug']}, + debug: {type: 'boolean'} - 'level:restarted': - {} # TODO schema + 'level:restart': c.object {} - 'level-set-volume': - {} # TODO schema + 'level:restarted': c.object {} - 'level-set-time': - {} # TODO schema + 'level:set-volume': c.object {required: ['volume']}, + volume: {type: 'number', minimum: 0, maximum: 1} - 'level-select-sprite': - {} # TODO schema + 'level:set-time': c.object {}, + time: {type: 'number', minimum: 0} + ratio: {type: 'number', minimum: 0, maximum: 1} + frameOffset: {type: 'integer'} + scrubDuration: {type: 'integer', minimum: 0} - 'level-set-playing': - {} # TODO schema + 'level:select-sprite': c.object {}, + thangID: {type: ['string', 'null', 'undefined']} + spellName: {type: ['string', 'null', 'undefined']} - 'level:team-set': - {} # TODO schema + 'level:set-playing': c.object {required: ['playing']}, + playing: {type: 'boolean'} - 'level:docs-shown': {} + 'level:team-set': c.object {required: ['team']}, + team: c.shortString() - 'level:docs-hidden': {} + 'level:docs-shown': c.object {} - 'level:victory-hidden': - {} # TODO schema + 'level:docs-hidden': c.object {} - 'level:flag-color-selected': - type: 'object' - additionalProperties: false - properties: - color: - oneOf: [ - {type: 'null'} - {type: 'string', enum: ['green', 'black', 'violet'], description: 'The flag color to place next, or omitted/null if deselected.'} - ] - pos: + 'level:flag-color-selected': c.object {}, + color: + oneOf: [ + {type: 'null'} + {type: 'string', enum: ['green', 'black', 'violet'], description: 'The flag color to place next, or omitted/null if deselected.'} + ] + pos: c.object {required: ['x', 'y']}, + x: {type: 'number'} + y: {type: 'number'} + + 'level:flag-updated': c.object {required: ['player', 'color', 'time', 'active']}, + player: {type: 'string'} + team: {type: 'string'} + color: {type: 'string', enum: ['green', 'black', 'violet']} + time: {type: 'number', minimum: 0} + active: {type: 'boolean'} + pos: c.object {required: ['x', 'y']}, + x: {type: 'number'} + y: {type: 'number'} + + 'level:next-game-pressed': c.object {} + + 'level:loading-view-unveiled': c.object {required: ['view']}, + view: {type: 'object'} + + 'playback:manually-scrubbed': c.object {required: ['ratio']}, + ratio: {type: 'number', minimum: 0, maximum: 1} + + 'playback:stop-real-time-playback': c.object {} + + 'playback:real-time-playback-started': c.object {} + + 'playback:real-time-playback-ended': c.object {} + + 'level:play-next-level': c.object {} + + 'level:toggle-playing': c.object {} + + 'level:toggle-grid': c.object {} + + 'level:toggle-debug': c.object {} + + 'level:toggle-pathfinding': c.object {} + + 'level:scrub-forward': c.object {} + + 'level:scrub-back': c.object {} + + 'level:show-victory': c.object {required: ['showModal']}, + showModal: {type: 'boolean'} + + 'level:highlight-dom': c.object {required: ['selector']}, + selector: {type: 'string'} + delay: {type: 'number'} + sides: {type: 'array', items: {'enum': ['left', 'right', 'top', 'bottom']}} + offset: {type: 'object'} + rotation: {type: 'number'} + + 'level:end-highlight-dom': c.object {} + + 'level:focus-dom': c.object {}, + selector: {type: 'string'} + + 'level:lock-select': c.object {}, + lock: {type: ['boolean', 'array']} + + 'level:suppress-selection-sounds': c.object {required: ['suppress']}, + suppress: {type: 'boolean'} + + 'goal-manager:new-goal-states': c.object {required: ['goalStates', 'goals', 'overallStatus', 'timedOut']}, + goalStates: + type: 'object' + additionalProperties: type: 'object' - additionalProperties: false - required: ['x', 'y'] + required: ['status'] properties: - x: {type: 'number'} - y: {type: 'number'} + status: + oneOf: [ + {type: 'null'} + {type: 'string', enum: ['success', 'failure', 'incomplete']} + ] + keyFrame: + oneOf: [ + {type: 'integer', minimum: 0} + {type: 'string', enum: ['end']} + ] + team: {type: ['null', 'string']} + goals: c.array {}, + {type: 'object'} + overallStatus: + oneOf: [ + {type: 'null'} + {type: 'string', enum: ['success', 'failure', 'incomplete']} + ] + timedOut: {type: 'boolean'} - 'level:flag-updated': - type: 'object' - additionalProperties: false - required: ['player', 'color', 'time', 'active'] - properties: - player: - type: 'string' - team: - type: 'string' - color: - type: 'string' - enum: ['green', 'black', 'violet'] - time: - type: 'number' - minimum: 0 - active: - type: 'boolean' - pos: - type: 'object' - additionalProperties: false - required: ['x', 'y'] - properties: - x: {type: 'number'} - y: {type: 'number'} - - 'next-game-pressed': - {} # TODO schema - - 'end-current-script': - {} # TODO schema - - 'script:reset': - {} # TODO schema - - 'script:ended': - {} # TODO schema - - 'end-all-scripts': {} - - 'script:state-changed': - {} # TODO schema - - 'script-manager:tick': - type: 'object' - additionalProperties: false - properties: - scriptRunning: {type: 'string'} - noteGroupRunning: {type: 'string'} - timeSinceLastScriptEnded: {type: 'number'} - scriptStates: - type: 'object' - additionalProperties: - title: 'Script State' - type: 'object' - additionalProperties: false - properties: - timeSinceLastEnded: - type: 'number' - description: 'seconds since this script ended last' - timeSinceLastTriggered: - type: 'number' - description: 'seconds since this script was triggered last' - - 'play-sound': - {} # TODO schema - - # TODO refactor name - 'onLoadingViewUnveiled': - {} # TODO schema - - 'playback:manually-scrubbed': - {} # TODO schema - - 'playback:stop-real-time-playback': - type: 'object' - additionalProperties: false - - 'playback:real-time-playback-started': - type: 'object' - additionalProperties: false - - 'playback:real-time-playback-ended': - type: 'object' - additionalProperties: false - - '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 - - 'level-show-victory': - type: 'object' - additionalProperties: false - properties: - showModal: {type: 'boolean'} - - 'level-highlight-dom': - type: 'object' - additionalProperties: false - properties: - selector: {type: 'string'} - delay: {type: 'number'} - sides: {type: 'array', items: {'enum': ['left', 'right', 'top', 'bottom']}} - offset: {type: 'object'} - rotation: {type: 'number'} - - 'goal-manager:new-goal-states': - {} # TODO schema + 'level:edit-wizard-settings': c.object {} diff --git a/app/schemas/subscriptions/scripts.coffee b/app/schemas/subscriptions/scripts.coffee new file mode 100644 index 000000000..75bfa3fbc --- /dev/null +++ b/app/schemas/subscriptions/scripts.coffee @@ -0,0 +1,27 @@ +c = require 'schemas/schemas' + +module.exports = + 'script:end-current-script': c.object {} + + 'script:reset': c.object {} + + 'script:ended': c.object {required: ['scriptID']}, + scriptID: {type: 'string'} + + 'script:state-changed': c.object {required: ['currentScript', 'currentScriptOffset']}, + currentScript: {type: ['string', 'null']} + currentScriptOffset: {type: 'integer', minimum: 0} + + 'script:tick': c.object {required: ['scriptRunning', 'noteGroupRunning', 'scriptStates', 'timeSinceLastScriptEnded']}, + scriptRunning: {type: 'string'} + noteGroupRunning: {type: 'string'} + timeSinceLastScriptEnded: {type: 'number'} + scriptStates: + type: 'object' + additionalProperties: c.object {title: 'Script State'}, + timeSinceLastEnded: {type: 'number', minimum: 0, description: 'seconds since this script ended last'} + timeSinceLastTriggered: {type: 'number', minimum: 0, description: 'seconds since this script was triggered last'} + + 'script:note-group-started': c.object {} + + 'script:note-group-ended': c.object {} diff --git a/app/schemas/subscriptions/surface.coffee b/app/schemas/subscriptions/surface.coffee index ee3b98458..22b59643a 100644 --- a/app/schemas/subscriptions/surface.coffee +++ b/app/schemas/subscriptions/surface.coffee @@ -1,108 +1,180 @@ +c = require 'schemas/schemas' + +spriteMouseEventSchema = c.object {required: ['sprite', 'thang', 'originalEvent', 'canvas']}, + sprite: {type: 'object'} + thang: {type: 'object'} + originalEvent: {type: 'object'} + canvas: {type: 'object'} + module.exports = # /app/lib/surface - 'camera-dragged': - {} # TODO schema + 'camera:dragged': c.object {} - 'camera-zoom-in': - {} # TODO schema + 'camera:zoom-in': c.object {} - 'camera-zoom-out': - {} # TODO schema + 'camera:zoom-out': c.object {} - 'camera-zoom-to': - {} # TODO schema + 'camera:zoom-to': c.object {required: ['pos']}, + pos: c.object {required: ['x', 'y']}, + x: {type: 'number'} + y: {type: 'number'} + duration: {type: 'number', minimum: 0} - 'camera:zoom-updated': - {} # TODO schema + 'camera:zoom-updated': c.object {required: ['camera', 'zoom', 'surfaceViewport']}, + camera: {type: 'object'} + zoom: {type: 'number', minimum: 0, exclusiveMinimum: true} + surfaceViewport: {type: 'object'} - 'sprite:speech-updated': - {} # TODO schema + 'camera:set-camera': c.object {}, + pos: c.object {required: ['x', 'y']}, + x: {type: 'number'} + y: {type: 'number'} + thangID: {type: 'string'} + zoom: {type: 'number'} + duration: {type: 'number', minimum: 0} + bounds: c.array {maxItems: 2, minItems: 2}, + c.object {required: ['x', 'y']}, + x: {type: 'number'} + y: {type: 'number'} - 'dialogue-sound-completed': - {} # TODO schema + 'sprite:speech-updated': c.object {required: ['sprite', 'thang']}, + sprite: {type: 'object'} + thang: {type: 'object'} + blurb: {type: 'string'} + message: {type: 'string'} + mood: {type: 'string'} + responses: {type: 'array'} + spriteID: {type: 'string'} + sound: {type: ['null', 'undefined', 'object']} - 'surface:gold-changed': - {} # TODO schema + 'level:sprite-dialogue': c.object {required: ['spriteID', 'message']}, + blurb: {type: 'string'} + message: {type: 'string'} + mood: {type: 'string'} + responses: {type: 'array'} + spriteID: {type: 'string'} + sound: {type: ['null', 'undefined', 'object']} - 'surface:coordinate-selected': - {} # TODO schema + 'sprite:dialogue-sound-completed': c.object {} - 'surface:coordinates-shown': - {} # TODO schema + 'level:sprite-clear-dialogue': c.object {} - 'level-sprite-clear-dialogue': - {} # TODO schema + 'surface:gold-changed': c.object {required: ['team', 'gold']}, + team: {type: 'string'} + gold: {type: 'number'} + goldEarned: {type: 'number'} - 'sprite:loaded': - {} # TODO schema + 'surface:coordinate-selected': c.object {required: ['x', 'y']}, + x: {type: 'number'} + y: {type: 'number'} - 'choose-point': - {} # TODO schema + 'surface:coordinates-shown': c.object {} - 'choose-region': - {} # TODO schema + 'sprite:loaded': c.object {}, + sprite: {type: 'object'} - 'surface:new-thang-added': - {} # TODO schema + 'surface:choose-point': c.object {required: ['point']}, + point: c.object {required: ['x', 'y']}, + x: {type: 'number'} + y: {type: 'number'} - 'surface:sprite-selected': - {} # TODO schema + 'surface:choose-region': c.object {required: ['points']}, + points: c.array {minItems: 2, maxItems: 2}, + c.object {required: ['x', 'y']}, + x: {type: 'number'} + y: {type: 'number'} - 'thang-began-talking': - {} # TODO schema + 'surface:new-thang-added': c.object {required: ['thang', 'sprite']}, + thang: {type: 'object'} + sprite: {type: 'object'} - 'thang-finished-talking': - {} # TODO schema + 'surface:sprite-selected': c.object {required: ['thang', 'sprite']}, + thang: {type: ['object', 'null', 'undefined']} + sprite: {type: ['object', 'null', 'undefined']} + spellName: {type: ['string', 'null', 'undefined']} + originalEvent: {type: ['object', 'null', 'undefined']} + worldPos: {type: ['object', 'null', 'undefined']} - 'surface:world-set-up': - {} # TODO schema + 'sprite:thang-began-talking': c.object {}, + thang: {type: 'object'} - 'surface:frame-changed': - {} # TODO schema + 'sprite:thang-finished-talking': c.object {}, + thang: {type: 'object'} - 'surface:playback-ended': - {} # TODO schema + 'sprite:highlight-sprites': c.object {}, + thangIDs: c.array {}, {type: 'string'} + delay: {type: 'number'} - 'surface:playback-restarted': - {} # TODO schema + 'sprite:move': c.object {required: ['spriteID', 'pos']}, + spriteID: {type: 'string'} + pos: c.object {required: ['x', 'y']}, + x: {type: 'number'} + y: {type: 'number'} + duration: {type: 'number', minimum: 0} - 'level-set-playing': - {} # TODO schema + 'sprite:mouse-down': spriteMouseEventSchema + 'sprite:clicked': spriteMouseEventSchema + 'sprite:double-clicked': spriteMouseEventSchema + 'sprite:dragged': spriteMouseEventSchema + 'sprite:mouse-up': spriteMouseEventSchema - 'registrar-echo-states': - {} # TODO schema + 'surface:world-set-up': c.object {}, + world: {type: 'object'} - 'surface:mouse-moved': - {} # TODO schema + 'surface:frame-changed': c.object {required: ['frame', 'world', 'progress']}, + frame: {type: 'number', minimum: 0} + world: {type: 'object'} + progress: {type: 'number', minimum: 0, maximum: 1} + selectedThang: {type: ['object', 'null', 'undefined']} - 'surface:stage-mouse-down': - {} # TODO schema + 'surface:playback-ended': c.object {} - 'surface:mouse-scrolled': - {} # TODO schema + 'surface:playback-restarted': c.object {} - 'surface:ticked': - {} # TODO schema + 'surface:mouse-moved': c.object {required: ['x', 'y']}, + x: {type: 'number'} + y: {type: 'number'} - 'surface:mouse-over': - {} # TODO schema + 'surface:stage-mouse-down': c.object {required: ['onBackground', 'x', 'y', 'originalEvent']}, + onBackground: {type: 'boolean'} + x: {type: 'number'} + y: {type: 'number'} + originalEvent: {type: 'object'} + worldPos: {type: ['object', 'null', 'undefined']} - 'surface:mouse-out': - {} # TODO schema + 'surface:stage-mouse-up': c.object {required: ['onBackground', 'x', 'y', 'originalEvent']}, + onBackground: {type: 'boolean'} + x: {type: 'number'} + y: {type: 'number'} + originalEvent: {type: 'object'} - 'self-wizard:target-changed': - {} # TODO schema + 'surface:mouse-scrolled': c.object {required: ['deltaX', 'deltaY', 'screenPos', 'canvas']}, + deltaX: {type: 'number'} + deltaY: {type: 'number'} + screenPos: c.object {required: ['x', 'y']}, + x: {type: 'number'} + y: {type: 'number'} + canvas: {type: 'object'} - 'echo-all-wizard-sprites': - {} # TODO schema + 'surface:ticked': c.object {required: ['dt']}, + dt: {type: 'number'} - 'surface:flag-appeared': - type: 'object' - additionalProperties: false - required: ['sprite'] - properties: - sprite: - type: 'object' + 'surface:mouse-over': c.object {} - 'surface:remove-selected-flag': - type: 'object' - additionalProperties: false + 'surface:mouse-out': c.object {} + + 'sprite:echo-all-wizard-sprites': c.object {required: ['payload']}, + payload: c.array {}, {type: 'object'} + + 'self-wizard:created': c.object {required: ['sprite']}, + sprite: {type: 'object'} + + 'self-wizard:target-changed': c.object {required: ['sprite']}, + sprite: {type: 'object'} + + 'surface:flag-appeared': c.object {required: ['sprite']}, + sprite: {type: 'object'} + + 'surface:remove-selected-flag': c.object {} + + 'surface:remove-flag': c.object {required: 'color'}, + color: {type: 'string'} diff --git a/app/schemas/subscriptions/tome.coffee b/app/schemas/subscriptions/tome.coffee index a582156e1..f79cb62b5 100644 --- a/app/schemas/subscriptions/tome.coffee +++ b/app/schemas/subscriptions/tome.coffee @@ -1,277 +1,109 @@ +c = require 'schemas/schemas' + module.exports = - "tome:cast-spell": - title: "Cast Spell" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published when a spell is cast" - type: ["object", "undefined"] - properties: - spell: - type: "object" - thang: - type: "object" - preload: - type: "boolean" - realTime: - type: "boolean" - required: [] - additionalProperties: false + 'tome:cast-spell': c.object {title: 'Cast Spell', description: 'Published when a spell is cast', required: ['spell', 'thang', 'preload', 'realTime']}, + spell: {type: 'object'} + thang: {type: 'object'} + preload: {type: 'boolean'} + realTime: {type: 'boolean'} - "tome:cast-spells": - title: "Cast Spells" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published when spells are cast" - type: ["object", "undefined"] - properties: - spells: - type: "object" - preload: - type: "boolean" - realTime: - type: "boolean" - required: [] - additionalProperties: false + 'tome:cast-spells': c.object {title: 'Cast Spells', description: 'Published when spells are cast', required: ['spells', 'preload', 'realTime']}, + spells: [type: 'object'] + preload: [type: 'boolean'] + realTime: [type: 'boolean'] - "tome:manual-cast": - title: "Manually Cast Spells" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published when you wish to manually recast all spells" - type: "object" - properties: - realTime: - type: "boolean" - required: [] - additionalProperties: false + 'tome:manual-cast': c.object {title: 'Manually Cast Spells', description: 'Published when you wish to manually recast all spells', required: []}, + realTime: {type: 'boolean'} - "tome:spell-created": - title: "Spell Created" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published after a new spell has been created" - type: "object" - properties: - "spell": "object" - required: ["spell"] - additionalProperties: false + 'tome:spell-created': c.object {title: 'Spell Created', description: 'Published after a new spell has been created', required: ['spell']}, + spell: {type: 'object'} - "tome:spell-debug-property-hovered": - title: "Spell Debug Property Hovered" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published when you hover over a spell property" - type: "object" - properties: - "property": "string" - "owner": "string" - required: [] - additionalProperties: false + 'tome:spell-has-changed-significantly-calculation': c.object {title: 'Has Changed Significantly Calculation', description: 'Let anyone know that the spell has changed significantly.', required: ['hasChangedSignificantly']}, + hasChangedSignificantly: {type: 'boolean'} - "tome:toggle-spell-list": - title: "Toggle Spell List" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published when you toggle the dropdown for a thang's spells" - type: "undefined" - additionalProperties: false + 'tome:spell-debug-property-hovered': c.object {title: 'Spell Debug Property Hovered', description: 'Published when you hover over a spell property', required: []}, + property: {type: 'string'} + owner: {type: 'string'} - "tome:reload-code": - title: "Reload Code" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published when you reset a spell to its original source" - type: "object" - properties: - "spell": "object" - required: ["spell"] - additionalProperties: false + 'tome:spell-debug-value-request': c.object {title: 'Spell Debug Value Request', description: 'Published when the SpellDebugView wants to retrieve a debug value.', required: ['thangID', 'spellID', 'variableChain', 'frame']}, + thangID: {type: 'string'} + spellID: {type: 'string'} + variableChain: c.array {}, {type: 'string'} + frame: {type: 'integer', minimum: 0} - "tome:palette-hovered": - title: "Palette Hovered" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published when you hover over a Thang in the spell palette" - type: "object" - properties: - "thang": "object" - "prop": "string" - "entry": "object" - required: ["thang", "prop", "entry"] - additionalProperties: false + 'tome:toggle-spell-list': c.object {title: 'Toggle Spell List', description: 'Published when you toggle the dropdown for a thang\'s spells'} - "tome:palette-pin-toggled": - title: "Palette Pin Toggled" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published when you pin or unpin the spell palette" - type: "object" - properties: - "entry": "object" - "pinned": "boolean" - required: ["entry", "pinned"] - additionalProperties: false + 'tome:reload-code': c.object {title: 'Reload Code', description: 'Published when you reset a spell to its original source', required: ['spell']}, + spell: {type: 'object'} - "tome:palette-clicked": - title: "Palette Clicked" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published when you click on the spell palette" - type: "object" - properties: - "thang": "object" - "prop": "string" - "entry": "object" - required: ["thang", "prop", "entry"] - additionalProperties: false + 'tome:palette-hovered': c.object {title: 'Palette Hovered', description: 'Published when you hover over a Thang in the spell palette', required: ['thang', 'prop', 'entry']}, + thang: {type: 'object'} + prop: {type: 'string'} + entry: {type: 'object'} - "tome:spell-statement-index-updated": - title: "Spell Statement Index Updated" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published when the spell index is updated" - type: "object" - properties: - "statementIndex": "object" - "ace": "object" - required: ["statementIndex", "ace"] - additionalProperties: false + 'tome:palette-pin-toggled': c.object {title: 'Palette Pin Toggled', description: 'Published when you pin or unpin the spell palette', required: ['entry', 'pinned']}, + entry: {type: 'object'} + pinned: {type: 'boolean'} - # TODO proposition: refactor 'tome' into spell events - "spell-beautify": - title: "Beautify" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published when you click the \"beautify\" button" - type: "object" - properties: - "spell": "object" - required: [] - additionalProperties: false + 'tome:palette-clicked': c.object {title: 'Palette Clicked', description: 'Published when you click on the spell palette', required: ['thang', 'prop', 'entry']}, + thang: {type: 'object'} + prop: {type: 'string'} + entry: {type: 'object'} - "spell-step-forward": - title: "Step Forward" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published when you step forward in time" - type: "undefined" - additionalProperties: false + 'tome:spell-statement-index-updated': c.object {title: 'Spell Statement Index Updated', description: 'Published when the spell index is updated', required: ['statementIndex', 'ace']}, + statementIndex: {type: 'object'} + ace: {type: 'object'} - "spell-step-backward": - title: "Step Backward" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published when you step backward in time" - type: "undefined" - additionalProperties: false + 'tome:spell-beautify': c.object {title: 'Beautify', description: 'Published when you click the \'beautify\' button', required: []}, + spell: {type: 'object'} - "tome:spell-loaded": - title: "Spell Loaded" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published when a spell is loaded" - type: "object" - properties: - "spell": "object" - required: ["spell"] - additionalProperties: false + 'tome:spell-step-forward': c.object {title: 'Step Forward', description: 'Published when you step forward in time'} - "tome:spell-changed": - title: "Spell Changed" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published when a spell is changed" - type: "object" - properties: - "spell": "object" - required: ["spell"] - additionalProperties: false + 'tome:spell-step-backward': c.object {title: 'Step Backward', description: 'Published when you step backward in time'} - "tome:editing-began": - title: "Editing Began" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published when you have begun changing code" - type: "undefined" - additionalProperties: false + 'tome:spell-loaded': c.object {title: 'Spell Loaded', description: 'Published when a spell is loaded', required: ['spell']}, + spell: {type: 'object'} - "tome:editing-ended": - title: "Editing Ended" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published when you have stopped changing code" - type: "undefined" - additionalProperties: false + 'tome:spell-changed': c.object {title: 'Spell Changed', description: 'Published when a spell is changed', required: ['spell']}, + spell: {type: 'object'} - "tome:problems-updated": - title: "Problems Updated" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published when problems have been updated" - type: "object" - properties: - "spell": "object" - "problems": "array" - "isCast": "boolean" - required: ["spell", "problems", "isCast"] - additionalProperties: false + 'tome:editing-began': c.object {title: 'Editing Began', description: 'Published when you have begun changing code'} - "tome:thang-list-entry-popover-shown": - title: "Thang List Entry Popover Shown" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published when we show the popover for a thang in the master list" - type: "object" - properties: - "entry": "object" - required: ["entry"] - additionalProperties: false + 'tome:editing-ended': c.object {title: 'Editing Ended', description: 'Published when you have stopped changing code'} - "tome:spell-shown": - title: "Spell Shown" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published when we show a spell" - type: "object" - properties: - "thang": "object" - "spell": "object" - required: ["thang", "spell"] - additionalProperties: false + 'tome:problems-updated': c.object {title: 'Problems Updated', description: 'Published when problems have been updated', required: ['spell', 'problems', 'isCast']}, + spell: {type: 'object'} + problems: {type: 'array'} + isCast: {type: 'boolean'} - 'tome:change-language': - title: 'Tome Change Language' - $schema: 'http://json-schema.org/draft-04/schema#' - description: 'Published when the Tome should update its programming language.' - type: 'object' - additionalProperties: false - properties: - language: - type: 'string' - required: ['language'] + 'tome:thang-list-entry-popover-shown': c.object {title: 'Thang List Entry Popover Shown', description: 'Published when we show the popover for a thang in the master list', required: ['entry']}, + entry: {type: 'object'} - 'tome:spell-changed-language': - title: 'Spell Changed Language' - $schema: 'http://json-schema.org/draft-04/schema#' - description: 'Published when an individual spell has updated its code language.' - type: 'object' - additionalProperties: false - properties: - spell: - type: 'object' - language: - type: 'string' - required: ['spell'] + 'tome:spell-shown': c.object {title: 'Spell Shown', description: 'Published when we show a spell', required: ['thang', 'spell']}, + thang: {type: 'object'} + spell: {type: 'object'} - "tome:comment-my-code": - title: "Comment My Code" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published when we comment out a chunk of your code" - type: "undefined" - additionalProperties: false + 'tome:change-language': c.object {title: 'Tome Change Language', description: 'Published when the Tome should update its programming language', required: ['language']}, + language: {type: 'string'} - "tome:change-config": - title: "Change Config" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published when you change your tome settings" - type: "undefined" - additionalProperties: false + 'tome:spell-changed-language': c.object {title: 'Spell Changed Language', description: 'Published when an individual spell has updated its code language', required: ['spell']}, + spell: {type: 'object'} + language: {type: 'string'} - "tome:update-snippets": - title: "Update Snippets" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published when we need to add Zatanna Snippets" - type: "object" - properties: - "propGroups": "object" - "allDocs": "object" - "language": "string" - required: ["propGroups", "allDocs"] - additionalProperties: false + 'tome:comment-my-code': c.object {title: 'Comment My Code', description: 'Published when we comment out a chunk of your code'} - # TODO proposition: add tome to name - "focus-editor": - title: "Focus Editor" - $schema: "http://json-schema.org/draft-04/schema#" - description: "Published whenever we want to give focus back to the editor" - type: "undefined" - additionalProperties: false + 'tome:change-config': c.object {title: 'Change Config', description: 'Published when you change your tome settings'} + + 'tome:update-snippets': c.object {title: 'Update Snippets', description: 'Published when we need to add Zatanna snippets', required: ['propGroups', 'allDocs']}, + propGroups: {type: 'object'} + allDocs: {type: 'object'} + language: {type: 'string'} + + 'tome:insert-snippet': c.object {title: 'Insert Snippet', description: 'Published when we need to insert a Zatanna snippet', required: ['doc', 'language', 'formatted']}, + doc: {type: 'object'} + language: {type: 'string'} + formatted: {type: 'object'} + + 'tome:focus-editor': c.object {title: 'Focus Editor', description: 'Published whenever we want to give focus back to the editor'} + + 'tome:fullscreen-view': c.object {title: 'Fullscreen View', description: 'Published when we want to make the Tome take up most of the screen'} diff --git a/app/schemas/subscriptions/user.coffee b/app/schemas/subscriptions/user.coffee deleted file mode 100644 index b9ae1e4c0..000000000 --- a/app/schemas/subscriptions/user.coffee +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = - 'me:synced': - {} # TODO schema - - 'user-fetched': - {} # TODO schema - - 'edit-wizard-settings': - {} # TODO schema diff --git a/app/schemas/subscriptions/world.coffee b/app/schemas/subscriptions/world.coffee deleted file mode 100644 index 0eb748c5e..000000000 --- a/app/schemas/subscriptions/world.coffee +++ /dev/null @@ -1,18 +0,0 @@ -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:streaming-world-updated': - {} # TODO schema - - 'god:world-load-progress-changed': - {} # TODO schema diff --git a/app/styles/base.sass b/app/styles/base.sass index a00d037ee..443073605 100644 --- a/app/styles/base.sass +++ b/app/styles/base.sass @@ -225,6 +225,14 @@ table.table .ui-slider-handle border: 1px solid black !important +// Override jQuery UI widget images that we don't use +.ui-widget-content, .ui-widget-header, .ui-widget-overlay, .ui-widget-shadow + background-image: none + +.ui-widget-content, .ui-state-default, .ui-widget-header + .ui-state-default, .ui-state-focus, .ui-state-active, .ui-state-highlight, .ui-state-error + background-image: none + // Fonts .header-font diff --git a/app/views/editor/article/ArticleEditView.coffee b/app/views/editor/article/ArticleEditView.coffee index a61f19b2e..420c44356 100644 --- a/app/views/editor/article/ArticleEditView.coffee +++ b/app/views/editor/article/ArticleEditView.coffee @@ -15,7 +15,7 @@ module.exports = class ArticleEditView extends RootView 'click #save-button': 'openSaveModal' subscriptions: - 'save-new-version': 'saveNewArticle' + 'editor:save-new-version': 'saveNewArticle' constructor: (options, @articleID) -> super options @@ -98,4 +98,4 @@ module.exports = class ArticleEditView extends RootView showVersionHistory: (e) -> versionHistoryView = new VersionHistoryView article: @article, @articleID @openModalView versionHistoryView - Backbone.Mediator.publish 'level:view-switched', e + Backbone.Mediator.publish 'editor:view-switched', {} diff --git a/app/views/editor/level/LevelEditView.coffee b/app/views/editor/level/LevelEditView.coffee index 7dd827254..567dd6d54 100644 --- a/app/views/editor/level/LevelEditView.coffee +++ b/app/views/editor/level/LevelEditView.coffee @@ -72,7 +72,7 @@ module.exports = class LevelEditView extends RootView super() return unless @supermodel.finished() @$el.find('a[data-toggle="tab"]').on 'shown.bs.tab', (e) => - Backbone.Mediator.publish 'level:view-switched', e + Backbone.Mediator.publish 'editor:view-switched', {} @insertSubView new ThangsTabView world: @world, supermodel: @supermodel, level: @level @insertSubView new SettingsTabView supermodel: @supermodel @insertSubView new ScriptsTabView world: @world, supermodel: @supermodel, files: @files @@ -81,7 +81,7 @@ module.exports = class LevelEditView extends RootView @insertSubView new RelatedAchievementsView supermodel: @supermodel, level: @level @insertSubView new ComponentDocsView # Don't give it the supermodel, it'll pollute it! - Backbone.Mediator.publish 'level-loaded', level: @level + Backbone.Mediator.publish 'editor:level-loaded', level: @level @showReadOnly() if me.get('anonymous') @patchesView = @insertSubView(new PatchesView(@level), @$el.find('.patches-view')) @listenTo @patchesView, 'accepted-patch', -> location.reload() @@ -96,7 +96,7 @@ module.exports = class LevelEditView extends RootView onPlayLevel: (e) -> team = $(e.target).data('team') sendLevel = => - @childWindow.Backbone.Mediator.publish 'level-reload-from-data', level: @level, supermodel: @supermodel + @childWindow.Backbone.Mediator.publish 'level:reload-from-data', level: @level, supermodel: @supermodel if @childWindow and not @childWindow.closed # Reset the LevelView's world, but leave the rest of the state alone sendLevel() @@ -134,20 +134,20 @@ module.exports = class LevelEditView extends RootView startPatchingLevel: (e) -> @openModalView new SaveVersionModal({model: @level}) - Backbone.Mediator.publish 'level:view-switched', e + Backbone.Mediator.publish 'editor:view-switched', {} startCommittingLevel: (e) -> @openModalView new SaveLevelModal level: @level, supermodel: @supermodel - Backbone.Mediator.publish 'level:view-switched', e + Backbone.Mediator.publish 'editor:view-switched', {} startForking: (e) -> @openModalView new ForkModal model: @level, editorPath: 'level' - Backbone.Mediator.publish 'level:view-switched', e + Backbone.Mediator.publish 'editor:view-switched', {} showVersionHistory: (e) -> versionHistoryView = new VersionHistoryView level: @level, @levelID @openModalView versionHistoryView - Backbone.Mediator.publish 'level:view-switched', e + Backbone.Mediator.publish 'editor:view-switched', {} toggleWatchLevel: -> button = @$el.find('#level-watch-button') diff --git a/app/views/editor/level/components/ComponentsTabView.coffee b/app/views/editor/level/components/ComponentsTabView.coffee index 3cfb953b8..4507184ec 100644 --- a/app/views/editor/level/components/ComponentsTabView.coffee +++ b/app/views/editor/level/components/ComponentsTabView.coffee @@ -14,9 +14,7 @@ module.exports = class ComponentsTabView extends CocoView className: 'tab-pane' subscriptions: - 'edit-level-component': 'editLevelComponent' - 'level-component-edited': 'onLevelComponentEdited' - 'level-component-editing-ended': 'onLevelComponentEditingEnded' + 'editor:level-component-editing-ended': 'onLevelComponentEditingEnded' events: 'click #create-new-component-button': 'createNewLevelComponent' @@ -66,14 +64,11 @@ module.exports = class ComponentsTabView extends CocoView createNewLevelComponent: (e) -> levelComponentNewView = new LevelComponentNewView supermodel: @supermodel @openModalView levelComponentNewView - Backbone.Mediator.publish 'level:view-switched', e + Backbone.Mediator.publish 'editor:view-switched', {} editLevelComponent: (e) -> @levelComponentEditView = @insertSubView new LevelComponentEditView(original: e.original, majorVersion: e.majorVersion, supermodel: @supermodel) - onLevelComponentEdited: (e) -> - Backbone.Mediator.publish 'level-components-changed', {} - onLevelComponentEditingEnded: (e) -> @removeSubView @levelComponentEditView @levelComponentEditView = null @@ -90,6 +85,3 @@ class LevelComponentNode extends TreemaObjectNode m.get('original') is @data.original and m.get('version').major is @data.majorVersion name = "#{comp.get('system')}.#{comp.get('name')} v#{comp.get('version').major}" @buildValueForDisplaySimply valEl, "#{name} (#{count})" - - onEnterPressed: -> - Backbone.Mediator.publish 'edit-level-component', original: @data.original, majorVersion: @data.majorVersion diff --git a/app/views/editor/level/components/LevelComponentEditView.coffee b/app/views/editor/level/components/LevelComponentEditView.coffee index c09600241..67fba26d1 100644 --- a/app/views/editor/level/components/LevelComponentEditView.coffee +++ b/app/views/editor/level/components/LevelComponentEditView.coffee @@ -64,7 +64,6 @@ module.exports = class LevelComponentEditView extends CocoView # Make sure it validates first? for key, value of @componentSettingsTreema.data @levelComponent.set key, value unless key is 'js' # will compile code if needed - Backbone.Mediator.publish 'level-component-edited', levelComponent: @levelComponent null buildConfigSchemaTreema: -> @@ -82,7 +81,6 @@ module.exports = class LevelComponentEditView extends CocoView onConfigSchemaEdited: => @levelComponent.set 'configSchema', @configSchemaTreema.data - Backbone.Mediator.publish 'level-component-edited', levelComponent: @levelComponent buildCodeEditor: -> @editor?.destroy() @@ -100,21 +98,20 @@ module.exports = class LevelComponentEditView extends CocoView onEditorChange: => return if @destroyed @levelComponent.set 'code', @editor.getValue() - Backbone.Mediator.publish 'level-component-edited', levelComponent: @levelComponent null endEditing: (e) -> - Backbone.Mediator.publish 'level-component-editing-ended', levelComponent: @levelComponent + Backbone.Mediator.publish 'editor:level-component-editing-ended', component: @levelComponent null showVersionHistory: (e) -> componentVersionsModal = new ComponentVersionsModal {}, @levelComponent.id @openModalView componentVersionsModal - Backbone.Mediator.publish 'level:view-switched', e + Backbone.Mediator.publish 'editor:view-switched', {} startPatchingComponent: (e) -> @openModalView new SaveVersionModal({model: @levelComponent}) - Backbone.Mediator.publish 'level:view-switched', e + Backbone.Mediator.publish 'editor:view-switched', {} toggleWatchComponent: -> button = @$el.find('#component-watch-button') diff --git a/app/views/editor/level/components/NewLevelComponentModal.coffee b/app/views/editor/level/components/NewLevelComponentModal.coffee index c4ead45de..a65b5c921 100644 --- a/app/views/editor/level/components/NewLevelComponentModal.coffee +++ b/app/views/editor/level/components/NewLevelComponentModal.coffee @@ -13,12 +13,12 @@ module.exports = class NewLevelComponentModal extends ModalView events: 'click #new-level-component-submit': 'makeNewLevelComponent' 'submit form': 'makeNewLevelComponent' - + getRenderData: -> c = super() c.systems = LevelComponent.schema.properties.system.enum c - + makeNewLevelComponent: (e) -> e.preventDefault() system = @$el.find('#level-component-system').val() @@ -38,5 +38,4 @@ module.exports = class NewLevelComponentModal extends ModalView forms.applyErrorsToForm(@$el, JSON.parse(res.responseText)) res.success => @supermodel.registerModel component - Backbone.Mediator.publish 'edit-level-component', original: component.get('_id'), majorVersion: 0 @hide() diff --git a/app/views/editor/level/modals/TerrainRandomizeModal.coffee b/app/views/editor/level/modals/TerrainRandomizeModal.coffee index 7dc37d7c8..fa6da998a 100644 --- a/app/views/editor/level/modals/TerrainRandomizeModal.coffee +++ b/app/views/editor/level/modals/TerrainRandomizeModal.coffee @@ -102,7 +102,7 @@ presets = { 'width': [8, 12] 'height': [8, 12] 'numBarrels': [4,6] - 'cluster': 'barrel' + 'cluster': 'barrel' } 'cave': { 'num':[1,1] @@ -215,9 +215,7 @@ module.exports = class TerrainRandomizeModal extends ModalView presetType = target.attr 'data-preset-type' presetSize = target.attr 'data-preset-size' @randomizeThangs presetType, presetSize - Backbone.Mediator.publish('randomize:terrain-generated', - 'thangs': @thangs - ) + Backbone.Mediator.publish 'editor:random-terrain-generated', thangs: @thangs @hide() randomizeThangs: (presetName, presetSize) -> @@ -272,29 +270,29 @@ module.exports = class TerrainRandomizeModal extends ModalView @addThang { 'id': @getRandomThang(clusters[preset.borders].thangs) 'pos': { - 'x': i + preset.borderSize/2 + 'x': i + preset.borderSize/2 'y': presetSize.y - 3 * preset.borderSize/2 } 'margin': clusters[preset.borders].margin - } + } if ( i / preset.borderSize ) % 2 and i isnt presetSize.x - thangSizes.borderSize.x @addThang { 'id': @getRandomThang(clusters['torch'].thangs) 'pos': { - 'x': i + preset.borderSize + 'x': i + preset.borderSize 'y': presetSize.y - preset.borderSize } 'margin': clusters['torch'].margin - } + } else if ( i / preset.borderSize ) % 2 is 0 and i and _.random(100) < 30 @addThang { 'id': @getRandomThang(clusters['chains'].thangs) 'pos': { - 'x': i + preset.borderSize + 'x': i + preset.borderSize 'y': presetSize.y - preset.borderSize } 'margin': clusters['chains'].margin - } + } for i in _.range(0, presetSize.y, thangSizes.borderSize.y) for j in _.range(preset.borderThickness) @@ -395,7 +393,7 @@ module.exports = class TerrainRandomizeModal extends ModalView 'pos': { 'x': thang.pos.x - preset.borderSize / 2 'y': thang.pos.y + preset.borderSize / 2 - } + } 'margin': clusters['torch'].margin } @@ -415,7 +413,7 @@ module.exports = class TerrainRandomizeModal extends ModalView for t in _.range(0, roomThickness) for i in _.range(rect.y - rect.height/2 - t * preset.borderSize, rect.y + rect.height/2 + (t+1) * preset.borderSize, preset.borderSize) - # Left wall + # Left wall @addThang { 'id': @getRandomThang(clusters[room.cluster].thangs) 'pos': { @@ -425,7 +423,7 @@ module.exports = class TerrainRandomizeModal extends ModalView 'margin': clusters[room.cluster].margin } - # Right wall + # Right wall @addThang { 'id': @getRandomThang(clusters[room.cluster].thangs) 'pos': { diff --git a/app/views/editor/level/modals/WorldSelectModal.coffee b/app/views/editor/level/modals/WorldSelectModal.coffee index 4274a76ec..38ba12fc6 100644 --- a/app/views/editor/level/modals/WorldSelectModal.coffee +++ b/app/views/editor/level/modals/WorldSelectModal.coffee @@ -10,8 +10,8 @@ module.exports = class WorldSelectModal extends ModalView cache: false subscriptions: - 'choose-region': 'selectionMade' - 'choose-point': 'selectionMade' + 'surface:choose-region': 'selectionMade' + 'surface:choose-point': 'selectionMade' events: 'click #done-button': 'done' diff --git a/app/views/editor/level/scripts/ScriptsTabView.coffee b/app/views/editor/level/scripts/ScriptsTabView.coffee index cf412a649..a7f066be0 100644 --- a/app/views/editor/level/scripts/ScriptsTabView.coffee +++ b/app/views/editor/level/scripts/ScriptsTabView.coffee @@ -11,7 +11,7 @@ module.exports = class ScriptsTabView extends CocoView className: 'tab-pane' subscriptions: - 'level-loaded': 'onLevelLoaded' + 'editor:level-loaded': 'onLevelLoaded' constructor: (options) -> super options @@ -133,7 +133,7 @@ class ScriptNode extends TreemaObjectNode onDeletePressed: (e) -> returnVal = super(e) if @callbacks.removeChild - @callbacks.removeChild() + @callbacks.removeChild() returnVal onRightArrowPressed: -> @@ -159,7 +159,7 @@ class EventPropsNode extends TreemaNode.nodeMap.string joined = '(unset)' if not joined.length @buildValueForDisplaySimply valEl, joined - buildValueForEditing: (valEl) -> + buildValueForEditing: (valEl) -> super(valEl) channel = @getRoot().data.channel channelSchema = Backbone.Mediator.channelSchemas[channel] diff --git a/app/views/editor/level/settings/SettingsTabView.coffee b/app/views/editor/level/settings/SettingsTabView.coffee index cf2c57196..dabca773a 100644 --- a/app/views/editor/level/settings/SettingsTabView.coffee +++ b/app/views/editor/level/settings/SettingsTabView.coffee @@ -17,7 +17,7 @@ module.exports = class SettingsTabView extends CocoView ] subscriptions: - 'level-loaded': 'onLevelLoaded' + 'editor:level-loaded': 'onLevelLoaded' constructor: (options) -> super options @@ -56,4 +56,4 @@ module.exports = class SettingsTabView extends CocoView @level.set key, @settingsTreema.data[key] class SettingsNode extends TreemaObjectNode - nodeDescription: 'Settings' \ No newline at end of file + nodeDescription: 'Settings' diff --git a/app/views/editor/level/systems/LevelSystemEditView.coffee b/app/views/editor/level/systems/LevelSystemEditView.coffee index b1bcf8f67..455cf13ca 100644 --- a/app/views/editor/level/systems/LevelSystemEditView.coffee +++ b/app/views/editor/level/systems/LevelSystemEditView.coffee @@ -58,7 +58,6 @@ module.exports = class LevelSystemEditView extends CocoView # Make sure it validates first? for key, value of @systemSettingsTreema.data @levelSystem.set key, value unless key is 'js' # will compile code if needed - Backbone.Mediator.publish 'level-system-edited', levelSystem: @levelSystem null buildConfigSchemaTreema: -> @@ -76,7 +75,6 @@ module.exports = class LevelSystemEditView extends CocoView onConfigSchemaEdited: => @levelSystem.set 'configSchema', @configSchemaTreema.data - Backbone.Mediator.publish 'level-system-edited', levelSystem: @levelSystem buildCodeEditor: -> @editor?.destroy() @@ -93,21 +91,20 @@ module.exports = class LevelSystemEditView extends CocoView onEditorChange: => @levelSystem.set 'code', @editor.getValue() - Backbone.Mediator.publish 'level-system-edited', levelSystem: @levelSystem null endEditing: (e) -> - Backbone.Mediator.publish 'level-system-editing-ended', levelSystem: @levelSystem + Backbone.Mediator.publish 'editor:level-system-editing-ended', system: @levelSystem null showVersionHistory: (e) -> systemVersionsModal = new SystemVersionsModal {}, @levelSystem.id @openModalView systemVersionsModal - Backbone.Mediator.publish 'level:view-switched', e + Backbone.Mediator.publish 'editor:view-switched', {} startPatchingSystem: (e) -> @openModalView new SaveVersionModal({model: @levelSystem}) - Backbone.Mediator.publish 'level:view-switched', e + Backbone.Mediator.publish 'editor:view-switched', {} toggleWatchSystem: -> console.log 'toggle watch system?' diff --git a/app/views/editor/level/systems/NewLevelSystemModal.coffee b/app/views/editor/level/systems/NewLevelSystemModal.coffee index d2f509dbf..dd66343f9 100644 --- a/app/views/editor/level/systems/NewLevelSystemModal.coffee +++ b/app/views/editor/level/systems/NewLevelSystemModal.coffee @@ -32,5 +32,5 @@ module.exports = class NewLevelSystemModal extends ModalView forms.applyErrorsToForm(@$el, JSON.parse(res.responseText)) res.success => @supermodel.registerModel system - Backbone.Mediator.publish 'edit-level-system', original: system.get('_id'), majorVersion: 0 + Backbone.Mediator.publish 'editor:edit-level-system', original: system.get('_id'), majorVersion: 0 @hide() diff --git a/app/views/editor/level/systems/SystemsTabView.coffee b/app/views/editor/level/systems/SystemsTabView.coffee index 89fa16bf1..2ade6d0bd 100644 --- a/app/views/editor/level/systems/SystemsTabView.coffee +++ b/app/views/editor/level/systems/SystemsTabView.coffee @@ -13,11 +13,10 @@ module.exports = class SystemsTabView extends CocoView className: 'tab-pane' subscriptions: - 'level-system-added': 'onLevelSystemAdded' - 'edit-level-system': 'editLevelSystem' - 'level-system-edited': 'onLevelSystemEdited' - 'level-system-editing-ended': 'onLevelSystemEditingEnded' - 'level-loaded': 'onLevelLoaded' + 'editor:level-system-added': 'onLevelSystemAdded' + 'editor:edit-level-system': 'editLevelSystem' + 'editor:level-system-editing-ended': 'onLevelSystemEditingEnded' + 'editor:level-loaded': 'onLevelLoaded' events: 'click #add-system-button': 'addLevelSystem' @@ -91,18 +90,15 @@ module.exports = class SystemsTabView extends CocoView addLevelSystem: (e) -> @openModalView new AddLevelSystemModal supermodel: @supermodel, extantSystems: _.cloneDeep @systemsTreema.data - Backbone.Mediator.publish 'level:view-switched', e + Backbone.Mediator.publish 'editor:view-switched', {} createNewLevelSystem: (e) -> @openModalView new NewLevelSystemModal supermodel: @supermodel - Backbone.Mediator.publish 'level:view-switched', e + Backbone.Mediator.publish 'editor:view-switched', {} editLevelSystem: (e) -> @levelSystemEditView = @insertSubView new LevelSystemEditView(original: e.original, majorVersion: e.majorVersion, supermodel: @supermodel) - onLevelSystemEdited: (e) -> - Backbone.Mediator.publish 'level-systems-changed', systemsData: @systemsTreema.data - onLevelSystemEditingEnded: (e) -> @removeSubView @levelSystemEditView @levelSystemEditView = null @@ -150,7 +146,7 @@ class LevelSystemNode extends TreemaObjectNode onEnterPressed: (e) -> super e - Backbone.Mediator.publish 'edit-level-system', original: @data.original, majorVersion: @data.majorVersion + Backbone.Mediator.publish 'editor:edit-level-system', original: @data.original, majorVersion: @data.majorVersion open: (depth) -> super depth diff --git a/app/views/editor/level/thangs/LevelThangEditView.coffee b/app/views/editor/level/thangs/LevelThangEditView.coffee index 7ed5dce9e..a7c6e1f9f 100644 --- a/app/views/editor/level/thangs/LevelThangEditView.coffee +++ b/app/views/editor/level/thangs/LevelThangEditView.coffee @@ -56,13 +56,10 @@ module.exports = class LevelThangEditView extends CocoView saveThang: (e) -> # Make sure it validates first? - event = - thangData: @thangData - id: @oldID - Backbone.Mediator.publish 'level-thang-edited', event + Backbone.Mediator.publish 'editor:level-thang-edited', thangData: @thangData, thangID: @oldID navigateToAllThangs: -> - Backbone.Mediator.publish 'level-thang-done-editing' + Backbone.Mediator.publish 'editor:level-thang-done-editing', {} toggleNameEdit: -> link = @$el.find '#thang-name-link' diff --git a/app/views/editor/level/thangs/ThangsTabView.coffee b/app/views/editor/level/thangs/ThangsTabView.coffee index ee7954d58..2ca8211e5 100644 --- a/app/views/editor/level/thangs/ThangsTabView.coffee +++ b/app/views/editor/level/thangs/ThangsTabView.coffee @@ -34,15 +34,15 @@ module.exports = class ThangsTabView extends CocoView 'surface:mouse-moved': 'onSurfaceMouseMoved' 'surface:mouse-over': 'onSurfaceMouseOver' 'surface:mouse-out': 'onSurfaceMouseOut' - 'edit-level-thang': 'editThang' - 'level-thang-edited': 'onLevelThangEdited' - 'level-thang-done-editing': 'onLevelThangDoneEditing' - 'level:view-switched': 'onViewSwitched' + 'editor:edit-level-thang': 'editThang' + 'editor:level-thang-edited': 'onLevelThangEdited' + 'editor:level-thang-done-editing': 'onLevelThangDoneEditing' + 'editor:view-switched': 'onViewSwitched' 'sprite:dragged': 'onSpriteDragged' 'sprite:mouse-up': 'onSpriteMouseUp' 'sprite:double-clicked': 'onSpriteDoubleClicked' 'surface:stage-mouse-up': 'onStageMouseUp' - 'randomize:terrain-generated': 'onRandomizeTerrain' + 'editor:random-terrain-generated': 'onRandomTerrainGenerated' events: 'click #extant-thangs-filter button': 'onFilterExtantThangs' @@ -232,7 +232,7 @@ module.exports = class ThangsTabView extends CocoView return unless e.thang @editThang thangID: e.thang.id - onRandomizeTerrain: (e) -> + onRandomTerrainGenerated: (e) -> @thangsBatch = [] nonRandomThangs = (thang for thang in @thangsTreema.get('') when not /Random/.test thang.id) @thangsTreema.set '', nonRandomThangs @@ -402,7 +402,6 @@ module.exports = class ThangsTabView extends CocoView thang.isSelectable = not thang.isLand for thang in @world.thangs # let us select walls and such @surface?.setWorld @world @selectAddThangType @addThangType, @cloneSourceThang if @addThangType # make another addThang sprite, since the World just refreshed - Backbone.Mediator.publish 'level-thangs-changed', thangsData: @thangsTreema.data null onTreemaThangSelected: (e, selectedTreemas) => @@ -449,13 +448,13 @@ module.exports = class ThangsTabView extends CocoView @editThangView = new LevelThangEditView thangData: thangData, level: @level, world: @world, supermodel: @supermodel # supermodel needed for checkForMissingSystems @insertSubView @editThangView @$el.find('.thangs-column').hide() - Backbone.Mediator.publish 'level:view-switched', e + Backbone.Mediator.publish 'editor:view-switched', {} onLevelThangEdited: (e) -> newThang = e.thangData - @thangsTreema.set "id=#{e.id}", newThang + @thangsTreema.set "id=#{e.thangID}", newThang - onLevelThangDoneEditing: -> + onLevelThangDoneEditing: (e) -> @removeSubView @editThangView @editThangView = null @onThangsChanged() @@ -530,4 +529,4 @@ class ThangNode extends TreemaObjectNode @buildValueForDisplaySimply valEl, s onEnterPressed: -> - Backbone.Mediator.publish 'edit-level-thang', thangID: @data.id + Backbone.Mediator.publish 'editor:edit-level-thang', thangID: @data.id diff --git a/app/views/editor/thang/ThangTypeEditView.coffee b/app/views/editor/thang/ThangTypeEditView.coffee index 1522ddeb5..e54bb9274 100644 --- a/app/views/editor/thang/ThangTypeEditView.coffee +++ b/app/views/editor/thang/ThangTypeEditView.coffee @@ -44,7 +44,7 @@ module.exports = class ThangTypeEditView extends RootView 'keyup .play-with-level-input': 'onPlayLevelKeyUp' subscriptions: - 'save-new-version': 'saveNewThangType' + 'editor:save-new-version': 'saveNewThangType' # init / render @@ -438,7 +438,7 @@ module.exports = class ThangTypeEditView extends RootView level = _.string.slugify level if @childWindow and not @childWindow.closed # Reset the LevelView's world, but leave the rest of the state alone - @childWindow.Backbone.Mediator.publish 'level-reload-thang-type', thangType: @thangType + @childWindow.Backbone.Mediator.publish 'level:reload-thang-type', thangType: @thangType else # Create a new Window with a blank LevelView scratchLevelID = level + '?dev=true' diff --git a/app/views/game-menu/ChooseHeroView.coffee b/app/views/game-menu/ChooseHeroView.coffee index 8568877e9..88632e1c4 100644 --- a/app/views/game-menu/ChooseHeroView.coffee +++ b/app/views/game-menu/ChooseHeroView.coffee @@ -9,7 +9,7 @@ module.exports = class ChooseHeroView extends CocoView template: template events: - 'click #restart-level-confirm-button': -> Backbone.Mediator.publish 'restart-level' + 'click #restart-level-confirm-button': -> Backbone.Mediator.publish 'level:restart-level', {} getRenderData: (context={}) -> context = super(context) diff --git a/app/views/game-menu/OptionsView.coffee b/app/views/game-menu/OptionsView.coffee index e1bd2c53e..f2cf46b2e 100644 --- a/app/views/game-menu/OptionsView.coffee +++ b/app/views/game-menu/OptionsView.coffee @@ -61,7 +61,7 @@ module.exports = class OptionsView extends CocoView volume = @volumeSlider.slider('value') me.set 'volume', volume @$el.find('#option-volume-value').text (volume * 100).toFixed(0) + '%' - Backbone.Mediator.publish 'level-set-volume', volume: volume + Backbone.Mediator.publish 'level:set-volume', volume: volume onHidden: -> if @playerName and @playerName isnt me.get('name') @@ -72,7 +72,7 @@ module.exports = class OptionsView extends CocoView @aceConfig.behaviors = @$el.find('#option-behaviors').prop('checked') @aceConfig.liveCompletion = @$el.find('#option-live-completion').prop('checked') me.set 'aceConfig', @aceConfig - Backbone.Mediator.publish 'tome:change-config' + Backbone.Mediator.publish 'tome:change-config', {} updateMusic: -> me.set 'music', @$el.find('#option-music').prop('checked') diff --git a/app/views/kinds/CocoView.coffee b/app/views/kinds/CocoView.coffee index a562621dd..eb6d4859f 100644 --- a/app/views/kinds/CocoView.coffee +++ b/app/views/kinds/CocoView.coffee @@ -179,7 +179,7 @@ module.exports = class CocoView extends Backbone.View $('#modal-wrapper .modal').modal(modalOptions).on 'hidden.bs.modal', @modalClosed window.currentModal = modalView @getRootView().stopListeningToShortcuts(true) - Backbone.Mediator.publish 'modal-opened', {} + Backbone.Mediator.publish 'modal:opened', {} modalClosed: => visibleModal.willDisappear() if visibleModal @@ -193,7 +193,7 @@ module.exports = class CocoView extends Backbone.View @openModalView(wm) else @getRootView().listenToShortcuts(true) - Backbone.Mediator.publish 'modal-closed', {} + Backbone.Mediator.publish 'modal:closed', {} # Loading RootViews @@ -268,7 +268,7 @@ module.exports = class CocoView extends Backbone.View view.parentKey = key @subviews[key] = view view - + makeSubViewKey: (view) -> key = view.id or (view.constructor.name+classCount++) key = _.string.underscored(key) # handy for autocomplete in dev console diff --git a/app/views/kinds/RootView.coffee b/app/views/kinds/RootView.coffee index 59603ccd1..e44b3b0ba 100644 --- a/app/views/kinds/RootView.coffee +++ b/app/views/kinds/RootView.coffee @@ -36,8 +36,8 @@ module.exports = class RootView extends CocoView showNewAchievement: (achievement, earnedAchievement) -> popup = new AchievementPopup achievement: achievement, earnedAchievement: earnedAchievement - handleNewAchievements: (earnedAchievements) -> - _.each earnedAchievements.models, (earnedAchievement) => + handleNewAchievements: (e) -> + _.each e.earnedAchievements.models, (earnedAchievement) => achievement = new Achievement(_id: earnedAchievement.get('achievement')) achievement.fetch success: (achievement) => @showNewAchievement(achievement, earnedAchievement) diff --git a/app/views/modal/AuthModal.coffee b/app/views/modal/AuthModal.coffee index fd87dd988..67abf2537 100644 --- a/app/views/modal/AuthModal.coffee +++ b/app/views/modal/AuthModal.coffee @@ -19,8 +19,8 @@ module.exports = class AuthModal extends ModalView 'keyup #name': 'onNameChange' subscriptions: - 'server-error': 'onServerError' - 'logging-in-with-facebook': 'onLoggingInWithFacebook' + 'errors:server-error': 'onServerError' + 'auth:logging-in-with-facebook': 'onLoggingInWithFacebook' constructor: (options) -> @onNameChange = _.debounce @checkNameExists, 500 @@ -39,7 +39,7 @@ module.exports = class AuthModal extends ModalView c.onEmployersPage = Backbone.history.fragment is "employers" c.me = me c - + afterInsert: -> super() _.delay application.router.renderLoginButtons, 500 @@ -104,4 +104,4 @@ module.exports = class AuthModal extends ModalView forms.setErrorToProperty @$el, 'name', "That name is taken! How about #{newName}?", true onGitHubLoginClicked: -> - Backbone.Mediator.publish 'github-login' + Backbone.Mediator.publish 'auth:log-in-with-github', {} diff --git a/app/views/modal/EmployerSignupModal.coffee b/app/views/modal/EmployerSignupModal.coffee index 65c9f1392..2c5306356 100644 --- a/app/views/modal/EmployerSignupModal.coffee +++ b/app/views/modal/EmployerSignupModal.coffee @@ -11,8 +11,8 @@ module.exports = class EmployerSignupModal extends ModalView closeButton: true subscriptions: - 'server-error': 'onServerError' - 'linkedin-loaded': 'onLinkedInLoaded' + 'errors:server-error': 'onServerError' + 'auth:linkedin-api-loaded': 'onLinkedInLoaded' 'created-user-without-reload': 'createdAccount' events: diff --git a/app/views/modal/RecoverModal.coffee b/app/views/modal/RecoverModal.coffee index 64cdd8154..cb7781bed 100644 --- a/app/views/modal/RecoverModal.coffee +++ b/app/views/modal/RecoverModal.coffee @@ -18,7 +18,7 @@ module.exports = class RecoverModal extends ModalView 'keydown input': 'recoverAccount' subscriptions: - 'server-error': 'onServerError' + 'errors:server-error': 'onServerError' onServerError: (e) -> # TODO: work error handling into a separate forms system @disableModalInProgress(@$el) diff --git a/app/views/modal/SaveVersionModal.coffee b/app/views/modal/SaveVersionModal.coffee index 16367273f..77c5556a7 100644 --- a/app/views/modal/SaveVersionModal.coffee +++ b/app/views/modal/SaveVersionModal.coffee @@ -43,9 +43,9 @@ module.exports = class SaveVersionModal extends ModalView onSubmitForm: (e) -> e.preventDefault() if @isPatch then @submitPatch() else @saveChanges() - + saveChanges: -> - Backbone.Mediator.publish 'save-new-version', { + Backbone.Mediator.publish 'editor:save-new-version', { major: @$el.find('#major-version').prop('checked') commitMessage: @$el.find('#commit-message').val() } diff --git a/app/views/play/SpectateView.coffee b/app/views/play/SpectateView.coffee index eb11eda33..30fb92aca 100644 --- a/app/views/play/SpectateView.coffee +++ b/app/views/play/SpectateView.coffee @@ -37,38 +37,21 @@ module.exports = class SpectateLevelView extends RootView id: 'spectate-level-view' template: template cache: false - shortcutsEnabled: true isEditorPreview: false subscriptions: - 'level-set-volume': (e) -> createjs.Sound.setVolume(e.volume) - 'level-highlight-dom': 'onHighlightDom' - 'end-level-highlight-dom': 'onEndHighlight' - 'level-focus-dom': 'onFocusDom' - 'level-disable-controls': 'onDisableControls' - 'level-enable-controls': 'onEnableControls' + 'level:set-volume': (e) -> createjs.Sound.setVolume(e.volume) 'god:new-world-created': 'onNewWorld' + 'god:streaming-world-updated': 'onNewWorld' 'god:infinite-loop': 'onInfiniteLoop' - 'level-reload-from-data': 'onLevelReloadFromData' - 'play-next-level': 'onPlayNextLevel' 'surface:world-set-up': 'onSurfaceSetUpNewWorld' - 'level:set-team': 'setTeam' - 'god:new-world-created': 'loadSoundsForWorld' - 'god:streaming-world-updated': 'loadSoundsForWorld' - 'next-game-pressed': 'onNextGamePressed' + 'level:next-game-pressed': 'onNextGamePressed' 'level:started': 'onLevelStarted' 'level:loading-view-unveiled': 'onLoadingViewUnveiled' - events: - 'click #level-done-button': 'onDonePressed' - - shortcuts: - 'ctrl+s': 'onCtrlS' - constructor: (options, @levelID) -> console.profile?() if PROFILE_ME super options - $(window).on('resize', @onWindowResize) @sessionOne = @getQueryVariable 'session-one' @sessionTwo = @getQueryVariable 'session-two' @@ -207,143 +190,16 @@ module.exports = class SpectateLevelView extends RootView @insertSubView new HUDView {} worldName = utils.i18n @level.attributes, 'name' @controlBar = @insertSubView new ControlBarView {worldName: worldName, session: @session, level: @level, supermodel: @supermodel, playableTeams: @world.playableTeams, spectateGame: true} - #Backbone.Mediator.publish('level-set-debug', debug: true) if me.displayName() is 'Nick' - - afterInsert: -> - super() # callbacks - onCtrlS: (e) -> - e.preventDefault() - - onLevelReloadFromData: (e) -> - isReload = Boolean @world - @setLevel e.level, e.supermodel - if isReload - @scriptManager.setScripts(e.level.get('scripts')) - Backbone.Mediator.publish 'tome:cast-spell' # a bit hacky - - onWindowResize: (s...) -> - $('#pointer').css('opacity', 0.0) - - onDisableControls: (e) -> - return if e.controls and not ('level' in e.controls) - @shortcutsEnabled = false - @wasFocusedOn = document.activeElement - $('body').focus() - - onEnableControls: (e) -> - return if e.controls? and not ('level' in e.controls) - @shortcutsEnabled = true - $(@wasFocusedOn).focus() if @wasFocusedOn - @wasFocusedOn = null - - onDonePressed: -> return - - - onNewWorld: (e) -> - @world = e.world - onInfiniteLoop: (e) -> return unless e.firstWorld @openModalView new InfiniteLoopModal() window.tracker?.trackEvent 'Saw Initial Infinite Loop', level: @world.name, label: @world.name - onPlayNextLevel: -> - nextLevel = @getNextLevel() - nextLevelID = nextLevel.get('slug') or nextLevel.id - url = "/play/level/#{nextLevelID}" - Backbone.Mediator.publish 'router:navigate', { - route: url, - viewClass: PlayLevelView, - viewArgs: [{supermodel:@supermodel}, nextLevelID]} - - getNextLevel: -> - nextLevelOriginal = @level.get('nextLevel')?.original - levels = @supermodel.getModels(Level) - return l for l in levels when l.get('original') is nextLevelOriginal - - onHighlightDom: (e) -> - if e.delay - delay = e.delay - delete e.delay - @pointerInterval = _.delay((=> @onHighlightDom e), delay) - return - @addPointer() - selector = e.selector + ':visible' - dom = $(selector) - return if parseFloat(dom.css('opacity')) is 0.0 - offset = dom.offset() - return if not offset - target_left = offset.left + dom.outerWidth() * 0.5 - target_top = offset.top + dom.outerHeight() * 0.5 - body = $('#level-view') - - if e.sides - if 'left' in e.sides then target_left = offset.left - if 'right' in e.sides then target_left = offset.left + dom.outerWidth() - if 'top' in e.sides then target_top = offset.top - if 'bottom' in e.sides then target_top = offset.top + dom.outerHeight() - else - # aim to hit the side if the target is entirely on one side of the screen - if offset.left > body.outerWidth()*0.5 - target_left = offset.left - else if offset.left + dom.outerWidth() < body.outerWidth()*0.5 - target_left = offset.left + dom.outerWidth() - - # aim to hit the bottom or top if the target is entirely on the top or bottom of the screen - if offset.top > body.outerWidth()*0.5 - target_top = offset.top - else if offset.top + dom.outerHeight() < body.outerHeight()*0.5 - target_top = offset.top + dom.outerHeight() - - if e.offset - target_left += e.offset.x - target_top += e.offset.y - - @pointerRadialDistance = -47 # - Math.sqrt(Math.pow(dom.outerHeight()*0.5, 2), Math.pow(dom.outerWidth()*0.5)) - @pointerRotation = e.rotation ? Math.atan2(body.outerWidth()*0.5 - target_left, target_top - body.outerHeight()*0.5) - pointer = $('#pointer') - pointer - .css('opacity', 1.0) - .css('transition', 'none') - .css('transform', "rotate(#{@pointerRotation}rad) translate(-3px, #{@pointerRadialDistance}px)") - .css('top', target_top - 50) - .css('left', target_left - 50) - setTimeout((=> - @animatePointer() - clearInterval(@pointerInterval) - @pointerInterval = setInterval(@animatePointer, 1200) - ), 1) - - animatePointer: -> - pointer = $('#pointer') - pointer.css('transition', 'all 0.6s ease-out') - pointer.css('transform', "rotate(#{@pointerRotation}rad) translate(-3px, #{@pointerRadialDistance-50}px)") - setTimeout((=> - pointer.css('transform', "rotate(#{@pointerRotation}rad) translate(-3px, #{@pointerRadialDistance}px)").css('transition', 'all 0.4s ease-in')), 800) - - onFocusDom: (e) -> $(e.selector).focus() - - onEndHighlight: -> - $('#pointer').css('opacity', 0.0) - clearInterval(@pointerInterval) - - onMultiplayerChanged: (e) -> - if @session.get('multiplayer') - @bus.connect() - else - @bus.removeFirebaseData => - @bus.disconnect() - # initialization - addPointer: -> - p = $('#pointer') - return if p.length - @$el.append($('')) - initSurface: -> surfaceCanvas = $('canvas#surface', @$el) @surface = new Surface(@world, surfaceCanvas, thangTypes: @supermodel.getModels(ThangType), playJingle: not @isEditorPreview, spectateGame: true) @@ -372,14 +228,14 @@ module.exports = class SpectateLevelView extends RootView initVolume: -> volume = me.get('volume') volume = 1.0 unless volume? - Backbone.Mediator.publish 'level-set-volume', volume: volume + Backbone.Mediator.publish 'level:set-volume', volume: volume onSurfaceSetUpNewWorld: -> return if @alreadyLoadedState @alreadyLoadedState = true state = @originalSessionState if state.playing? - Backbone.Mediator.publish 'level-set-playing', { playing: state.playing } + Backbone.Mediator.publish 'level:set-playing', playing: state.playing register: -> return @@ -400,17 +256,22 @@ module.exports = class SpectateLevelView extends RootView # Dynamic sound loading - loadSoundsForWorld: (e) -> + onNewWorld: (e) -> return if @headless - world = e.world + scripts = @world.scripts # Since these worlds don't have scripts, preserve them. + @world = e.world thangTypes = @supermodel.getModels(ThangType) - for [spriteName, message] in world.thangDialogueSounds() + startFrame = @lastWorldFramesLoaded ? 0 + if @world.frames.length is @world.totalFrames # Finished loading + @lastWorldFramesLoaded = 0 + else + @lastWorldFramesLoaded = @world.frames.length + for [spriteName, message] in @world.thangDialogueSounds startFrame continue unless thangType = _.find thangTypes, (m) -> m.get('name') is spriteName continue unless sound = AudioPlayer.soundForDialogue message, thangType.get('soundTriggers') AudioPlayer.preloadSoundReference sound onNextGamePressed: (e) -> - console.log 'You want to see the next game!' @fetchRandomSessionPair (err, data) => if err? then return console.log "There was an error fetching the random session pair: #{data}" @sessionOne = data[0]._id @@ -445,10 +306,8 @@ module.exports = class SpectateLevelView extends RootView @levelLoader?.destroy() @surface?.destroy() @god?.destroy() - $(window).off('resize', @onWindowResize) @goalManager?.destroy() @scriptManager?.destroy() delete window.world # not sure where this is set, but this is one way to clean it up - clearInterval(@pointerInterval) console.profileEnd?() if PROFILE_ME super() diff --git a/app/views/play/ladder/LadderTabView.coffee b/app/views/play/ladder/LadderTabView.coffee index 27a43c4b6..cd437bc6c 100644 --- a/app/views/play/ladder/LadderTabView.coffee +++ b/app/views/play/ladder/LadderTabView.coffee @@ -21,10 +21,10 @@ module.exports = class LadderTabView extends CocoView 'click .load-more-ladder-entries': 'onLoadMoreLadderEntries' subscriptions: - 'fbapi-loaded': 'checkFriends' - 'gapi-loaded': 'checkFriends' - 'facebook-logged-in': 'onConnectedWithFacebook' - 'gplus-logged-in': 'onConnectedWithGPlus' + 'auth:facebook-api-loaded': 'checkFriends' + 'auth:gplus-api-loaded': 'checkFriends' + 'auth:logged-in-with-facebook': 'onConnectedWithFacebook' + 'auth:logged-in-with-gplus': 'onConnectedWithGPlus' constructor: (options, @level, @sessions) -> super(options) diff --git a/app/views/play/ladder/MyMatchesTabView.coffee b/app/views/play/ladder/MyMatchesTabView.coffee index 13bd52882..0b9b1afa1 100644 --- a/app/views/play/ladder/MyMatchesTabView.coffee +++ b/app/views/play/ladder/MyMatchesTabView.coffee @@ -61,7 +61,7 @@ module.exports = class MyMatchesTabView extends CocoView state = 'tie' if match.metrics.rank is opponent.metrics.rank fresh = match.date > (new Date(new Date() - 20 * 1000)).toISOString() if fresh - Backbone.Mediator.publish 'play-sound', trigger: 'chat_received' + Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'chat_received' { state: state opponentName: @nameMap[opponent.userID] @@ -88,7 +88,7 @@ module.exports = class MyMatchesTabView extends CocoView team.scoreHistory = scoreHistory if not team.isRanking and @previouslyRankingTeams[team.id] - Backbone.Mediator.publish 'play-sound', trigger: 'cast-end' + Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'cast-end' @previouslyRankingTeams[team.id] = team.isRanking ctx diff --git a/app/views/play/level/ControlBarView.coffee b/app/views/play/level/ControlBarView.coffee index d4fbe91c6..0afcf7e95 100644 --- a/app/views/play/level/ControlBarView.coffee +++ b/app/views/play/level/ControlBarView.coffee @@ -16,7 +16,7 @@ module.exports = class ControlBarView extends CocoView window.tracker?.trackEvent 'Clicked Docs', level: @level.get('name'), label: @level.get('name') @showGuideModal() - 'click #next-game-button': -> Backbone.Mediator.publish 'next-game-pressed', {} + 'click #next-game-button': -> Backbone.Mediator.publish 'level:next-game-pressed', {} 'click #game-menu-button': 'showGameMenuModal' diff --git a/app/views/play/level/LevelChatView.coffee b/app/views/play/level/LevelChatView.coffee index 5c4fe650a..8e71c2c24 100644 --- a/app/views/play/level/LevelChatView.coffee +++ b/app/views/play/level/LevelChatView.coffee @@ -51,7 +51,7 @@ module.exports = class LevelChatView extends CocoView @playNoise() if e.message.authorID isnt me.id playNoise: -> - Backbone.Mediator.publish 'play-sound', trigger: 'chat_received' + Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'chat_received' messageObjectToJQuery: (message) -> td = $('