mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -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]
|
return defaults[message.length % defaults.length]
|
||||||
|
|
||||||
preloadInterfaceSounds: (names) ->
|
preloadInterfaceSounds: (names) ->
|
||||||
|
return unless me.get 'volume'
|
||||||
for name in names
|
for name in names
|
||||||
filename = "/file/interface/#{name}#{@ext}"
|
filename = "/file/interface/#{name}#{@ext}"
|
||||||
@preloadSound filename, name
|
@preloadSound filename, name
|
||||||
|
|
||||||
playInterfaceSound: (name, volume=1) ->
|
playInterfaceSound: (name, volume=1) ->
|
||||||
|
return unless volume and me.get 'volume'
|
||||||
filename = "/file/interface/#{name}#{@ext}"
|
filename = "/file/interface/#{name}#{@ext}"
|
||||||
if @hasLoadedSound filename
|
if @hasLoadedSound filename
|
||||||
@playSound name, volume
|
@playSound name, volume
|
||||||
|
@ -107,6 +109,7 @@ class AudioPlayer extends CocoClass
|
||||||
|
|
||||||
playSound: (name, volume=1, delay=0, pos=null) ->
|
playSound: (name, volume=1, delay=0, pos=null) ->
|
||||||
return console.error 'Trying to play empty sound?' unless name
|
return console.error 'Trying to play empty sound?' unless name
|
||||||
|
return unless volume and me.get 'volume'
|
||||||
audioOptions = {volume: volume, delay: delay}
|
audioOptions = {volume: volume, delay: delay}
|
||||||
filename = if _.string.startsWith(name, '/file/') then name else '/file/' + name
|
filename = if _.string.startsWith(name, '/file/') then name else '/file/' + name
|
||||||
unless @hasLoadedSound filename
|
unless @hasLoadedSound filename
|
||||||
|
@ -120,9 +123,8 @@ class AudioPlayer extends CocoClass
|
||||||
return false unless createjs.Sound.loadComplete filename
|
return false unless createjs.Sound.loadComplete filename
|
||||||
true
|
true
|
||||||
|
|
||||||
# TODO: load Interface sounds somehow, somewhere, somewhen
|
|
||||||
|
|
||||||
preloadSoundReference: (sound) ->
|
preloadSoundReference: (sound) ->
|
||||||
|
return unless me.get 'volume'
|
||||||
return unless name = @nameForSoundReference sound
|
return unless name = @nameForSoundReference sound
|
||||||
filename = '/file/' + name
|
filename = '/file/' + name
|
||||||
@preloadSound filename, name
|
@preloadSound filename, name
|
||||||
|
|
|
@ -418,20 +418,23 @@ module.exports = class LevelLoader extends CocoClass
|
||||||
# Initial Sound Loading
|
# Initial Sound Loading
|
||||||
|
|
||||||
playJingle: ->
|
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.
|
# 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.
|
# Add the timeout to fix this weird behavior.
|
||||||
f = ->
|
f = ->
|
||||||
jingles = ['ident_1', 'ident_2']
|
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
|
setTimeout f, 500
|
||||||
|
|
||||||
loadAudio: ->
|
loadAudio: ->
|
||||||
return if @headless
|
return if @headless or not me.get('volume')
|
||||||
AudioPlayer.preloadInterfaceSounds ['victory']
|
AudioPlayer.preloadInterfaceSounds ['victory']
|
||||||
|
|
||||||
loadLevelSounds: ->
|
loadLevelSounds: ->
|
||||||
return if @headless
|
return if @headless or not me.get('volume')
|
||||||
scripts = @level.get 'scripts'
|
scripts = @level.get 'scripts'
|
||||||
return unless scripts
|
return unless scripts
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ module.exports = class MusicPlayer extends CocoClass
|
||||||
'playback:real-time-playback-ended': 'onRealTimePlaybackEnded'
|
'playback:real-time-playback-ended': 'onRealTimePlaybackEnded'
|
||||||
'music-player:enter-menu': 'onEnterMenu'
|
'music-player:enter-menu': 'onEnterMenu'
|
||||||
'music-player:exit-menu': 'onExitMenu'
|
'music-player:exit-menu': 'onExitMenu'
|
||||||
|
'level:set-volume': 'onSetVolume'
|
||||||
|
|
||||||
constructor: ->
|
constructor: ->
|
||||||
super arguments...
|
super arguments...
|
||||||
|
@ -26,6 +27,9 @@ module.exports = class MusicPlayer extends CocoClass
|
||||||
|
|
||||||
onPlayMusic: (e) ->
|
onPlayMusic: (e) ->
|
||||||
return if application.isIPadApp # Hard to measure, but just guessing this will save memory.
|
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 = e.file
|
||||||
src = "/file#{src}#{AudioPlayer.ext}"
|
src = "/file#{src}#{AudioPlayer.ext}"
|
||||||
if (not e.file) or src is @currentMusic?.src
|
if (not e.file) or src is @currentMusic?.src
|
||||||
|
@ -97,6 +101,11 @@ module.exports = class MusicPlayer extends CocoClass
|
||||||
@currentMusic = @previousMusic
|
@currentMusic = @previousMusic
|
||||||
@restartCurrentMusic()
|
@restartCurrentMusic()
|
||||||
|
|
||||||
|
onSetVolume: (e) ->
|
||||||
|
return unless e.volume and @lastMusicEventIgnoredWhileMuted
|
||||||
|
@onPlayMusic @lastMusicEventIgnoredWhileMuted
|
||||||
|
@lastMusicEventIgnoredWhileMuted = null
|
||||||
|
|
||||||
destroy: ->
|
destroy: ->
|
||||||
me.off 'change:music', @onMusicSettingChanged, @
|
me.off 'change:music', @onMusicSettingChanged, @
|
||||||
@fadeOutCurrentMusic()
|
@fadeOutCurrentMusic()
|
||||||
|
|
|
@ -49,7 +49,6 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
navigateToSelection: true
|
navigateToSelection: true
|
||||||
choosing: false # 'point', 'region', 'ratio-region'
|
choosing: false # 'point', 'region', 'ratio-region'
|
||||||
coords: null # use world defaults, or set to false/true to override
|
coords: null # use world defaults, or set to false/true to override
|
||||||
playJingle: false
|
|
||||||
showInvisible: false
|
showInvisible: false
|
||||||
frameRate: 30 # Best as a divisor of 60, like 15, 30, 60, with RAF_SYNCHED timing.
|
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: ->
|
initSurface: ->
|
||||||
webGLSurface = $('canvas#webgl-surface', @$el)
|
webGLSurface = $('canvas#webgl-surface', @$el)
|
||||||
normalSurface = $('canvas#normal-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()
|
worldBounds = @world.getBounds()
|
||||||
bounds = [{x:worldBounds.left, y:worldBounds.top}, {x:worldBounds.right, y:worldBounds.bottom}]
|
bounds = [{x:worldBounds.left, y:worldBounds.top}, {x:worldBounds.right, y:worldBounds.bottom}]
|
||||||
@surface.camera.setBounds(bounds)
|
@surface.camera.setBounds(bounds)
|
||||||
|
|
|
@ -50,7 +50,7 @@ module.exports = class PlayLevelView extends RootView
|
||||||
isEditorPreview: false
|
isEditorPreview: false
|
||||||
|
|
||||||
subscriptions:
|
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:show-victory': 'onShowVictory'
|
||||||
'level:restart': 'onRestartLevel'
|
'level:restart': 'onRestartLevel'
|
||||||
'level:highlight-dom': 'onHighlightDOM'
|
'level:highlight-dom': 'onHighlightDOM'
|
||||||
|
@ -324,7 +324,7 @@ module.exports = class PlayLevelView extends RootView
|
||||||
initSurface: ->
|
initSurface: ->
|
||||||
webGLSurface = $('canvas#webgl-surface', @$el)
|
webGLSurface = $('canvas#webgl-surface', @$el)
|
||||||
normalSurface = $('canvas#normal-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()
|
worldBounds = @world.getBounds()
|
||||||
bounds = [{x: worldBounds.left, y: worldBounds.top}, {x: worldBounds.right, y: worldBounds.bottom}]
|
bounds = [{x: worldBounds.left, y: worldBounds.top}, {x: worldBounds.right, y: worldBounds.bottom}]
|
||||||
@surface.camera.setBounds(bounds)
|
@surface.camera.setBounds(bounds)
|
||||||
|
@ -370,9 +370,15 @@ module.exports = class PlayLevelView extends RootView
|
||||||
$(window).trigger 'resize'
|
$(window).trigger 'resize'
|
||||||
_.delay (=> @perhapsStartSimulating?()), 10 * 1000
|
_.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: ->
|
playAmbientSound: ->
|
||||||
return if @destroyed
|
return if @destroyed
|
||||||
return if @ambientSound
|
return if @ambientSound
|
||||||
|
return unless me.get 'volume'
|
||||||
return unless file = {Dungeon: 'ambient-dungeon', Grass: 'ambient-grass'}[@level.get('terrain')]
|
return unless file = {Dungeon: 'ambient-dungeon', Grass: 'ambient-grass'}[@level.get('terrain')]
|
||||||
src = "/file/interface/#{file}#{AudioPlayer.ext}"
|
src = "/file/interface/#{file}#{AudioPlayer.ext}"
|
||||||
unless AudioPlayer.getStatus(src)?.loaded
|
unless AudioPlayer.getStatus(src)?.loaded
|
||||||
|
|
Loading…
Reference in a new issue