From defe37f9e868c16be6eddbe2dfde6293be200b6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20M=C3=B6nig?= Date: Wed, 9 Mar 2022 19:23:24 +0100 Subject: [PATCH] added collecting dependencies for sprite-local custom blocks --- HISTORY.md | 1 + src/byob.js | 37 +++++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index d249deae..21fdb984 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -12,6 +12,7 @@ * new dev version * byob, store, gui: export / import sprite-local custom block definitions, under construction * byob, gui: adapted library import dialog to the new format +* byob: added collecting dependencies for sprite-local custom blocks ## 7.3.0: * **New Features:** diff --git a/src/byob.js b/src/byob.js index 6c39f100..95b0cccf 100644 --- a/src/byob.js +++ b/src/byob.js @@ -595,27 +595,31 @@ CustomBlockDefinition.prototype.purgeCorpses = function () { // CustomBlockDefinition dependencies CustomBlockDefinition.prototype.collectDependencies = function ( - excluding = [], - result = [] + excluding, + result, + localReceiver // optional when exporting sprite-local blocks ) { -/* // +++ under construction - if (!this.isGlobal) { - throw new Error('collecting dependencies is only supported\n' + - 'for global custom blocks'); + if (!this.isGlobal && !localReceiver) { + throw new Error('cannot collect dependencies for local\n' + + 'custom blocks of an unspecified sprite'); } -*/ excluding.push(this); this.scripts.concat( this.body ? [this.body.expression] : [] ).forEach(script => { script.forAllChildren(morph => { - if (morph.isCustomBlock && - morph.isGlobal && - !contains(excluding, morph.definition) && - !contains(result, morph.definition) - ) { - result.push(morph.definition); - morph.definition.collectDependencies(excluding, result); + var def; + if (morph.isCustomBlock) { + def = morph.isGlobal ? morph.definition + : localReceiver.getMethod(morph.blockSpec); + if (!contains(excluding, def) && !contains(result, def)) { + result.push(def); + def.collectDependencies( + excluding, + result, + localReceiver + ); + } } }); }); @@ -1309,11 +1313,12 @@ CustomCommandBlockMorph.prototype.userMenu = function () { CustomCommandBlockMorph.prototype.exportBlockDefinition = function () { var ide = this.parentThatIsA(IDE_Morph), + rcvr = this.scriptTarget(), def = this.isGlobal ? this.definition - : this.scriptTarget().getMethod(this.blockSpec); + : rcvr.getMethod(this.blockSpec); new BlockExportDialogMorph( ide.serializer, - [def].concat(def.collectDependencies()), + [def].concat(def.collectDependencies([], [], rcvr)), ide ).popUp(this.world()); };