mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-24 08:08:15 -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
|
spriteSheetsBuilt: 0
|
||||||
spriteSheetsToBuild: 0
|
spriteSheetsToBuild: 0
|
||||||
|
|
||||||
subscriptions:
|
|
||||||
'god:new-world-created': 'loadSoundsForWorld'
|
|
||||||
|
|
||||||
constructor: (options) ->
|
constructor: (options) ->
|
||||||
super()
|
super()
|
||||||
@supermodel = options.supermodel
|
@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'
|
for trigger, sounds of thangType.get('soundTriggers') or {} when trigger isnt 'say'
|
||||||
AudioPlayer.preloadSoundReference sound for sound in sounds
|
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
|
# everything else sound wise is loaded as needed as worlds are generated
|
||||||
|
|
||||||
allDone: ->
|
allDone: ->
|
||||||
|
|
|
@ -17,6 +17,7 @@ LevelSession = require 'models/LevelSession'
|
||||||
Level = require 'models/Level'
|
Level = require 'models/Level'
|
||||||
LevelComponent = require 'models/LevelComponent'
|
LevelComponent = require 'models/LevelComponent'
|
||||||
Camera = require 'lib/surface/Camera'
|
Camera = require 'lib/surface/Camera'
|
||||||
|
AudioPlayer = require 'lib/AudioPlayer'
|
||||||
|
|
||||||
# subviews
|
# subviews
|
||||||
TomeView = require './level/tome/tome_view'
|
TomeView = require './level/tome/tome_view'
|
||||||
|
@ -58,6 +59,7 @@ module.exports = class PlayLevelView extends View
|
||||||
'surface:world-set-up': 'onSurfaceSetUpNewWorld'
|
'surface:world-set-up': 'onSurfaceSetUpNewWorld'
|
||||||
'level:session-will-save': 'onSessionWillSave'
|
'level:session-will-save': 'onSessionWillSave'
|
||||||
'level:set-team': 'setTeam'
|
'level:set-team': 'setTeam'
|
||||||
|
'god:new-world-created': 'loadSoundsForWorld'
|
||||||
|
|
||||||
events:
|
events:
|
||||||
'click #level-done-button': 'onDonePressed'
|
'click #level-done-button': 'onDonePressed'
|
||||||
|
@ -393,6 +395,17 @@ module.exports = class PlayLevelView extends View
|
||||||
me.team = team
|
me.team = team
|
||||||
Backbone.Mediator.publish 'level:team-set', 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: ->
|
destroy: ->
|
||||||
@supermodel.off 'error', @onLevelLoadError
|
@supermodel.off 'error', @onLevelLoadError
|
||||||
@levelLoader?.off 'loaded-all', @onLevelLoaderLoaded
|
@levelLoader?.off 'loaded-all', @onLevelLoaderLoaded
|
||||||
|
|
Loading…
Reference in a new issue