Skip to content

Commit

Permalink
Some remaining work to get the delayed show guide script set up.
Browse files Browse the repository at this point in the history
  • Loading branch information
sderickson committed May 21, 2014
1 parent 4929f81 commit 037dbe9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
37 changes: 22 additions & 15 deletions app/lib/scripts/ScriptManager.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass
@initProperties()
@loadFromSession()
@quiet = false
@addScriptSubscriptions()
@run()

initProperties: ->
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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()

Expand All @@ -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) ->
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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()
Expand All @@ -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 = []

Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions app/models/SuperModel.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
5 changes: 3 additions & 2 deletions app/schemas/subscriptions/play.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/views/play/level/modal/docs_modal.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit 037dbe9

Please sign in to comment.