phaser/src/sound/noaudio/NoAudioSoundManager.js

245 lines
5.8 KiB
JavaScript
Raw Normal View History

2018-02-12 12:25:30 +00:00
var BaseSoundManager = require('../BaseSoundManager');
var Class = require('../../utils/Class');
var EventEmitter = require('eventemitter3');
var NoAudioSound = require('./NoAudioSound');
var NOOP = require('../../utils/NOOP');
2018-01-26 14:40:45 +00:00
2018-02-12 12:25:30 +00:00
/**
* @classdesc
* No audio implementation of the sound manager. It is used if audio has been
* disabled in the game config or the device doesn't support any audio.
*
* It represents a graceful degradation of sound manager logic that provides
* minimal functionality and prevents Phaser projects that use audio from
* breaking on devices that don't support any audio playback technologies.
*
* @class NoAudioSoundManager
* @extends Phaser.Sound.EventEmitter
* @memberOf Phaser.Sound
* @constructor
* @author Pavle Goloskokovic <pgoloskokovic@gmail.com> (http://prunegames.com)
2018-02-12 12:25:30 +00:00
* @since 3.0.0
*
* @param {Phaser.Game} game - Reference to the current game instance.
*/
var NoAudioSoundManager = new Class({
2018-02-12 12:25:30 +00:00
Extends: EventEmitter,
2018-01-26 14:40:45 +00:00
2018-02-12 12:25:30 +00:00
initialize:
function NoAudioSoundManager (game)
2018-01-26 14:40:45 +00:00
{
EventEmitter.call(this);
2018-02-12 12:25:30 +00:00
/**
* Reference to the current game instance.
*
* @name Phaser.Sound.NoAudioSoundManager#game
* @type {Phaser.Game}
* @since 3.0.0
*/
this.game = game;
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSoundManager#sounds
* @type {array}
* @default []
* @since 3.0.0
*/
this.sounds = [];
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSoundManager#mute
* @type {boolean}
* @default false
* @since 3.0.0
*/
2018-01-20 19:00:21 +00:00
this.mute = false;
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSoundManager#volume
* @type {number}
* @default 1
* @since 3.0.0
*/
2018-01-20 19:00:36 +00:00
this.volume = 1;
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSoundManager#rate
* @type {number}
* @default 1
* @since 3.0.0
*/
2018-01-20 19:00:55 +00:00
this.rate = 1;
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSoundManager#detune
* @type {number}
* @default 0
* @since 3.0.0
*/
2018-01-20 19:01:09 +00:00
this.detune = 0;
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSoundManager#pauseOnBlur
* @type {boolean}
* @default true
* @since 3.0.0
*/
this.pauseOnBlur = true;
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSoundManager#locked
* @type {boolean}
* @default false
* @since 3.0.0
*/
2018-01-20 19:01:44 +00:00
this.locked = false;
},
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @method Phaser.Sound.NoAudioSoundManager#add
* @since 3.0.0
*
* @param {string} key - Asset key for the sound.
* @param {ISoundConfig} [config] - An optional config object containing default sound settings.
*
* @return {ISound} The new sound instance.
*/
2018-01-26 14:40:45 +00:00
add: function (key, config)
{
var sound = new NoAudioSound(this, key, config);
2018-02-12 12:25:30 +00:00
this.sounds.push(sound);
2018-02-12 12:25:30 +00:00
return sound;
},
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @method Phaser.Sound.NoAudioSoundManager#addAudioSprite
* @since 3.0.0
*
* @param {string} key - Asset key for the sound.
* @param {ISoundConfig} [config] - An optional config object containing default sound settings.
*
* @return {IAudioSpriteSound} The new audio sprite sound instance.
*/
2018-01-26 14:40:45 +00:00
addAudioSprite: function (key, config)
{
var sound = this.add(key, config);
sound.spritemap = {};
return sound;
},
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @method Phaser.Sound.NoAudioSoundManager#play
* @since 3.0.0
*
* @return {boolean} No Audio methods always return `false`.
*/
play: function ()
2018-01-26 14:40:45 +00:00
{
return false;
},
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @method Phaser.Sound.NoAudioSoundManager#playAudioSprite
* @since 3.0.0
*
* @return {boolean} No Audio methods always return `false`.
*/
playAudioSprite: function ()
2018-01-26 14:40:45 +00:00
{
return false;
},
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @method Phaser.Sound.NoAudioSoundManager#remove
* @since 3.0.0
*
* @param {ISound} sound - The sound object to remove.
*
* @return {boolean} True if the sound was removed successfully, otherwise false.
*/
2018-01-26 14:40:45 +00:00
remove: function (sound)
{
return BaseSoundManager.prototype.remove.call(this, sound);
},
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @method Phaser.Sound.NoAudioSoundManager#removeByKey
* @since 3.0.0
*
* @param {string} key - The key to match when removing sound objects.
*
* @return {number} The number of matching sound objects that were removed.
*/
2018-01-26 14:40:45 +00:00
removeByKey: function (key)
{
return BaseSoundManager.prototype.removeByKey.call(this, key);
},
2018-02-12 12:25:30 +00:00
pauseAll: NOOP,
2018-02-12 12:25:30 +00:00
2018-01-20 19:25:27 +00:00
resumeAll: NOOP,
2018-02-12 12:25:30 +00:00
2018-01-20 19:31:53 +00:00
stopAll: NOOP,
2018-02-12 12:25:30 +00:00
update: NOOP,
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @method Phaser.Sound.NoAudioSoundManager#destroy
* @since 3.0.0
*/
2018-01-26 14:40:45 +00:00
destroy: function ()
{
BaseSoundManager.prototype.destroy.call(this);
},
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @method Phaser.Sound.NoAudioSoundManager#forEachActiveSound
* @since 3.0.0
*
* @param {function} callbackfn - Callback function. (sound: ISound, index: number, array: ISound[]) => void
* @param [scope] - Callback context.
*/
forEachActiveSound: function (callbackfn, scope)
2018-01-26 14:40:45 +00:00
{
2018-02-12 12:25:30 +00:00
BaseSoundManager.prototype.forEachActiveSound.call(this, callbackfn, scope);
}
2018-02-12 12:25:30 +00:00
});
2018-02-12 12:25:30 +00:00
module.exports = NoAudioSoundManager;