Merge pull request #975 from ericrosenbaum/bugfix/move-volume-to-rendered-target

Move volume to rendered target
This commit is contained in:
Eric Rosenbaum 2018-03-19 16:45:25 -04:00 committed by GitHub
commit 2b985fa083
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 10 deletions

View file

@ -238,7 +238,7 @@ class Scratch3SensingBlocks {
case 'backdrop #': return attrTarget.currentCostume + 1;
case 'backdrop name':
return attrTarget.getCostumes()[attrTarget.currentCostume].name;
case 'volume': return; // @todo: Keep this in mind for sound blocks!
case 'volume': return attrTarget.volume;
}
} else {
switch (args.PROPERTY) {
@ -249,7 +249,7 @@ class Scratch3SensingBlocks {
case 'costume name':
return attrTarget.getCostumes()[attrTarget.currentCostume].name;
case 'size': return attrTarget.size;
case 'volume': return; // @todo: above, keep in mind for sound blocks..
case 'volume': return attrTarget.volume;
}
}

View file

@ -37,7 +37,6 @@ class Scratch3SoundBlocks {
*/
static get DEFAULT_SOUND_STATE () {
return {
volume: 100,
effects: {
pitch: 0,
pan: 0
@ -267,22 +266,19 @@ class Scratch3SoundBlocks {
}
changeVolume (args, util) {
const soundState = this._getSoundState(util.target);
const volume = Cast.toNumber(args.VOLUME) + soundState.volume;
const volume = Cast.toNumber(args.VOLUME) + util.target.volume;
this._updateVolume(volume, util);
}
_updateVolume (volume, util) {
const soundState = this._getSoundState(util.target);
volume = MathUtil.clamp(volume, 0, 100);
soundState.volume = volume;
util.target.volume = volume;
if (util.target.audioPlayer === null) return;
util.target.audioPlayer.setVolume(soundState.volume);
util.target.audioPlayer.setVolume(util.target.volume);
}
getVolume (args, util) {
const soundState = this._getSoundState(util.target);
return soundState.volume;
return util.target.volume;
}
soundsMenu (args) {

View file

@ -122,6 +122,12 @@ class RenderedTarget extends Target {
* @type {number}
*/
this.tempo = 60;
/**
* Loudness for sound playback for this target, as a percentage.
* @type {number}
*/
this.volume = 100;
}
/**