mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-09 14:32:07 -05:00
Clones inherit music custom state
This commit is contained in:
parent
21ae14c499
commit
88b13e218d
1 changed files with 19 additions and 0 deletions
|
@ -74,6 +74,9 @@ class Scratch3MusicBlocks {
|
||||||
this._bufferSources = [];
|
this._bufferSources = [];
|
||||||
|
|
||||||
this._loadAllSounds();
|
this._loadAllSounds();
|
||||||
|
|
||||||
|
this._onTargetCreated = this._onTargetCreated.bind(this);
|
||||||
|
runtime.on('targetWasCreated', this._onTargetCreated);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -441,6 +444,22 @@ class Scratch3MusicBlocks {
|
||||||
return musicState;
|
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.
|
* @returns {object} metadata for this extension and its blocks.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue