2014-01-03 13:32:13 -05:00
|
|
|
ScriptModule = require './ScriptModule'
|
2014-11-28 20:49:41 -05:00
|
|
|
{me} = require 'core/auth'
|
|
|
|
utils = require 'core/utils'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
module.exports = class SpritesScriptModule extends ScriptModule
|
|
|
|
@neededFor: (noteGroup) ->
|
|
|
|
return noteGroup.sprites?.length
|
|
|
|
|
|
|
|
startNotes: ->
|
|
|
|
notes = []
|
|
|
|
@moveSums = {}
|
|
|
|
@speakingSprites = {}
|
|
|
|
for sprite in @noteGroup.sprites or []
|
|
|
|
notes.push(@spriteMoveNote sprite) if sprite.move?
|
|
|
|
for sprite in @noteGroup.sprites or []
|
|
|
|
notes.push(@spriteSayNote(sprite, @noteGroup.script)) if sprite.say?
|
|
|
|
notes.push(@spriteSelectNote sprite) if sprite.select?
|
|
|
|
return (n for n in notes when n)
|
|
|
|
|
|
|
|
spriteMoveNote: (sprite, instant=false) ->
|
|
|
|
duration = if instant then 0 else sprite.move.duration
|
|
|
|
note =
|
2014-08-27 15:24:03 -04:00
|
|
|
channel: 'sprite:move'
|
2014-01-03 13:32:13 -05:00
|
|
|
event:
|
|
|
|
pos: sprite.move.target
|
|
|
|
duration: duration
|
|
|
|
spriteID: sprite.id
|
|
|
|
if duration
|
|
|
|
@moveSums[sprite.id] ?= 0
|
|
|
|
note.delay = @scrubbingTime + @moveSums[sprite.id]
|
|
|
|
@moveSums[sprite.id] += sprite.move.duration
|
|
|
|
return note
|
|
|
|
|
|
|
|
spriteSayNote: (sprite, script) ->
|
|
|
|
return if @speakingSprites[sprite.id]
|
|
|
|
responses = sprite.say.responses
|
2014-02-25 16:27:02 -05:00
|
|
|
responses = [] unless script.skippable or responses
|
2014-01-03 13:32:13 -05:00
|
|
|
for response in responses ? []
|
2014-03-13 12:02:19 -04:00
|
|
|
response.text = utils.i18n response, 'text'
|
|
|
|
text = utils.i18n sprite.say, 'text'
|
|
|
|
blurb = utils.i18n sprite.say, 'blurb'
|
2014-10-29 13:38:01 -04:00
|
|
|
sound = utils.i18n sprite.say, 'sound'
|
2014-01-03 13:32:13 -05:00
|
|
|
note =
|
2014-08-27 15:24:03 -04:00
|
|
|
channel: 'level:sprite-dialogue'
|
2014-01-03 13:32:13 -05:00
|
|
|
event:
|
|
|
|
message: text
|
|
|
|
blurb: blurb
|
2014-06-30 22:16:26 -04:00
|
|
|
mood: sprite.say.mood or 'explain'
|
2014-01-03 13:32:13 -05:00
|
|
|
responses: responses
|
|
|
|
spriteID: sprite.id
|
|
|
|
sound: sound
|
|
|
|
@maybeApplyDelayToNote note
|
|
|
|
return note
|
|
|
|
|
|
|
|
spriteSelectNote: (sprite) ->
|
|
|
|
note =
|
2014-08-27 15:24:03 -04:00
|
|
|
channel: 'level:select-sprite'
|
2014-01-03 13:32:13 -05:00
|
|
|
event:
|
|
|
|
thangID: if sprite.select then sprite.id else null
|
|
|
|
return note
|
|
|
|
|
|
|
|
endNotes: ->
|
|
|
|
notes = {}
|
|
|
|
for sprite in @noteGroup.sprites or []
|
|
|
|
notes[sprite.id] ?= {}
|
|
|
|
notes[sprite.id]['move'] = (@spriteMoveNote sprite, true) if sprite.move?
|
2014-08-27 15:24:03 -04:00
|
|
|
notes[sprite.id]['say'] = { channel: 'level:sprite-clear-dialogue' } if sprite.say?
|
2014-01-03 13:32:13 -05:00
|
|
|
noteArray = []
|
|
|
|
for spriteID of notes
|
|
|
|
for type of notes[spriteID]
|
|
|
|
noteArray.push(notes[spriteID][type])
|
|
|
|
noteArray
|