diff --git a/app/lib/AudioPlayer.coffee b/app/lib/AudioPlayer.coffee index 3a0abfb34..b9e2d3f55 100644 --- a/app/lib/AudioPlayer.coffee +++ b/app/lib/AudioPlayer.coffee @@ -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 diff --git a/app/lib/LevelLoader.coffee b/app/lib/LevelLoader.coffee index d3b78f1f4..84ed7fe45 100644 --- a/app/lib/LevelLoader.coffee +++ b/app/lib/LevelLoader.coffee @@ -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 diff --git a/app/lib/surface/MusicPlayer.coffee b/app/lib/surface/MusicPlayer.coffee index b218ea05b..2a3443644 100644 --- a/app/lib/surface/MusicPlayer.coffee +++ b/app/lib/surface/MusicPlayer.coffee @@ -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() diff --git a/app/lib/surface/Surface.coffee b/app/lib/surface/Surface.coffee index 974767b2f..d9a8943b1 100644 --- a/app/lib/surface/Surface.coffee +++ b/app/lib/surface/Surface.coffee @@ -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. diff --git a/app/views/play/SpectateView.coffee b/app/views/play/SpectateView.coffee index 309e1a03d..7ebe8332a 100644 --- a/app/views/play/SpectateView.coffee +++ b/app/views/play/SpectateView.coffee @@ -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) diff --git a/app/views/play/level/PlayLevelView.coffee b/app/views/play/level/PlayLevelView.coffee index b32c6e6d1..52fef8a94 100644 --- a/app/views/play/level/PlayLevelView.coffee +++ b/app/views/play/level/PlayLevelView.coffee @@ -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