From ae5182be7d0cde6f31a34e8fdc4dc3b1c135d24d Mon Sep 17 00:00:00 2001 From: samme Date: Thu, 10 Sep 2020 09:22:44 -0700 Subject: [PATCH] Default Phaser.Core.Config#audio; and refactor --- src/core/Config.js | 2 +- src/core/DebugHeader.js | 4 ++-- src/loader/filetypes/AudioFile.js | 4 ++-- src/sound/SoundManagerCreator.js | 6 +++--- src/sound/webaudio/WebAudioSoundManager.js | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/core/Config.js b/src/core/Config.js index 7c8388f6c..daeb3c278 100644 --- a/src/core/Config.js +++ b/src/core/Config.js @@ -293,7 +293,7 @@ var Config = new Class({ /** * @const {Phaser.Types.Core.AudioConfig} Phaser.Core.Config#audio - The Audio Configuration object. */ - this.audio = GetValue(config, 'audio'); + this.audio = GetValue(config, 'audio', {}); // If you do: { banner: false } it won't display any banner at all diff --git a/src/core/DebugHeader.js b/src/core/DebugHeader.js index 6b73761c0..8ecc2f315 100644 --- a/src/core/DebugHeader.js +++ b/src/core/DebugHeader.js @@ -41,11 +41,11 @@ var DebugHeader = function (game) var audioType; - if (deviceAudio.webAudio && !(audioConfig && audioConfig.disableWebAudio)) + if (deviceAudio.webAudio && !audioConfig.disableWebAudio) { audioType = 'Web Audio'; } - else if ((audioConfig && audioConfig.noAudio) || (!deviceAudio.webAudio && !deviceAudio.audioData)) + else if (audioConfig.noAudio || (!deviceAudio.webAudio && !deviceAudio.audioData)) { audioType = 'No Audio'; } diff --git a/src/loader/filetypes/AudioFile.js b/src/loader/filetypes/AudioFile.js index ea49c1e4a..fe1f8e41a 100644 --- a/src/loader/filetypes/AudioFile.js +++ b/src/loader/filetypes/AudioFile.js @@ -122,7 +122,7 @@ AudioFile.create = function (loader, key, urls, config, xhrSettings) // https://developers.google.com/web/updates/2012/02/HTML5-audio-and-the-Web-Audio-API-are-BFFs // var stream = GetFastValue(config, 'stream', false); - if (deviceAudio.webAudio && !(audioConfig && audioConfig.disableWebAudio)) + if (deviceAudio.webAudio && !audioConfig.disableWebAudio) { return new AudioFile(loader, key, urlConfig, xhrSettings, game.sound.context); } @@ -231,7 +231,7 @@ FileTypesManager.register('audio', function (key, urls, config, xhrSettings) var audioConfig = game.config.audio; var deviceAudio = game.device.audio; - if ((audioConfig && audioConfig.noAudio) || (!deviceAudio.webAudio && !deviceAudio.audioData)) + if (audioConfig.noAudio || (!deviceAudio.webAudio && !deviceAudio.audioData)) { // Sounds are disabled, so skip loading audio return this; diff --git a/src/sound/SoundManagerCreator.js b/src/sound/SoundManagerCreator.js index 46c5ec590..fc69d3a42 100644 --- a/src/sound/SoundManagerCreator.js +++ b/src/sound/SoundManagerCreator.js @@ -18,7 +18,7 @@ var WebAudioSoundManager = require('./webaudio/WebAudioSoundManager'); * @since 3.0.0 * * @param {Phaser.Game} game - Reference to the current game instance. - * + * * @return {(Phaser.Sound.HTML5AudioSoundManager|Phaser.Sound.WebAudioSoundManager|Phaser.Sound.NoAudioSoundManager)} The Sound Manager instance that was created. */ var SoundManagerCreator = { @@ -28,12 +28,12 @@ var SoundManagerCreator = { var audioConfig = game.config.audio; var deviceAudio = game.device.audio; - if ((audioConfig && audioConfig.noAudio) || (!deviceAudio.webAudio && !deviceAudio.audioData)) + if (audioConfig.noAudio || (!deviceAudio.webAudio && !deviceAudio.audioData)) { return new NoAudioSoundManager(game); } - if (deviceAudio.webAudio && !(audioConfig && audioConfig.disableWebAudio)) + if (deviceAudio.webAudio && !audioConfig.disableWebAudio) { return new WebAudioSoundManager(game); } diff --git a/src/sound/webaudio/WebAudioSoundManager.js b/src/sound/webaudio/WebAudioSoundManager.js index f564a6fb2..a4b2ad99f 100644 --- a/src/sound/webaudio/WebAudioSoundManager.js +++ b/src/sound/webaudio/WebAudioSoundManager.js @@ -108,7 +108,7 @@ var WebAudioSoundManager = new Class({ { var audioConfig = game.config.audio; - if (audioConfig && audioConfig.context) + if (audioConfig.context) { audioConfig.context.resume(); @@ -355,7 +355,7 @@ var WebAudioSoundManager = new Class({ this.masterMuteNode.disconnect(); this.masterMuteNode = null; - if (this.game.config.audio && this.game.config.audio.context) + if (this.game.config.audio.context) { this.context.suspend(); }