Merge pull request #1184 from ericrosenbaum/bugfix/sound-blocks-yield

Set/change sound effect and volume blocks yield until the next tick
This commit is contained in:
Eric Rosenbaum 2018-06-01 13:19:50 -04:00 committed by GitHub
commit 294801c1f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -204,11 +204,11 @@ class Scratch3SoundBlocks {
} }
setEffect (args, util) { setEffect (args, util) {
this._updateEffect(args, util, false); return this._updateEffect(args, util, false);
} }
changeEffect (args, util) { changeEffect (args, util) {
this._updateEffect(args, util, true); return this._updateEffect(args, util, true);
} }
_updateEffect (args, util, change) { _updateEffect (args, util, change) {
@ -229,6 +229,11 @@ class Scratch3SoundBlocks {
if (util.target.audioPlayer === null) return; if (util.target.audioPlayer === null) return;
util.target.audioPlayer.setEffect(effect, soundState.effects[effect]); util.target.audioPlayer.setEffect(effect, soundState.effects[effect]);
// Yield until the next tick.
return new Promise(resolve => {
resolve();
});
} }
_syncEffectsForTarget (target) { _syncEffectsForTarget (target) {
@ -264,12 +269,12 @@ class Scratch3SoundBlocks {
setVolume (args, util) { setVolume (args, util) {
const volume = Cast.toNumber(args.VOLUME); const volume = Cast.toNumber(args.VOLUME);
this._updateVolume(volume, util); return this._updateVolume(volume, util);
} }
changeVolume (args, util) { changeVolume (args, util) {
const volume = Cast.toNumber(args.VOLUME) + util.target.volume; const volume = Cast.toNumber(args.VOLUME) + util.target.volume;
this._updateVolume(volume, util); return this._updateVolume(volume, util);
} }
_updateVolume (volume, util) { _updateVolume (volume, util) {
@ -277,6 +282,11 @@ class Scratch3SoundBlocks {
util.target.volume = volume; util.target.volume = volume;
if (util.target.audioPlayer === null) return; if (util.target.audioPlayer === null) return;
util.target.audioPlayer.setVolume(util.target.volume); util.target.audioPlayer.setVolume(util.target.volume);
// Yield until the next tick.
return new Promise(resolve => {
resolve();
});
} }
getVolume (args, util) { getVolume (args, util) {