mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-07-05 10:41:03 -04:00
Merge pull request #1017 from ericrosenbaum/bugfix/clones-inherit-instrument
Clones inherit music custom state
This commit is contained in:
commit
25f1c1a5e6
2 changed files with 21 additions and 1 deletions
|
@ -74,6 +74,9 @@ class Scratch3MusicBlocks {
|
|||
this._bufferSources = [];
|
||||
|
||||
this._loadAllSounds();
|
||||
|
||||
this._onTargetCreated = this._onTargetCreated.bind(this);
|
||||
this.runtime.on('targetWasCreated', this._onTargetCreated);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -441,6 +444,22 @@ class Scratch3MusicBlocks {
|
|||
return musicState;
|
||||
}
|
||||
|
||||
/**
|
||||
* When a music-playing Target is cloned, clone the music state.
|
||||
* @param {Target} newTarget - the newly created target.
|
||||
* @param {Target} [sourceTarget] - the target used as a source for the new clone, if any.
|
||||
* @listens Runtime#event:targetWasCreated
|
||||
* @private
|
||||
*/
|
||||
_onTargetCreated (newTarget, sourceTarget) {
|
||||
if (sourceTarget) {
|
||||
const musicState = sourceTarget.getCustomState(Scratch3MusicBlocks.STATE_KEY);
|
||||
if (musicState) {
|
||||
newTarget.setCustomState(Scratch3MusicBlocks.STATE_KEY, Clone.simple(musicState));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {object} metadata for this extension and its blocks.
|
||||
*/
|
||||
|
|
|
@ -2,7 +2,8 @@ const test = require('tap').test;
|
|||
const Music = require('../../src/extensions/scratch3_music/index.js');
|
||||
|
||||
const fakeRuntime = {
|
||||
getTargetForStage: () => ({tempo: 60})
|
||||
getTargetForStage: () => ({tempo: 60}),
|
||||
on: () => {} // Stub out listener methods used in constructor.
|
||||
};
|
||||
|
||||
const blocks = new Music(fakeRuntime);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue