codecombat/app/lib/scripts/ScriptModule.coffee

39 lines
1,013 B
CoffeeScript
Raw Normal View History

2014-01-03 13:32:13 -05:00
CocoClass = require 'lib/CocoClass'
module.exports = class ScriptModule extends CocoClass
scrubbingTime = 0
movementTime = 0
constructor: (@noteGroup) ->
2014-01-03 13:32:13 -05:00
super()
if not @noteGroup.prepared
@analyzeNoteGroup(noteGroup)
@noteGroup.notes ?= []
@noteGroup.prepared = true
# subclass should overwrite these
@neededFor: -> false
startNotes: -> []
endNotes: -> []
skipNotes: -> @endNotes()
# common logic
analyzeNoteGroup: ->
# some notes need to happen after others. Calculate the delays
@movementTime = @calculateMovementMax(@noteGroup)
@scrubbingTime = @noteGroup.playback?.scrub?.duration or 0
calculateMovementMax: ->
sums = {}
for sprite in @noteGroup.sprites
continue unless sprite.move?
sums[sprite.id] ?= 0
sums[sprite.id] += sprite.move.duration
sums = (sums[k] for k of sums)
Math.max(0, sums...)
maybeApplyDelayToNote: (note) ->
note.delay = (@scrubbingTime + @movementTime) or 0