mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 15:48:11 -05:00
Don't load sounds from level while muted
This commit is contained in:
parent
95c703a7df
commit
ee6be55a9d
6 changed files with 29 additions and 10 deletions
|
@ -93,11 +93,13 @@ class AudioPlayer extends CocoClass
|
|||
return defaults[message.length % defaults.length]
|
||||
|
||||
preloadInterfaceSounds: (names) ->
|
||||
return unless me.get 'volume'
|
||||
for name in names
|
||||
filename = "/file/interface/#{name}#{@ext}"
|
||||
@preloadSound filename, name
|
||||
|
||||
playInterfaceSound: (name, volume=1) ->
|
||||
return unless volume and me.get 'volume'
|
||||
filename = "/file/interface/#{name}#{@ext}"
|
||||
if @hasLoadedSound filename
|
||||
@playSound name, volume
|
||||
|
@ -107,6 +109,7 @@ class AudioPlayer extends CocoClass
|
|||
|
||||
playSound: (name, volume=1, delay=0, pos=null) ->
|
||||
return console.error 'Trying to play empty sound?' unless name
|
||||
return unless volume and me.get 'volume'
|
||||
audioOptions = {volume: volume, delay: delay}
|
||||
filename = if _.string.startsWith(name, '/file/') then name else '/file/' + name
|
||||
unless @hasLoadedSound filename
|
||||
|
@ -120,9 +123,8 @@ class AudioPlayer extends CocoClass
|
|||
return false unless createjs.Sound.loadComplete filename
|
||||
true
|
||||
|
||||
# TODO: load Interface sounds somehow, somewhere, somewhen
|
||||
|
||||
preloadSoundReference: (sound) ->
|
||||
return unless me.get 'volume'
|
||||
return unless name = @nameForSoundReference sound
|
||||
filename = '/file/' + name
|
||||
@preloadSound filename, name
|
||||
|
|
|
@ -418,20 +418,23 @@ module.exports = class LevelLoader extends CocoClass
|
|||
# Initial Sound Loading
|
||||
|
||||
playJingle: ->
|
||||
return if @headless
|
||||
return if @headless or not me.get('volume')
|
||||
volume = 0.5
|
||||
if me.level() < 3
|
||||
volume = 0.25 # Start softly, since they may not be expecting it
|
||||
# Apparently the jingle, when it tries to play immediately during all this loading, you can't hear it.
|
||||
# Add the timeout to fix this weird behavior.
|
||||
f = ->
|
||||
jingles = ['ident_1', 'ident_2']
|
||||
AudioPlayer.playInterfaceSound jingles[Math.floor Math.random() * jingles.length]
|
||||
AudioPlayer.playInterfaceSound jingles[Math.floor Math.random() * jingles.length], volume
|
||||
setTimeout f, 500
|
||||
|
||||
loadAudio: ->
|
||||
return if @headless
|
||||
return if @headless or not me.get('volume')
|
||||
AudioPlayer.preloadInterfaceSounds ['victory']
|
||||
|
||||
loadLevelSounds: ->
|
||||
return if @headless
|
||||
return if @headless or not me.get('volume')
|
||||
scripts = @level.get 'scripts'
|
||||
return unless scripts
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ module.exports = class MusicPlayer extends CocoClass
|
|||
'playback:real-time-playback-ended': 'onRealTimePlaybackEnded'
|
||||
'music-player:enter-menu': 'onEnterMenu'
|
||||
'music-player:exit-menu': 'onExitMenu'
|
||||
'level:set-volume': 'onSetVolume'
|
||||
|
||||
constructor: ->
|
||||
super arguments...
|
||||
|
@ -26,6 +27,9 @@ module.exports = class MusicPlayer extends CocoClass
|
|||
|
||||
onPlayMusic: (e) ->
|
||||
return if application.isIPadApp # Hard to measure, but just guessing this will save memory.
|
||||
unless me.get 'volume'
|
||||
@lastMusicEventIgnoredWhileMuted = e
|
||||
return
|
||||
src = e.file
|
||||
src = "/file#{src}#{AudioPlayer.ext}"
|
||||
if (not e.file) or src is @currentMusic?.src
|
||||
|
@ -97,6 +101,11 @@ module.exports = class MusicPlayer extends CocoClass
|
|||
@currentMusic = @previousMusic
|
||||
@restartCurrentMusic()
|
||||
|
||||
onSetVolume: (e) ->
|
||||
return unless e.volume and @lastMusicEventIgnoredWhileMuted
|
||||
@onPlayMusic @lastMusicEventIgnoredWhileMuted
|
||||
@lastMusicEventIgnoredWhileMuted = null
|
||||
|
||||
destroy: ->
|
||||
me.off 'change:music', @onMusicSettingChanged, @
|
||||
@fadeOutCurrentMusic()
|
||||
|
|
|
@ -49,7 +49,6 @@ module.exports = Surface = class Surface extends CocoClass
|
|||
navigateToSelection: true
|
||||
choosing: false # 'point', 'region', 'ratio-region'
|
||||
coords: null # use world defaults, or set to false/true to override
|
||||
playJingle: false
|
||||
showInvisible: false
|
||||
frameRate: 30 # Best as a divisor of 60, like 15, 30, 60, with RAF_SYNCHED timing.
|
||||
|
||||
|
|
|
@ -196,7 +196,7 @@ module.exports = class SpectateLevelView extends RootView
|
|||
initSurface: ->
|
||||
webGLSurface = $('canvas#webgl-surface', @$el)
|
||||
normalSurface = $('canvas#normal-surface', @$el)
|
||||
@surface = new Surface @world, normalSurface, webGLSurface, thangTypes: @supermodel.getModels(ThangType), playJingle: not @isEditorPreview, spectateGame: true, playerNames: @findPlayerNames()
|
||||
@surface = new Surface @world, normalSurface, webGLSurface, thangTypes: @supermodel.getModels(ThangType), spectateGame: true, playerNames: @findPlayerNames()
|
||||
worldBounds = @world.getBounds()
|
||||
bounds = [{x:worldBounds.left, y:worldBounds.top}, {x:worldBounds.right, y:worldBounds.bottom}]
|
||||
@surface.camera.setBounds(bounds)
|
||||
|
|
|
@ -50,7 +50,7 @@ module.exports = class PlayLevelView extends RootView
|
|||
isEditorPreview: false
|
||||
|
||||
subscriptions:
|
||||
'level:set-volume': (e) -> createjs.Sound.setVolume(if e.volume is 1 then 0.6 else e.volume) # Quieter for now until individual sound FX controls work again.
|
||||
'level:set-volume': 'onSetVolume'
|
||||
'level:show-victory': 'onShowVictory'
|
||||
'level:restart': 'onRestartLevel'
|
||||
'level:highlight-dom': 'onHighlightDOM'
|
||||
|
@ -324,7 +324,7 @@ module.exports = class PlayLevelView extends RootView
|
|||
initSurface: ->
|
||||
webGLSurface = $('canvas#webgl-surface', @$el)
|
||||
normalSurface = $('canvas#normal-surface', @$el)
|
||||
@surface = new Surface(@world, normalSurface, webGLSurface, thangTypes: @supermodel.getModels(ThangType), playJingle: not @isEditorPreview, observing: @observing, playerNames: @findPlayerNames())
|
||||
@surface = new Surface(@world, normalSurface, webGLSurface, thangTypes: @supermodel.getModels(ThangType), observing: @observing, playerNames: @findPlayerNames())
|
||||
worldBounds = @world.getBounds()
|
||||
bounds = [{x: worldBounds.left, y: worldBounds.top}, {x: worldBounds.right, y: worldBounds.bottom}]
|
||||
@surface.camera.setBounds(bounds)
|
||||
|
@ -370,9 +370,15 @@ module.exports = class PlayLevelView extends RootView
|
|||
$(window).trigger 'resize'
|
||||
_.delay (=> @perhapsStartSimulating?()), 10 * 1000
|
||||
|
||||
onSetVolume: (e) ->
|
||||
createjs.Sound.setVolume(if e.volume is 1 then 0.6 else e.volume) # Quieter for now until individual sound FX controls work again.
|
||||
if e.volume and not @ambientSound
|
||||
@playAmbientSound()
|
||||
|
||||
playAmbientSound: ->
|
||||
return if @destroyed
|
||||
return if @ambientSound
|
||||
return unless me.get 'volume'
|
||||
return unless file = {Dungeon: 'ambient-dungeon', Grass: 'ambient-grass'}[@level.get('terrain')]
|
||||
src = "/file/interface/#{file}#{AudioPlayer.ext}"
|
||||
unless AudioPlayer.getStatus(src)?.loaded
|
||||
|
|
Loading…
Reference in a new issue