@@ -39,6 +39,11 @@ export class SoundPlugin extends ButtonPlugin {
39
39
this . _voMuted = false ;
40
40
this . _sfxMuted = false ;
41
41
42
+ this . _musicMutedByUser = false ;
43
+ this . _soundMutedByUser = false ;
44
+ this . _sfxMutedByUser = false ;
45
+ this . _voMutedByUser = false ;
46
+
42
47
this . soundMuteEnabled = false ;
43
48
this . musicMuteEnabled = false ;
44
49
this . sfxMuteEnabled = false ;
@@ -246,10 +251,16 @@ export class SoundPlugin extends ButtonPlugin {
246
251
this . soundVolume = this . soundSliders [ 0 ] . sliderRange (
247
252
Number ( e . target . value )
248
253
) ;
254
+ this . soundMuted = ! this . soundVolume ;
249
255
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 ;
253
264
}
254
265
255
266
this . sendProperty ( SoundPlugin . soundVolumeKey , this . soundVolume ) ;
@@ -268,14 +279,14 @@ export class SoundPlugin extends ButtonPlugin {
268
279
this . musicVolume = e . target . value ;
269
280
return ;
270
281
}
282
+
271
283
this . musicVolume = this . musicSliders [ 0 ] . sliderRange (
272
284
Number ( e . target . value )
273
285
) ;
274
286
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 ( ) ;
279
290
this . sendProperty ( SoundPlugin . musicVolumeKey , this . musicVolume ) ;
280
291
281
292
for ( let i = 0 ; i < this . musicSlidersLength ; i ++ ) {
@@ -293,11 +304,10 @@ export class SoundPlugin extends ButtonPlugin {
293
304
return ;
294
305
}
295
306
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 ( ) ;
296
310
297
- if ( ! this . voVolume !== this . voMuted ) {
298
- this . voMuted = ! this . voVolume ;
299
- this . _checkSoundMute ( ) ;
300
- }
301
311
this . sendProperty ( SoundPlugin . voVolumeKey , this . voVolume ) ;
302
312
for ( let i = 0 ; i < this . voSlidersLength ; i ++ ) {
303
313
this . voSliders [ i ] . value = this . voVolume ;
@@ -314,11 +324,10 @@ export class SoundPlugin extends ButtonPlugin {
314
324
return ;
315
325
}
316
326
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 ( ) ;
317
330
318
- if ( ! this . sfxVolume !== this . sfxMuted ) {
319
- this . sfxMuted = ! this . sfxVolume ;
320
- this . _checkSoundMute ( ) ;
321
- }
322
331
this . sendProperty ( SoundPlugin . sfxVolumeKey , this . sfxVolume ) ;
323
332
324
333
for ( let i = 0 ; i < this . sfxSlidersLength ; i ++ ) {
@@ -332,16 +341,24 @@ export class SoundPlugin extends ButtonPlugin {
332
341
onSoundToggle ( ) {
333
342
const muted = ! this . soundMuted ;
334
343
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
+ }
338
354
}
339
355
340
356
/**
341
357
* @memberof SoundPlugin
342
358
*/
343
359
onMusicToggle ( ) {
344
360
this . musicMuted = ! this . musicMuted ;
361
+ this . _musicMutedByUser = this . musicMuted ;
345
362
this . _checkSoundMute ( ) ;
346
363
}
347
364
@@ -350,6 +367,7 @@ export class SoundPlugin extends ButtonPlugin {
350
367
*/
351
368
onVOToggle ( ) {
352
369
this . voMuted = ! this . voMuted ;
370
+ this . _voMutedByUser = this . voMuted ;
353
371
this . _checkSoundMute ( ) ;
354
372
}
355
373
@@ -358,6 +376,7 @@ export class SoundPlugin extends ButtonPlugin {
358
376
*/
359
377
onSFXToggle ( ) {
360
378
this . sfxMuted = ! this . sfxMuted ;
379
+ this . _sfxMutedByUser = this . sfxMuted ;
361
380
this . _checkSoundMute ( ) ;
362
381
}
363
382
@@ -374,9 +393,9 @@ export class SoundPlugin extends ButtonPlugin {
374
393
* @param {Element } element
375
394
* @memberof SoundPlugin
376
395
*/
377
- setMuteProp ( key , value , element ) {
396
+ setMuteProp ( key , value , element , disableSend = false ) {
378
397
this [ '_' + key ] = value ;
379
- this . _setMuteProp ( key , element , value ) ;
398
+ this . _setMuteProp ( key , element , value , disableSend ) ;
380
399
}
381
400
382
401
/**
@@ -467,7 +486,7 @@ export class SoundPlugin extends ButtonPlugin {
467
486
this . sendProperty ( SoundPlugin . voVolumeKey , this . voVolume ) ;
468
487
this . sendProperty ( SoundPlugin . sfxVolumeKey , this . sfxVolume ) ;
469
488
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
471
490
// or the volume channel isn't enabled
472
491
if ( this . soundMuteEnabled && ( this . soundMuted || ! this . soundVolumeEnabled ) ) {
473
492
this . sendProperty ( SoundPlugin . soundMutedKey , this . soundMuted ) ;
@@ -488,7 +507,19 @@ export class SoundPlugin extends ButtonPlugin {
488
507
* @param {boolean } muted
489
508
*/
490
509
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 ) ;
492
523
}
493
524
494
525
/**
@@ -503,7 +534,17 @@ export class SoundPlugin extends ButtonPlugin {
503
534
* @param {boolean } muted
504
535
*/
505
536
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 ) ;
507
548
}
508
549
509
550
/**
@@ -518,7 +559,18 @@ export class SoundPlugin extends ButtonPlugin {
518
559
* @param {boolean } muted
519
560
*/
520
561
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 ) ;
522
574
}
523
575
524
576
/**
@@ -533,7 +585,17 @@ export class SoundPlugin extends ButtonPlugin {
533
585
* @param {boolean } muted
534
586
*/
535
587
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 ) ;
537
599
}
538
600
539
601
/**
0 commit comments