shareBlocksToTarget (blocks, targetId, optFromTargetId) {
        this.emit('shareBlocksToTarget*');
        const sb3 = require('./serialization/sb3');

        const copiedBlocks = JSON.parse(JSON.stringify(blocks));
        newBlockIds(copiedBlocks);
        const target = this.runtime.getTargetById(targetId);

        if (optFromTargetId) {
            // If the blocks are being shared from another target,
            // resolve any possible variable conflicts that may arise.
            const fromTarget = this.runtime.getTargetById(optFromTargetId);
            fromTarget.resolveVariableSharingConflictsWithTarget(copiedBlocks, target);
        }

        // Create a unique set of extensionIds that are not yet loaded
        const extensionIDs = new Set(copiedBlocks
            .map(b => sb3.getExtensionIdForOpcode(b.opcode))
            .filter(id => !!id) // Remove ids that do not exist
            .filter(id => !this.extensionManager.isExtensionLoaded(id)) // and remove loaded extensions
        );

        // Create an array promises for extensions to load
        const extensionPromises = Array.from(extensionIDs,
            id => this.extensionManager.loadExtensionURL(id)
        );

        return Promise.all(extensionPromises).then(() => {
            copiedBlocks.forEach(block => {
                target.blocks.createBlock(block);
            });
            target.blocks.updateTargetSpecificBlocks(target.isStage);
        });
    }
/**
     * Called when blocks are dragged from one sprite to another. Adds the blocks to the
     * workspace of the given target.
     * @param {!Array<object>} blocks Blocks to add.
     * @param {!string} targetId Id of target to add blocks to.
     * @param {?string} optFromTargetId Optional target id indicating that blocks are being
     * shared from that target. This is needed for resolving any potential variable conflicts.
     * @return {!Promise} Promise that resolves when the extensions and blocks have been added.
     */
Called when blocks are dragged from one sprite to another. Adds the blocks to the
workspace of the given target.
@param {!Array} blocks Blocks to add.
@param {!string} targetId Id of target to add blocks to.
@param {?string} optFromTargetId Optional target id indicating that blocks are being
shared from that target. This is needed for resolving any potential variable conflicts.
@return {!Promise} Promise that resolves when the extensions and blocks have been added.
Called when blocks are dragged from one sprite to another . Adds the blocks to the workspace of the given target . @param { !Array } blocks Blocks to add . @param { !string } targetId Id of target to add blocks to . @param { ?string } optFromTargetId Optional target id indicating that blocks are being shared from that target . This is needed for resolving any potential variable conflicts . @return { !Promise } Promise that resolves when the extensions and blocks have been added .
shareBlocksToTarget (blocks, targetId, optFromTargetId) {
        this.emit('shareBlocksToTarget*');
        const sb3 = require('./serialization/sb3');
        const copiedBlocks = JSON.parse(JSON.stringify(blocks));
        newBlockIds(copiedBlocks);
        const target = this.runtime.getTargetById(targetId);
        if (optFromTargetId) {
            const fromTarget = this.runtime.getTargetById(optFromTargetId);
            fromTarget.resolveVariableSharingConflictsWithTarget(copiedBlocks, target);
        }
        const extensionIDs = new Set(copiedBlocks
            .map(b => sb3.getExtensionIdForOpcode(b.opcode))
            .filter(id => !!id) 
            .filter(id => !this.extensionManager.isExtensionLoaded(id)) 
        );
        const extensionPromises = Array.from(extensionIDs,
            id => this.extensionManager.loadExtensionURL(id)
        );
        return Promise.all(extensionPromises).then(() => {
            copiedBlocks.forEach(block => {
                target.blocks.createBlock(block);
            });
            target.blocks.updateTargetSpecificBlocks(target.isStage);
        });
    }
shareBlocksToTarget ( blocks , targetId , optFromTargetId ) { this . emit ( 'shareBlocksToTarget*' ) ; const sb3 = require ( './serialization/sb3' ) ; const copiedBlocks = JSON . parse ( JSON . stringify ( blocks ) ) ; newBlockIds ( copiedBlocks ) ; const target = this . runtime . getTargetById ( targetId ) ; if ( optFromTargetId ) { const fromTarget = this . runtime . getTargetById ( optFromTargetId ) ; fromTarget . resolveVariableSharingConflictsWithTarget ( copiedBlocks , target ) ; } const extensionIDs = new Set ( copiedBlocks . map ( b => sb3 . getExtensionIdForOpcode ( b . opcode ) ) . filter ( id => ! ! id ) . filter ( id => ! this . extensionManager . isExtensionLoaded ( id ) ) ) ; const extensionPromises = Array . from ( extensionIDs , id => this . extensionManager . loadExtensionURL ( id ) ) ; return Promise . all ( extensionPromises ) . then ( ( ) => { copiedBlocks . forEach ( block => { target . blocks . createBlock ( block ) ; } ) ; target . blocks . updateTargetSpecificBlocks ( target . isStage ) ; } ) ; }
Called when blocks are dragged from one sprite to another.
Called when blocks are dragged from one sprite to another .
// If the blocks are being shared from another target, // resolve any possible variable conflicts that may arise. // Create a unique set of extensionIds that are not yet loaded // Remove ids that do not exist // and remove loaded extensions // Create an array promises for extensions to load