kopia lustrzana https://github.com/backface/turtlestitch
added collecting dependencies for sprite-local custom blocks
rodzic
5ae43f4f1b
commit
defe37f9e8
|
@ -12,6 +12,7 @@
|
||||||
* new dev version
|
* new dev version
|
||||||
* byob, store, gui: export / import sprite-local custom block definitions, under construction
|
* byob, store, gui: export / import sprite-local custom block definitions, under construction
|
||||||
* byob, gui: adapted library import dialog to the new format
|
* byob, gui: adapted library import dialog to the new format
|
||||||
|
* byob: added collecting dependencies for sprite-local custom blocks
|
||||||
|
|
||||||
## 7.3.0:
|
## 7.3.0:
|
||||||
* **New Features:**
|
* **New Features:**
|
||||||
|
|
37
src/byob.js
37
src/byob.js
|
@ -595,27 +595,31 @@ CustomBlockDefinition.prototype.purgeCorpses = function () {
|
||||||
// CustomBlockDefinition dependencies
|
// CustomBlockDefinition dependencies
|
||||||
|
|
||||||
CustomBlockDefinition.prototype.collectDependencies = function (
|
CustomBlockDefinition.prototype.collectDependencies = function (
|
||||||
excluding = [],
|
excluding,
|
||||||
result = []
|
result,
|
||||||
|
localReceiver // optional when exporting sprite-local blocks
|
||||||
) {
|
) {
|
||||||
/* // +++ under construction
|
if (!this.isGlobal && !localReceiver) {
|
||||||
if (!this.isGlobal) {
|
throw new Error('cannot collect dependencies for local\n' +
|
||||||
throw new Error('collecting dependencies is only supported\n' +
|
'custom blocks of an unspecified sprite');
|
||||||
'for global custom blocks');
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
excluding.push(this);
|
excluding.push(this);
|
||||||
this.scripts.concat(
|
this.scripts.concat(
|
||||||
this.body ? [this.body.expression] : []
|
this.body ? [this.body.expression] : []
|
||||||
).forEach(script => {
|
).forEach(script => {
|
||||||
script.forAllChildren(morph => {
|
script.forAllChildren(morph => {
|
||||||
if (morph.isCustomBlock &&
|
var def;
|
||||||
morph.isGlobal &&
|
if (morph.isCustomBlock) {
|
||||||
!contains(excluding, morph.definition) &&
|
def = morph.isGlobal ? morph.definition
|
||||||
!contains(result, morph.definition)
|
: localReceiver.getMethod(morph.blockSpec);
|
||||||
) {
|
if (!contains(excluding, def) && !contains(result, def)) {
|
||||||
result.push(morph.definition);
|
result.push(def);
|
||||||
morph.definition.collectDependencies(excluding, result);
|
def.collectDependencies(
|
||||||
|
excluding,
|
||||||
|
result,
|
||||||
|
localReceiver
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1309,11 +1313,12 @@ CustomCommandBlockMorph.prototype.userMenu = function () {
|
||||||
|
|
||||||
CustomCommandBlockMorph.prototype.exportBlockDefinition = function () {
|
CustomCommandBlockMorph.prototype.exportBlockDefinition = function () {
|
||||||
var ide = this.parentThatIsA(IDE_Morph),
|
var ide = this.parentThatIsA(IDE_Morph),
|
||||||
|
rcvr = this.scriptTarget(),
|
||||||
def = this.isGlobal ? this.definition
|
def = this.isGlobal ? this.definition
|
||||||
: this.scriptTarget().getMethod(this.blockSpec);
|
: rcvr.getMethod(this.blockSpec);
|
||||||
new BlockExportDialogMorph(
|
new BlockExportDialogMorph(
|
||||||
ide.serializer,
|
ide.serializer,
|
||||||
[def].concat(def.collectDependencies()),
|
[def].concat(def.collectDependencies([], [], rcvr)),
|
||||||
ide
|
ide
|
||||||
).popUp(this.world());
|
).popUp(this.world());
|
||||||
};
|
};
|
||||||
|
|
Ładowanie…
Reference in New Issue