Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.4.6] - 2023-10-16

### Fixed

- added check to prevent sub sound channel volumes being set to 0 causing soundVolume to be set to 1 in the game
- Added/fixed logic in `SoundPlugin` volume and toggle handlers to make sure everything stays in sync and respects user preferences better

## [2.4.5] 2023-09-08

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion dist/SpringRoll-Container-umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/SpringRoll-Container-umd.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "springroll-container",
"version": "2.4.5",
"version": "2.4.6",
"description": "The iframe controller for interacting with SpringRoll applications",
"main": "./dist/index.js",
"license": "MIT",
Expand Down
4 changes: 3 additions & 1 deletion src/base-plugins/BasePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ export class BasePlugin {
*
* @param {string} prop
* @param {any} value
* @param {Boolean} disableSend
* @memberof BasePlugin
*/
sendProperty(prop, value) {
sendProperty(prop, value, disableSend = false) {
SavedData.write(prop, value);
if (disableSend) { return; }
this.client.send(prop, value);
}

Expand Down
5 changes: 3 additions & 2 deletions src/base-plugins/ButtonPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,17 @@ export class ButtonPlugin extends BasePlugin {
* @param {string} prop
* @param {Element} button
* @param {Boolean} muted
* @param {Boolean} disableSend
* @memberof ButtonPlugin
*/
_setMuteProp(prop, button, muted) {
_setMuteProp(prop, button, muted, disableSend = false) {
if (Array.isArray(button)) {
button.forEach(b => this.changeMutedState(b, muted));
} else {
this.changeMutedState(button, muted);
}

this.sendProperty(prop, muted);
this.sendProperty(prop, muted, disableSend);
}

/**
Expand Down
112 changes: 87 additions & 25 deletions src/plugins/SoundPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ export class SoundPlugin extends ButtonPlugin {
this._voMuted = false;
this._sfxMuted = false;

this._musicMutedByUser = false;
this._soundMutedByUser = false;
this._sfxMutedByUser = false;
this._voMutedByUser = false;

this.soundMuteEnabled = false;
this.musicMuteEnabled = false;
this.sfxMuteEnabled = false;
Expand Down Expand Up @@ -246,10 +251,16 @@ export class SoundPlugin extends ButtonPlugin {
this.soundVolume = this.soundSliders[0].sliderRange(
Number(e.target.value)
);
this.soundMuted = !this.soundVolume;

if (!this.soundVolume !== this.soundMuted) {
this.soundMuted = !this.soundVolume;
this._checkSoundMute();
if (!this._musicMutedByUser) {
this.musicMuted = this.soundMuted;
}
if (!this._sfxMutedByUser) {
this.sfxMuted = this.soundMuted;
}
if (!this._voMutedByUser) {
this.voMuted = this.soundMuted;
}

this.sendProperty(SoundPlugin.soundVolumeKey, this.soundVolume);
Expand All @@ -268,14 +279,14 @@ export class SoundPlugin extends ButtonPlugin {
this.musicVolume = e.target.value;
return;
}

this.musicVolume = this.musicSliders[0].sliderRange(
Number(e.target.value)
);

if (!this.musicVolume !== this.musicMuted) {
this.musicMuted = !this.musicVolume;
this._checkSoundMute();
}
this.musicMuted = !this.musicVolume;
if (!this.musicMuted) { this._musicMutedByUser = false; }
this._checkSoundMute();
this.sendProperty(SoundPlugin.musicVolumeKey, this.musicVolume);

for (let i = 0; i < this.musicSlidersLength; i++) {
Expand All @@ -293,11 +304,10 @@ export class SoundPlugin extends ButtonPlugin {
return;
}
this.voVolume = this.voSliders[0].sliderRange(Number(e.target.value));
if (!this.voMuted) { this._voMutedByUser = false; }
this.voMuted = !this.voVolume;
this._checkSoundMute();

if (!this.voVolume !== this.voMuted) {
this.voMuted = !this.voVolume;
this._checkSoundMute();
}
this.sendProperty(SoundPlugin.voVolumeKey, this.voVolume);
for (let i = 0; i < this.voSlidersLength; i++) {
this.voSliders[i].value = this.voVolume;
Expand All @@ -314,11 +324,10 @@ export class SoundPlugin extends ButtonPlugin {
return;
}
this.sfxVolume = this.sfxSliders[0].sliderRange(Number(e.target.value));
if (!this.sfxMuted) { this._sfxMutedByUser = false; }
this.sfxMuted = !this.sfxVolume;
this._checkSoundMute();

if (!this.sfxVolume !== this.sfxMuted) {
this.sfxMuted = !this.sfxVolume;
this._checkSoundMute();
}
this.sendProperty(SoundPlugin.sfxVolumeKey, this.sfxVolume);

for (let i = 0; i < this.sfxSlidersLength; i++) {
Expand All @@ -332,16 +341,24 @@ export class SoundPlugin extends ButtonPlugin {
onSoundToggle() {
const muted = !this.soundMuted;
this.soundMuted = muted;
this.musicMuted = muted;
this.voMuted = muted;
this.sfxMuted = muted;

if (!this._musicMutedByUser || muted) {
this.musicMuted = muted;
}
if (!this._sfxMutedByUser || muted) {
this.sfxMuted = muted;
}
if (!this._voMutedByUser || muted) {
this.voMuted = muted;
}
}

/**
* @memberof SoundPlugin
*/
onMusicToggle() {
this.musicMuted = !this.musicMuted;
this._musicMutedByUser = this.musicMuted;
this._checkSoundMute();
}

Expand All @@ -350,6 +367,7 @@ export class SoundPlugin extends ButtonPlugin {
*/
onVOToggle() {
this.voMuted = !this.voMuted;
this._voMutedByUser = this.voMuted;
this._checkSoundMute();
}

Expand All @@ -358,6 +376,7 @@ export class SoundPlugin extends ButtonPlugin {
*/
onSFXToggle() {
this.sfxMuted = !this.sfxMuted;
this._sfxMutedByUser = this.sfxMuted;
this._checkSoundMute();
}

Expand All @@ -374,9 +393,9 @@ export class SoundPlugin extends ButtonPlugin {
* @param {Element} element
* @memberof SoundPlugin
*/
setMuteProp(key, value, element) {
setMuteProp(key, value, element, disableSend = false) {
this['_' + key] = value;
this._setMuteProp(key, element, value);
this._setMuteProp(key, element, value, disableSend);
}

/**
Expand Down Expand Up @@ -467,7 +486,7 @@ export class SoundPlugin extends ButtonPlugin {
this.sendProperty(SoundPlugin.voVolumeKey, this.voVolume);
this.sendProperty(SoundPlugin.sfxVolumeKey, this.sfxVolume);

// to avoid the mute property overwriting the volume, mutes should only send if they're true
// to avoid the mute property overwriting the volume on startup, mutes should only send if they're true
// or the volume channel isn't enabled
if ( this.soundMuteEnabled && (this.soundMuted || !this.soundVolumeEnabled )) {
this.sendProperty(SoundPlugin.soundMutedKey, this.soundMuted);
Expand All @@ -488,7 +507,19 @@ export class SoundPlugin extends ButtonPlugin {
* @param {boolean} muted
*/
set soundMuted(muted) {
this.setMuteProp('soundMuted', muted, this.soundButtons);
if (muted === this.soundMuted) {
// have to do this to make sure it gets set up properly on start up
this.setMuteProp('soundMuted', muted, this.soundButtons, true);
return;
}

let disableSend = false;
// if volume is enabled and the channel is becoming unmuted we update everything but only send the volume
if (this.soundVolumeEnabled && !muted) {
this.sendProperty(SoundPlugin.soundVolumeKey, this.soundVolume);
disableSend = true;
}
this.setMuteProp('soundMuted', muted, this.soundButtons, disableSend);
}

/**
Expand All @@ -503,7 +534,17 @@ export class SoundPlugin extends ButtonPlugin {
* @param {boolean} muted
*/
set voMuted(muted) {
this.setMuteProp('voMuted', muted, this.voButtons);
let disableSend = false;
if (this.voMuted === muted) {
// have to do this to make sure it gets set up properly on start up
this.setMuteProp('voMuted', muted, this.voButtons, true);
return;
}
if ((this.voVolumeEnabled && !muted)) {
this.sendProperty(SoundPlugin.voVolumeKey, this.voVolume);
disableSend = true;
}
this.setMuteProp('voMuted', muted, this.voButtons, disableSend);
}

/**
Expand All @@ -518,7 +559,18 @@ export class SoundPlugin extends ButtonPlugin {
* @param {boolean} muted
*/
set musicMuted(muted) {
this.setMuteProp('musicMuted', muted, this.musicButtons);
if (this.musicMuted === muted) {
// have to do this to make sure it gets set up properly on start up
this.setMuteProp('musicMuted', muted, this.musicButtons, true);
return;
}
let disableSend = false;
if (this.musicVolumeEnabled && !muted) {
this.sendProperty(SoundPlugin.musicVolumeKey, this.musicVolume);
disableSend = true;
}

this.setMuteProp('musicMuted', muted, this.musicButtons, disableSend);
}

/**
Expand All @@ -533,7 +585,17 @@ export class SoundPlugin extends ButtonPlugin {
* @param {boolean} muted
*/
set sfxMuted(muted) {
this.setMuteProp('sfxMuted', muted, this.sfxButtons);
if (this.sfxMuted === muted) {
// have to do this to make sure it gets set up properly on start up
this.setMuteProp('sfxMuted', muted, this.sfxButtons, true);
return;
}
let disableSend = false;
if (this.sfxVolumeEnabled && !muted) {
this.sendProperty(SoundPlugin.sfxVolumeKey, this.sfxVolume);
disableSend = true;
}
this.setMuteProp('sfxMuted', muted, this.sfxButtons, disableSend);
}

/**
Expand Down