Some remaining work to get the delayed show guide script set up.

This commit is contained in:
Scott Erickson 2014-05-21 14:50:27 -07:00
parent 4929f81fcc
commit 037dbe97c6
4 changed files with 39 additions and 17 deletions

View file

@ -59,6 +59,7 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass
@initProperties()
@loadFromSession()
@quiet = false
@addScriptSubscriptions()
@run()
initProperties: ->
@ -108,6 +109,7 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass
return unless script
@triggered.push(script.id)
noteChain = @processScript(script)
return unless noteChain
if scripts.currentScriptOffset
noteGroup.skipMe = true for noteGroup in noteChain[..scripts.currentScriptOffset-1]
@addNoteChain(noteChain, false)
@ -127,6 +129,7 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass
@triggered.push(scriptID)
@ended.push(scriptID)
noteChain = @processScript(script)
return unless noteChain
noteGroup.skipMe = true for noteGroup in noteChain
@addNoteChain(noteChain, false)
@ -168,10 +171,11 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass
continue unless @scriptPrereqsSatisfied(script)
continue unless scriptMatchesEventPrereqs(script, event)
# everything passed!
console.log "SCRIPT: Running script '#{script.id}'" if @debugScripts
console.debug "SCRIPT: Running script '#{script.id}'" if @debugScripts
script.lastTriggered = new Date().getTime()
@triggered.push(script.id) unless alreadyTriggered
noteChain = @processScript(script)
if not noteChain then return @trackScriptCompletions (script.id)
@addNoteChain(noteChain)
@run()
@ -180,10 +184,10 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass
processScript: (script) ->
noteChain = script.noteChain
return null unless noteChain?.length
noteGroup.scriptID = script.id for noteGroup in noteChain
if noteChain.length
lastNoteGroup = noteChain[noteChain.length - 1]
lastNoteGroup.isLast = true
lastNoteGroup = noteChain[noteChain.length - 1]
lastNoteGroup.isLast = true
return noteChain
addNoteChain: (noteChain, clearYields=true) ->
@ -228,7 +232,7 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass
@notifyScriptStateChanged()
@scriptInProgress = true
@currentTimeouts = []
console.log "SCRIPT: Starting note group '#{nextNoteGroup.name}'" if @debugScripts
console.debug "SCRIPT: Starting note group '#{nextNoteGroup.name}'" if @debugScripts
for module in nextNoteGroup.modules
@processNote(note, nextNoteGroup) for note in module.startNotes()
if nextNoteGroup.script.duration
@ -242,12 +246,12 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass
@ignoreEvents = true
for noteGroup, i in @noteGroupQueue
break unless noteGroup.skipMe
console.log "SCRIPT: Skipping note group '#{noteGroup.name}'" if @debugScripts
console.debug "SCRIPT: Skipping note group '#{noteGroup.name}'" if @debugScripts
@processNoteGroup(noteGroup)
for module in noteGroup.modules
notes = module.skipNotes()
@processNote(note, noteGroup) for note in notes
@trackScriptCompletions(noteGroup)
@trackScriptCompletionsFromNoteGroup(noteGroup)
@noteGroupQueue = @noteGroupQueue[i..]
@ignoreEvents = false
@ -289,13 +293,13 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass
return if @ending # kill infinite loops right here
@ending = true
return unless @currentNoteGroup?
console.log "SCRIPT: Ending note group '#{@currentNoteGroup.name}'" if @debugScripts
console.debug "SCRIPT: Ending note group '#{@currentNoteGroup.name}'" if @debugScripts
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
@scriptInProgress = false
@trackScriptCompletions(@currentNoteGroup)
@trackScriptCompletionsFromNoteGroup(@currentNoteGroup)
@currentNoteGroup = null
unless @noteGroupQueue.length
@notifyScriptStateChanged()
@ -322,7 +326,7 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass
for module in noteGroup.modules
notes = module.skipNotes()
@processNote(note, noteGroup) for note in notes unless @quiet
@trackScriptCompletions(noteGroup) unless @quiet
@trackScriptCompletionsFromNoteGroup(noteGroup) unless @quiet
@noteGroupQueue = []
@ -337,15 +341,18 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass
Backbone.Mediator.publish 'level-enable-controls', {}
Backbone.Mediator.publish 'level-set-letterbox', { on: false }
trackScriptCompletions: (noteGroup) ->
return if @quiet
trackScriptCompletionsFromNoteGroup: (noteGroup) ->
return unless noteGroup.isLast
@ended.push(noteGroup.scriptID) unless noteGroup.scriptID in @ended
@trackScriptCompletions(noteGroup.scriptID)
trackScriptCompletions: (scriptID) ->
return if @quiet
@ended.push(scriptID) unless scriptID in @ended
for script in @scripts
if script.id is noteGroup.scriptID
if script.id is scriptID
script.lastEnded = new Date()
@lastScriptEnded = new Date()
Backbone.Mediator.publish 'script:ended', {scriptID: noteGroup.scriptID}
Backbone.Mediator.publish 'script:ended', {scriptID: scriptID}
notifyScriptStateChanged: ->
return if @quiet

View file

@ -16,6 +16,16 @@ module.exports = class SuperModel extends Backbone.Model
# retries, progress, and filling the cache. Note that the resource it passes back will not
# necessarily have the same model or collection that was passed in, if it was fetched from
# the cache.
report: ->
# Useful for debugging why a SuperModel never finishes loading.
console.info "SuperModel report ------------------------"
console.info "#{_.values(@resources).length} resources."
unfinished = []
for resource in _.values(@resources)
console.info '\t', resource.name, "loaded", resource.isLoaded
unfinished.push resource unless resource.isLoaded
unfinished
loadModel: (model, name, fetchOptions, value=1) ->
cachedModel = @getModelByURL(model.getURL())

View file

@ -53,8 +53,9 @@ module.exports =
"level:team-set":
{} # TODO schema
"level:docs-hidden":
{} # TODO schema
"level:docs-shown": {}
"level:docs-hidden": {}
"level:victory-hidden":
{} # TODO schema

View file

@ -49,6 +49,10 @@ module.exports = class DocsModal extends View
clickTab: (e) =>
@$el.find('li.active').removeClass('active')
afterInsert: ->
super()
Backbone.Mediator.publish 'level:docs-shown'
onHidden: ->
Backbone.Mediator.publish 'level:docs-hidden'