Skip to content

Commit 0fe8757

Browse files
moved create method meant for instantiating global sound manager object form BaseSoundManager class to dedicated SoundManagerCreator class
moved setting local game reference from WebAudioSoundManager class to BaseSoundManager class constructor fixed bug with audio context creation condition in WebAudioSoundManager class
1 parent 5b6fb58 commit 0fe8757

4 files changed

Lines changed: 42 additions & 25 deletions

File tree

v3/src/boot/Game.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var GlobalInputManager = require('../input/global/GlobalInputManager');
1717
var GlobalSceneManager = require('../scene/global/GlobalSceneManager');
1818
var TextureManager = require('../textures/TextureManager');
1919
var TimeStep = require('./TimeStep');
20-
var BaseSoundManager = require('../sound/BaseSoundManager');
20+
var SoundManagerCreator = require('../sound/SoundManagerCreator');
2121

2222
var Game = new Class({
2323

@@ -138,7 +138,7 @@ var Game = new Class({
138138
*
139139
* @property {Phaser.BaseSoundManager} sound
140140
*/
141-
this.sound = BaseSoundManager.create(this);
141+
this.sound = SoundManagerCreator.create(this);
142142

143143
/**
144144
* [description]

v3/src/sound/BaseSoundManager.js

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
11
var Class = require('../utils/Class');
2-
var WebAudioSoundManager = require('./WebAudioSoundManager');
32

43
// Phaser.Loader.BaseSoundManager
54

65
var BaseSoundManager = new Class({
76

87
// TODO define sound manager interface
98

10-
});
11-
12-
BaseSoundManager.create = function (game)
13-
{
14-
var audioConfig = game.config.audio;
15-
var deviceAudio = game.device.Audio;
16-
17-
if ((audioConfig && audioConfig.noAudio) || (!deviceAudio.webAudio && !deviceAudio.audioData))
18-
{
19-
return new BaseSoundManager(game);
20-
}
9+
initialize:
2110

22-
if(deviceAudio.webAudio && !(audioConfig && audioConfig.disableWebAudio))
11+
function BaseSoundManager (game)
2312
{
24-
return new WebAudioSoundManager(game);
13+
/**
14+
* @property {Phaser.Game} game - Local reference to game.
15+
*/
16+
this.game = game;
2517
}
2618

27-
// TODO return HTML5 Audio sound manager
28-
return new BaseSoundManager(game);
29-
};
19+
});
3020

3121
module.exports = BaseSoundManager;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var BaseSoundManager = require('./BaseSoundManager');
2+
var WebAudioSoundManager = require('./WebAudioSoundManager');
3+
4+
var SoundManagerCreator = {
5+
6+
create: function (game)
7+
{
8+
var audioConfig = game.config.audio;
9+
var deviceAudio = game.device.Audio;
10+
11+
if ((audioConfig && audioConfig.noAudio) || (!deviceAudio.webAudio && !deviceAudio.audioData))
12+
{
13+
// TODO add no audio implementation of BaseSoundManager
14+
return new BaseSoundManager(game);
15+
}
16+
17+
if(deviceAudio.webAudio && !(audioConfig && audioConfig.disableWebAudio))
18+
{
19+
return new WebAudioSoundManager(game);
20+
}
21+
22+
// TODO return HTML5 Audio sound manager
23+
return new BaseSoundManager(game);
24+
}
25+
26+
};
27+
28+
module.exports = SoundManagerCreator;

v3/src/sound/WebAudioSoundManager.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ var WebAudioSoundManager = new Class({
1111

1212
function WebAudioSoundManager (game)
1313
{
14-
/**
15-
* @property {Phaser.Game} game - Local reference to game.
16-
*/
17-
this.game = game;
14+
BaseSoundManager.call(this, game);
1815

1916
/**
2017
* @property {AudioContext} context - The AudioContext being used for playback.
@@ -25,9 +22,11 @@ var WebAudioSoundManager = new Class({
2522

2623
createAudioContext: function ()
2724
{
28-
if (this.game.config.audio.context)
25+
var audioConfig = this.game.config.audio;
26+
27+
if (audioConfig && audioConfig.context)
2928
{
30-
return this.game.config.audio.context;
29+
return audioConfig.context;
3130
}
3231

3332
return new (window['AudioContext'] || window['webkitAudioContext'])();

0 commit comments

Comments
 (0)