@@ -39,6 +39,11 @@ export class SoundPlugin extends ButtonPlugin {
3939 this . _voMuted = false ;
4040 this . _sfxMuted = false ;
4141
42+ this . _musicMutedByUser = false ;
43+ this . _soundMutedByUser = false ;
44+ this . _sfxMutedByUser = false ;
45+ this . _voMutedByUser = false ;
46+
4247 this . soundMuteEnabled = false ;
4348 this . musicMuteEnabled = false ;
4449 this . sfxMuteEnabled = false ;
@@ -246,10 +251,16 @@ export class SoundPlugin extends ButtonPlugin {
246251 this . soundVolume = this . soundSliders [ 0 ] . sliderRange (
247252 Number ( e . target . value )
248253 ) ;
254+ this . soundMuted = ! this . soundVolume ;
249255
250- if ( ! this . soundVolume !== this . soundMuted ) {
251- this . soundMuted = ! this . soundVolume ;
252- this . _checkSoundMute ( ) ;
256+ if ( ! this . _musicMutedByUser ) {
257+ this . musicMuted = this . soundMuted ;
258+ }
259+ if ( ! this . _sfxMutedByUser ) {
260+ this . sfxMuted = this . soundMuted ;
261+ }
262+ if ( ! this . _voMutedByUser ) {
263+ this . voMuted = this . soundMuted ;
253264 }
254265
255266 this . sendProperty ( SoundPlugin . soundVolumeKey , this . soundVolume ) ;
@@ -268,14 +279,14 @@ export class SoundPlugin extends ButtonPlugin {
268279 this . musicVolume = e . target . value ;
269280 return ;
270281 }
282+
271283 this . musicVolume = this . musicSliders [ 0 ] . sliderRange (
272284 Number ( e . target . value )
273285 ) ;
274286
275- if ( ! this . musicVolume !== this . musicMuted ) {
276- this . musicMuted = ! this . musicVolume ;
277- this . _checkSoundMute ( ) ;
278- }
287+ this . musicMuted = ! this . musicVolume ;
288+ if ( ! this . musicMuted ) { this . _musicMutedByUser = false ; }
289+ this . _checkSoundMute ( ) ;
279290 this . sendProperty ( SoundPlugin . musicVolumeKey , this . musicVolume ) ;
280291
281292 for ( let i = 0 ; i < this . musicSlidersLength ; i ++ ) {
@@ -293,11 +304,10 @@ export class SoundPlugin extends ButtonPlugin {
293304 return ;
294305 }
295306 this . voVolume = this . voSliders [ 0 ] . sliderRange ( Number ( e . target . value ) ) ;
307+ if ( ! this . voMuted ) { this . _voMutedByUser = false ; }
308+ this . voMuted = ! this . voVolume ;
309+ this . _checkSoundMute ( ) ;
296310
297- if ( ! this . voVolume !== this . voMuted ) {
298- this . voMuted = ! this . voVolume ;
299- this . _checkSoundMute ( ) ;
300- }
301311 this . sendProperty ( SoundPlugin . voVolumeKey , this . voVolume ) ;
302312 for ( let i = 0 ; i < this . voSlidersLength ; i ++ ) {
303313 this . voSliders [ i ] . value = this . voVolume ;
@@ -314,11 +324,10 @@ export class SoundPlugin extends ButtonPlugin {
314324 return ;
315325 }
316326 this . sfxVolume = this . sfxSliders [ 0 ] . sliderRange ( Number ( e . target . value ) ) ;
327+ if ( ! this . sfxMuted ) { this . _sfxMutedByUser = false ; }
328+ this . sfxMuted = ! this . sfxVolume ;
329+ this . _checkSoundMute ( ) ;
317330
318- if ( ! this . sfxVolume !== this . sfxMuted ) {
319- this . sfxMuted = ! this . sfxVolume ;
320- this . _checkSoundMute ( ) ;
321- }
322331 this . sendProperty ( SoundPlugin . sfxVolumeKey , this . sfxVolume ) ;
323332
324333 for ( let i = 0 ; i < this . sfxSlidersLength ; i ++ ) {
@@ -332,16 +341,24 @@ export class SoundPlugin extends ButtonPlugin {
332341 onSoundToggle ( ) {
333342 const muted = ! this . soundMuted ;
334343 this . soundMuted = muted ;
335- this . musicMuted = muted ;
336- this . voMuted = muted ;
337- this . sfxMuted = muted ;
344+
345+ if ( ! this . _musicMutedByUser || muted ) {
346+ this . musicMuted = muted ;
347+ }
348+ if ( ! this . _sfxMutedByUser || muted ) {
349+ this . sfxMuted = muted ;
350+ }
351+ if ( ! this . _voMutedByUser || muted ) {
352+ this . voMuted = muted ;
353+ }
338354 }
339355
340356 /**
341357 * @memberof SoundPlugin
342358 */
343359 onMusicToggle ( ) {
344360 this . musicMuted = ! this . musicMuted ;
361+ this . _musicMutedByUser = this . musicMuted ;
345362 this . _checkSoundMute ( ) ;
346363 }
347364
@@ -350,6 +367,7 @@ export class SoundPlugin extends ButtonPlugin {
350367 */
351368 onVOToggle ( ) {
352369 this . voMuted = ! this . voMuted ;
370+ this . _voMutedByUser = this . voMuted ;
353371 this . _checkSoundMute ( ) ;
354372 }
355373
@@ -358,6 +376,7 @@ export class SoundPlugin extends ButtonPlugin {
358376 */
359377 onSFXToggle ( ) {
360378 this . sfxMuted = ! this . sfxMuted ;
379+ this . _sfxMutedByUser = this . sfxMuted ;
361380 this . _checkSoundMute ( ) ;
362381 }
363382
@@ -374,9 +393,9 @@ export class SoundPlugin extends ButtonPlugin {
374393 * @param {Element } element
375394 * @memberof SoundPlugin
376395 */
377- setMuteProp ( key , value , element ) {
396+ setMuteProp ( key , value , element , disableSend = false ) {
378397 this [ '_' + key ] = value ;
379- this . _setMuteProp ( key , element , value ) ;
398+ this . _setMuteProp ( key , element , value , disableSend ) ;
380399 }
381400
382401 /**
@@ -467,7 +486,7 @@ export class SoundPlugin extends ButtonPlugin {
467486 this . sendProperty ( SoundPlugin . voVolumeKey , this . voVolume ) ;
468487 this . sendProperty ( SoundPlugin . sfxVolumeKey , this . sfxVolume ) ;
469488
470- // to avoid the mute property overwriting the volume, mutes should only send if they're true
489+ // to avoid the mute property overwriting the volume on startup , mutes should only send if they're true
471490 // or the volume channel isn't enabled
472491 if ( this . soundMuteEnabled && ( this . soundMuted || ! this . soundVolumeEnabled ) ) {
473492 this . sendProperty ( SoundPlugin . soundMutedKey , this . soundMuted ) ;
@@ -488,7 +507,19 @@ export class SoundPlugin extends ButtonPlugin {
488507 * @param {boolean } muted
489508 */
490509 set soundMuted ( muted ) {
491- this . setMuteProp ( 'soundMuted' , muted , this . soundButtons ) ;
510+ if ( muted === this . soundMuted ) {
511+ // have to do this to make sure it gets set up properly on start up
512+ this . setMuteProp ( 'soundMuted' , muted , this . soundButtons , true ) ;
513+ return ;
514+ }
515+
516+ let disableSend = false ;
517+ // if volume is enabled and the channel is becoming unmuted we update everything but only send the volume
518+ if ( this . soundVolumeEnabled && ! muted ) {
519+ this . sendProperty ( SoundPlugin . soundVolumeKey , this . soundVolume ) ;
520+ disableSend = true ;
521+ }
522+ this . setMuteProp ( 'soundMuted' , muted , this . soundButtons , disableSend ) ;
492523 }
493524
494525 /**
@@ -503,7 +534,17 @@ export class SoundPlugin extends ButtonPlugin {
503534 * @param {boolean } muted
504535 */
505536 set voMuted ( muted ) {
506- this . setMuteProp ( 'voMuted' , muted , this . voButtons ) ;
537+ let disableSend = false ;
538+ if ( this . voMuted === muted ) {
539+ // have to do this to make sure it gets set up properly on start up
540+ this . setMuteProp ( 'voMuted' , muted , this . voButtons , true ) ;
541+ return ;
542+ }
543+ if ( ( this . voVolumeEnabled && ! muted ) ) {
544+ this . sendProperty ( SoundPlugin . voVolumeKey , this . voVolume ) ;
545+ disableSend = true ;
546+ }
547+ this . setMuteProp ( 'voMuted' , muted , this . voButtons , disableSend ) ;
507548 }
508549
509550 /**
@@ -518,7 +559,18 @@ export class SoundPlugin extends ButtonPlugin {
518559 * @param {boolean } muted
519560 */
520561 set musicMuted ( muted ) {
521- this . setMuteProp ( 'musicMuted' , muted , this . musicButtons ) ;
562+ if ( this . musicMuted === muted ) {
563+ // have to do this to make sure it gets set up properly on start up
564+ this . setMuteProp ( 'musicMuted' , muted , this . musicButtons , true ) ;
565+ return ;
566+ }
567+ let disableSend = false ;
568+ if ( this . musicVolumeEnabled && ! muted ) {
569+ this . sendProperty ( SoundPlugin . musicVolumeKey , this . musicVolume ) ;
570+ disableSend = true ;
571+ }
572+
573+ this . setMuteProp ( 'musicMuted' , muted , this . musicButtons , disableSend ) ;
522574 }
523575
524576 /**
@@ -533,7 +585,17 @@ export class SoundPlugin extends ButtonPlugin {
533585 * @param {boolean } muted
534586 */
535587 set sfxMuted ( muted ) {
536- this . setMuteProp ( 'sfxMuted' , muted , this . sfxButtons ) ;
588+ if ( this . sfxMuted === muted ) {
589+ // have to do this to make sure it gets set up properly on start up
590+ this . setMuteProp ( 'sfxMuted' , muted , this . sfxButtons , true ) ;
591+ return ;
592+ }
593+ let disableSend = false ;
594+ if ( this . sfxVolumeEnabled && ! muted ) {
595+ this . sendProperty ( SoundPlugin . sfxVolumeKey , this . sfxVolume ) ;
596+ disableSend = true ;
597+ }
598+ this . setMuteProp ( 'sfxMuted' , muted , this . sfxButtons , disableSend ) ;
537599 }
538600
539601 /**
0 commit comments