mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-02-17 08:50:58 -05:00
Some work on subscription definitions for the validated Backbone Mediator. Added 'script-manager:tick' channel.
This commit is contained in:
parent
a6352c214a
commit
a7f24ab04f
6 changed files with 75 additions and 6 deletions
|
@ -1,3 +1,4 @@
|
|||
Backbone.Mediator.setValidationEnabled false
|
||||
app = require 'application'
|
||||
|
||||
channelSchemas =
|
||||
|
@ -17,6 +18,10 @@ definitionSchemas =
|
|||
'misc': require './schemas/definitions/misc'
|
||||
|
||||
init = ->
|
||||
# Set up Backbone.Mediator schemas
|
||||
setUpDefinitions()
|
||||
setUpChannels()
|
||||
Backbone.Mediator.setValidationEnabled true
|
||||
app.initialize()
|
||||
Backbone.history.start({ pushState: true })
|
||||
handleNormalUrls()
|
||||
|
@ -25,10 +30,6 @@ init = ->
|
|||
treemaExt.setup()
|
||||
filepicker.setKey('AvlkNoldcTOU4PvKi2Xm7z')
|
||||
|
||||
# Set up Backbone.Mediator schemas
|
||||
setUpDefinitions()
|
||||
setUpChannels()
|
||||
|
||||
$ -> init()
|
||||
|
||||
handleNormalUrls = ->
|
||||
|
|
|
@ -35,6 +35,7 @@ module.exports = class DOMScriptModule extends ScriptModule
|
|||
sides: dom.highlight.sides
|
||||
offset: dom.highlight.offset
|
||||
rotation: dom.highlight.rotation
|
||||
note.event = _.pick note.event, (value) -> not _.isUndefined value
|
||||
@maybeApplyDelayToNote note
|
||||
note
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass
|
|||
@debugScripts = @view.getQueryVariable 'dev'
|
||||
@initProperties()
|
||||
@addScriptSubscriptions()
|
||||
@beginTicking()
|
||||
|
||||
setScripts: (@originalScripts) ->
|
||||
@quiet = true
|
||||
|
@ -74,6 +75,25 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass
|
|||
script.id = (idNum++).toString() unless script.id
|
||||
callback = makeCallback(script.channel) # curry in the channel argument
|
||||
@addNewSubscription(script.channel, callback)
|
||||
|
||||
beginTicking: ->
|
||||
@tickInterval = setInterval @tick, 5000
|
||||
|
||||
tick: =>
|
||||
scriptStates = {}
|
||||
now = new Date()
|
||||
for script in @scripts
|
||||
scriptStates[script.id] =
|
||||
timeSinceLastEnded: (if script.lastEnded then now - script.lastEnded else 0) / 1000
|
||||
timeSinceLastTriggered: (if script.lastTriggered then now - script.lastTriggered else 0) / 1000
|
||||
|
||||
stateEvent =
|
||||
scriptRunning: @currentNoteGroup?.scriptID or ''
|
||||
noteGroupRunning: @currentNoteGroup?.name or ''
|
||||
scriptStates: scriptStates
|
||||
timeSinceLastScriptEnded: (if @lastScriptEnded then now - @lastScriptEnded else 0) / 1000
|
||||
|
||||
Backbone.Mediator.publish 'script-manager:tick', stateEvent
|
||||
|
||||
loadFromSession: ->
|
||||
# load the queue with note groups to skip through
|
||||
|
@ -123,6 +143,7 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass
|
|||
|
||||
destroy: ->
|
||||
@onEndAll()
|
||||
clearInterval @tickInterval
|
||||
super()
|
||||
|
||||
# TRIGGERERING NOTES
|
||||
|
@ -274,7 +295,6 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass
|
|||
@processNote(note, @currentNoteGroup) for note in module.endNotes()
|
||||
Backbone.Mediator.publish 'note-group-ended' unless @quiet
|
||||
@scriptInProgress = false
|
||||
@ended.push(@currentNoteGroup.scriptID) if @currentNoteGroup.isLast
|
||||
@trackScriptCompletions(@currentNoteGroup)
|
||||
@currentNoteGroup = null
|
||||
unless @noteGroupQueue.length
|
||||
|
@ -321,6 +341,10 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass
|
|||
return if @quiet
|
||||
return unless noteGroup.isLast
|
||||
@ended.push(noteGroup.scriptID) unless noteGroup.scriptID in @ended
|
||||
for script in @scripts
|
||||
if script.id is noteGroup.scriptID
|
||||
script.lastEnded = new Date()
|
||||
@lastScriptEnded = new Date()
|
||||
Backbone.Mediator.publish 'script:ended', {scriptID: noteGroup.scriptID}
|
||||
|
||||
notifyScriptStateChanged: ->
|
||||
|
|
|
@ -36,4 +36,4 @@ module.exports = class ScriptModule extends CocoClass
|
|||
Math.max(0, sums...)
|
||||
|
||||
maybeApplyDelayToNote: (note) ->
|
||||
note.delay = @scrubbingTime + @movementTime
|
||||
note.delay = (@scrubbingTime + @movementTime) or 0
|
|
@ -17,6 +17,10 @@ module.exports =
|
|||
response:
|
||||
type: "string"
|
||||
required: ["response"]
|
||||
|
||||
"facebook-logged-out": {}
|
||||
|
||||
"linkedin-loaded": {}
|
||||
|
||||
"gapi-loaded":
|
||||
{} # TODO schema
|
||||
|
|
|
@ -74,9 +74,32 @@ module.exports =
|
|||
"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
|
||||
|
||||
|
@ -114,5 +137,21 @@ module.exports =
|
|||
"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
|
||||
|
|
Loading…
Reference in a new issue