rebind (relabel) recursive calls when duplicating a custom block definition

pull/95/head
jmoenig 2021-03-05 11:59:22 +01:00
rodzic ab09e949c5
commit 8f5a166f01
3 zmienionych plików z 22 dodań i 3 usunięć

Wyświetl plik

@ -6,6 +6,7 @@
* undelete sprites
* **Notable Changes:**
* optimized special cases for COMBINE (sum, product, min, max) by up to 34 x
* rebind (relabel) recursive calls when duplicating a custom block definition
* custom block label parts inside the prototype (in the block editor) are now displayed the same as in block instances
* variadic ring inputs are now arranged vertically (e.g. the reporter rings in PIPE)
* changed zebra-coloring for yellow custom block prototypes (in the block editor) so the hat block changes the shade, not the prototype
@ -21,6 +22,7 @@
* gui: added "trash is empty" information, commented out for now
* gui: changed gui strings for undelete feature
* updated German translation
* byob: rebind (relabel) recursive calls when duplicating a custom block definition
### 2021-03-04
* gui: added trash button for undeleting sprites

Wyświetl plik

@ -14,7 +14,7 @@
<script src="src/gui.js?version=2021-03-05"></script>
<script src="src/paint.js?version=2020-05-17"></script>
<script src="src/lists.js?version=2021-02-20"></script>
<script src="src/byob.js?version=2021-03-01"></script>
<script src="src/byob.js?version=2021-03-05"></script>
<script src="src/tables.js?version=2021-03-05"></script>
<script src="src/sketch.js?version=2020-07-13"></script>
<script src="src/video.js?version=2019-06-27"></script>

Wyświetl plik

@ -106,7 +106,7 @@ WatcherMorph, XML_Serializer, SnapTranslator*/
// Global stuff ////////////////////////////////////////////////////////
modules.byob = '2021-March-01';
modules.byob = '2021-March-05';
// Declarations
@ -1255,8 +1255,18 @@ CustomCommandBlockMorph.prototype.duplicateBlockDefinition = function () {
def = this.isGlobal ? this.definition : rcvr.getMethod(this.blockSpec),
dup = def.copyAndBindTo(rcvr),
spec = dup.spec,
exp = dup.body.expression,
count = 1;
function rebindRecursiveCalls(topBlock) {
topBlock.forAllChildren(morph => {
if (morph.definition === def) {
morph.definition = dup;
morph.refresh();
}
});
}
if (this.isGlobal) {
ide.stage.globalBlocks.push(dup);
} else {
@ -1269,6 +1279,13 @@ CustomCommandBlockMorph.prototype.duplicateBlockDefinition = function () {
dup.spec = spec + ' (' + count + ')';
}
// rebind recursive calls
dup.scripts.forEach(script => rebindRecursiveCalls(script));
if (exp instanceof BlockMorph) {
rebindRecursiveCalls(exp);
}
ide.flushPaletteCache();
ide.refreshPalette();
ide.recordUnsavedChanges();