/
NoAudioSound.js
187 lines (158 loc) · 4.56 KB
/
NoAudioSound.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/**
* @author Richard Davey <rich@photonstorm.com>
* @author Pavle Goloskokovic <pgoloskokovic@gmail.com> (http://prunegames.com)
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var BaseSound = require('../BaseSound');
var Class = require('../../utils/Class');
var EventEmitter = require('eventemitter3');
var Extend = require('../../utils/object/Extend');
var returnFalse = function ()
{
return false;
};
var returnNull = function ()
{
return null;
};
var returnThis = function ()
{
return this;
};
/**
* @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
* @memberof Phaser.Sound
* @constructor
* @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 {Phaser.Types.Sound.SoundConfig} [config={}] - An optional config object containing default sound settings.
*/
var NoAudioSound = new Class({
Extends: EventEmitter,
initialize:
function NoAudioSound (manager, key, config)
{
if (config === void 0) { config = {}; }
EventEmitter.call(this);
this.manager = manager;
this.key = key;
this.isPlaying = false;
this.isPaused = false;
this.totalRate = 1;
this.duration = 0;
this.totalDuration = 0;
this.config = Extend({
mute: false,
volume: 1,
rate: 1,
detune: 0,
seek: 0,
loop: false,
delay: 0,
pan: 0
}, config);
this.currentConfig = this.config;
this.mute = false;
this.volume = 1;
this.rate = 1;
this.detune = 0;
this.seek = 0;
this.loop = false;
this.pan = 0;
this.markers = {};
this.currentMarker = null;
this.pendingRemove = false;
},
/**
* @method Phaser.Sound.NoAudioSound#addMarker
* @since 3.0.0
*
* @param {Phaser.Types.Sound.SoundMarker} marker - Marker object.
*
* @return {boolean} false
*/
addMarker: returnFalse,
/**
* @method Phaser.Sound.NoAudioSound#updateMarker
* @since 3.0.0
*
* @param {Phaser.Types.Sound.SoundMarker} marker - Marker object with updated values.
*
* @return {boolean} false
*/
updateMarker: returnFalse,
/**
* @method Phaser.Sound.NoAudioSound#removeMarker
* @since 3.0.0
*
* @param {string} markerName - The name of the marker to remove.
*
* @return {null} null
*/
removeMarker: returnNull,
/**
* @method Phaser.Sound.NoAudioSound#play
* @since 3.0.0
*
* @param {(string|Phaser.Types.Sound.SoundConfig)} [markerName=''] - If you want to play a marker then provide the marker name here. Alternatively, this parameter can be a SoundConfig object.
* @param {Phaser.Types.Sound.SoundConfig} [config] - Optional sound config object to be applied to this marker or entire sound if no marker name is provided. It gets memorized for future plays of current section of the sound.
*
* @return {boolean} false
*/
play: returnFalse,
/**
* @method Phaser.Sound.NoAudioSound#pause
* @since 3.0.0
*
* @return {boolean} false
*/
pause: returnFalse,
/**
* Resumes the sound.
*
* @method Phaser.Sound.NoAudioSound#resume
* @since 3.0.0
*
* @return {boolean} false
*/
resume: returnFalse,
/**
* Stop playing this sound.
*
* @method Phaser.Sound.NoAudioSound#stop
* @since 3.0.0
*
* @return {boolean} false
*/
stop: returnFalse,
/**
* Destroys this sound and all associated events and marks it for removal from the sound manager.
*
* @method Phaser.Sound.NoAudioSound#destroy
* @fires Phaser.Sound.Events#DESTROY
* @since 3.0.0
*/
destroy: function ()
{
BaseSound.prototype.destroy.call(this);
},
setMute: returnThis,
setVolume: returnThis,
setRate: returnThis,
setDetune: returnThis,
setSeek: returnThis,
setLoop: returnThis,
setPan: returnThis
});
module.exports = NoAudioSound;