phaser/src/sound/noaudio/NoAudioSound.js

330 lines
6.8 KiB
JavaScript
Raw Normal View History

2018-02-12 12:25:30 +00:00
var BaseSound = require('../BaseSound');
var Class = require('../../utils/Class');
var EventEmitter = require('eventemitter3');
2018-01-20 20:28:37 +00:00
var Extend = require('../../utils/object/Extend');
2018-01-26 14:39:34 +00:00
2018-02-12 12:25:30 +00:00
/**
* @classdesc
* No audio implementation of the sound. 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 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 NoAudioSound
* @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.Sound.NoAudioSoundManager} manager - Reference to the current sound manager instance.
* @param {string} key - Asset key for the sound.
* @param {ISoundConfig} [config={}] - An optional config object containing default sound settings.
*/
var NoAudioSound = new Class({
2018-02-12 12:25:30 +00:00
Extends: EventEmitter,
2018-01-26 14:39:34 +00:00
2018-02-12 12:25:30 +00:00
initialize:
function NoAudioSound (manager, key, config)
2018-01-26 14:39:34 +00:00
{
2018-01-26 13:52:03 +00:00
if (config === void 0) { config = {}; }
2018-02-12 12:25:30 +00:00
EventEmitter.call(this);
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSound#manager
* @type {Phaser.Sound.NoAudioSoundManager}
* @since 3.0.0
*/
this.manager = manager;
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSound#key
* @type {string}
* @since 3.0.0
*/
this.key = key;
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSound#isPlaying
* @type {boolean}
* @default false
* @since 3.0.0
*/
this.isPlaying = false;
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSound#isPaused
* @type {boolean}
* @default false
* @since 3.0.0
*/
this.isPaused = false;
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSound#totalRate
* @type {number}
* @default 1
* @since 3.0.0
*/
2018-01-20 20:00:31 +00:00
this.totalRate = 1;
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSound#duration
* @type {number}
* @default 0
* @since 3.0.0
*/
2018-01-20 20:00:50 +00:00
this.duration = 0;
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSound#totalDuration
* @type {number}
* @default 0
* @since 3.0.0
*/
this.totalDuration = 0;
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSound#config
* @type {object}
* @since 3.0.0
*/
this.config = Extend({
mute: false,
volume: 1,
rate: 1,
detune: 0,
seek: 0,
loop: false,
delay: 0
}, config);
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSound#currentConfig
* @type {[type]}
* @since 3.0.0
*/
this.currentConfig = this.config;
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSound#mute
* @type {boolean}
* @default false
* @since 3.0.0
*/
this.mute = false;
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSound#volume
* @type {number}
* @default 1
* @since 3.0.0
*/
this.volume = 1;
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSound#rate
* @type {number}
* @default 1
* @since 3.0.0
*/
this.rate = 1;
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSound#detune
* @type {number}
* @default 0
* @since 3.0.0
*/
this.detune = 0;
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSound#seek
* @type {number}
* @default 0
* @since 3.0.0
*/
this.seek = 0;
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSound#loop
* @type {boolean}
* @default false
* @since 3.0.0
*/
this.loop = false;
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSound#markers
* @type {object}
* @default {}
* @since 3.0.0
*/
this.markers = {};
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSound#currentMarker
* @type {?[type]}
* @default null
* @since 3.0.0
*/
this.currentMarker = null;
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @name Phaser.Sound.NoAudioSound#pendingRemove
* @type {boolean}
* @default null
* @since 3.0.0
*/
this.pendingRemove = false;
},
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @method Phaser.Sound.NoAudioSound#addMarker
* @since 3.0.0
*
* @return {boolean} False
*/
addMarker: function ()
2018-01-26 14:39:34 +00:00
{
return false;
},
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @method Phaser.Sound.NoAudioSound#updateMarker
* @since 3.0.0
*
* @return {boolean} False
*/
updateMarker: function ()
2018-01-26 14:39:34 +00:00
{
return false;
},
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @method Phaser.Sound.NoAudioSound#removeMarker
* @since 3.0.0
*
* @return {boolean} False
*/
removeMarker: function ()
2018-01-26 14:39:34 +00:00
{
return null;
},
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @method Phaser.Sound.NoAudioSound#play
* @since 3.0.0
*
* @return {boolean} False
*/
play: function ()
2018-01-26 14:39:34 +00:00
{
return false;
},
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @method Phaser.Sound.NoAudioSound#pause
* @since 3.0.0
*
* @return {boolean} False
*/
2018-01-26 14:39:34 +00:00
pause: function ()
{
return false;
},
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @method Phaser.Sound.NoAudioSound#resume
* @since 3.0.0
*
* @return {boolean} False
*/
2018-01-26 14:39:34 +00:00
resume: function ()
{
return false;
},
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @method Phaser.Sound.NoAudioSound#stop
* @since 3.0.0
*
* @return {boolean} False
*/
2018-01-26 14:39:34 +00:00
stop: function ()
{
return false;
2018-01-20 20:13:36 +00:00
},
2018-02-12 12:25:30 +00:00
/**
* [description]
*
* @method Phaser.Sound.NoAudioSound#destroy
* @since 3.0.0
*/
2018-01-26 14:39:34 +00:00
destroy: function ()
{
this.manager.remove(this);
2018-02-12 12:25:30 +00:00
BaseSound.prototype.destroy.call(this);
}
2018-02-12 12:25:30 +00:00
});
2018-02-12 12:25:30 +00:00
module.exports = NoAudioSound;