This repository has been archived on 2025-05-04. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
codecombat/app/lib/scripts/ScriptModule.coffee

39 lines
1,020 B
CoffeeScript
Raw Normal View History

2014-01-03 10:32:13 -08:00
CocoClass = require 'lib/CocoClass'
module.exports = class ScriptModule extends CocoClass
scrubbingTime = 0
movementTime = 0
constructor: (@noteGroup, @view) ->
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