Skip to content

Commit f25edc2

Browse files
authored
Merge pull request #167 from SpringRoll/release/2.4.6
Release 2.4.6
2 parents 62477fd + e3bf0f4 commit f25edc2

File tree

10 files changed

+113
-41
lines changed

10 files changed

+113
-41
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2.4.6] - 2023-10-16
9+
10+
### Fixed
11+
12+
- added check to prevent sub sound channel volumes being set to 0 causing soundVolume to be set to 1 in the game
13+
- Added/fixed logic in `SoundPlugin` volume and toggle handlers to make sure everything stays in sync and respects user preferences better
14+
815
## [2.4.5] 2023-09-08
916

1017
### Fixed

dist/SpringRoll-Container-umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/SpringRoll-Container-umd.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "springroll-container",
3-
"version": "2.4.5",
3+
"version": "2.4.6",
44
"description": "The iframe controller for interacting with SpringRoll applications",
55
"main": "./dist/index.js",
66
"license": "MIT",

src/base-plugins/BasePlugin.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ export class BasePlugin {
5252
*
5353
* @param {string} prop
5454
* @param {any} value
55+
* @param {Boolean} disableSend
5556
* @memberof BasePlugin
5657
*/
57-
sendProperty(prop, value) {
58+
sendProperty(prop, value, disableSend = false) {
5859
SavedData.write(prop, value);
60+
if (disableSend) { return; }
5961
this.client.send(prop, value);
6062
}
6163

src/base-plugins/ButtonPlugin.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,17 @@ export class ButtonPlugin extends BasePlugin {
5858
* @param {string} prop
5959
* @param {Element} button
6060
* @param {Boolean} muted
61+
* @param {Boolean} disableSend
6162
* @memberof ButtonPlugin
6263
*/
63-
_setMuteProp(prop, button, muted) {
64+
_setMuteProp(prop, button, muted, disableSend = false) {
6465
if (Array.isArray(button)) {
6566
button.forEach(b => this.changeMutedState(b, muted));
6667
} else {
6768
this.changeMutedState(button, muted);
6869
}
6970

70-
this.sendProperty(prop, muted);
71+
this.sendProperty(prop, muted, disableSend);
7172
}
7273

7374
/**

src/plugins/SoundPlugin.js

Lines changed: 87 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)