mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-28 01:55:38 -05:00
Refactored dynamic sound loading to the level view, since the level loader is no longer in service after finishing loading.
This commit is contained in:
parent
e85f5c7e6b
commit
86f94cb5fd
2 changed files with 13 additions and 14 deletions
|
@ -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: ->
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue