codecombat/app/lib/scripts/ScriptModule.coffee

40 lines
996 B
CoffeeScript
Raw Normal View History

CocoClass = require 'core/CocoClass'
2014-01-03 13:32:13 -05:00
module.exports = class ScriptModule extends CocoClass
2014-06-30 22:16:26 -04:00
2014-01-03 13:32:13 -05:00
scrubbingTime = 0
movementTime = 0
2014-06-30 22:16:26 -04:00
constructor: (@noteGroup) ->
2014-01-03 13:32:13 -05:00
super()
if not @noteGroup.prepared
@analyzeNoteGroup(@noteGroup)
2014-01-03 13:32:13 -05:00
@noteGroup.notes ?= []
@noteGroup.prepared = true
2014-06-30 22:16:26 -04:00
2014-01-03 13:32:13 -05:00
# subclass should overwrite these
2014-06-30 22:16:26 -04:00
2014-01-03 13:32:13 -05:00
@neededFor: -> false
startNotes: -> []
endNotes: -> []
skipNotes: -> @endNotes()
2014-06-30 22:16:26 -04:00
2014-01-03 13:32:13 -05:00
# common logic
2014-06-30 22:16:26 -04:00
2014-01-03 13:32:13 -05:00
analyzeNoteGroup: ->
# some notes need to happen after others. Calculate the delays
@movementTime = @calculateMovementMax(@noteGroup)
@scrubbingTime = @noteGroup.playback?.scrub?.duration or 0
2014-06-30 22:16:26 -04:00
2014-01-03 13:32:13 -05:00
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) ->
2014-06-30 22:16:26 -04:00
note.delay = (@scrubbingTime + @movementTime) or 0