diff --git a/app/lib/LevelLoader.coffee b/app/lib/LevelLoader.coffee index e655aa7b1..873da7d48 100644 --- a/app/lib/LevelLoader.coffee +++ b/app/lib/LevelLoader.coffee @@ -19,9 +19,6 @@ module.exports = class LevelLoader extends CocoClass spriteSheetsBuilt: 0 spriteSheetsToBuild: 0 - subscriptions: - 'god:new-world-created': 'loadSoundsForWorld' - constructor: (options) -> super() @supermodel = options.supermodel @@ -196,17 +193,6 @@ module.exports = class LevelLoader extends CocoClass for trigger, sounds of thangType.get('soundTriggers') or {} when trigger isnt 'say' AudioPlayer.preloadSoundReference sound for sound in sounds - # Dynamic sound loading - - loadSoundsForWorld: (e) -> - return if @headless - world = e.world - thangTypes = @supermodel.getModels(ThangType) - for [spriteName, message] in world.thangDialogueSounds() - continue unless thangType = _.find thangTypes, (m) -> m.get('name') is spriteName - continue unless sound = AudioPlayer.soundForDialogue message, thangType.get('soundTriggers') - filename = AudioPlayer.preloadSoundReference sound - # everything else sound wise is loaded as needed as worlds are generated allDone: -> diff --git a/app/views/play/level_view.coffee b/app/views/play/level_view.coffee index edb2af452..032e2027f 100644 --- a/app/views/play/level_view.coffee +++ b/app/views/play/level_view.coffee @@ -17,6 +17,7 @@ LevelSession = require 'models/LevelSession' Level = require 'models/Level' LevelComponent = require 'models/LevelComponent' Camera = require 'lib/surface/Camera' +AudioPlayer = require 'lib/AudioPlayer' # subviews TomeView = require './level/tome/tome_view' @@ -58,6 +59,7 @@ module.exports = class PlayLevelView extends View 'surface:world-set-up': 'onSurfaceSetUpNewWorld' 'level:session-will-save': 'onSessionWillSave' 'level:set-team': 'setTeam' + 'god:new-world-created': 'loadSoundsForWorld' events: 'click #level-done-button': 'onDonePressed' @@ -393,6 +395,17 @@ module.exports = class PlayLevelView extends View me.team = team Backbone.Mediator.publish 'level:team-set', team: team + # Dynamic sound loading + + loadSoundsForWorld: (e) -> + return if @headless + world = e.world + thangTypes = @supermodel.getModels(ThangType) + for [spriteName, message] in world.thangDialogueSounds() + continue unless thangType = _.find thangTypes, (m) -> m.get('name') is spriteName + continue unless sound = AudioPlayer.soundForDialogue message, thangType.get('soundTriggers') + AudioPlayer.preloadSoundReference sound + destroy: -> @supermodel.off 'error', @onLevelLoadError @levelLoader?.off 'loaded-all', @onLevelLoaderLoaded