From 00e68ade1afcc2a0a95341441673870be1d8f61d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20M=C3=B6nig?= Date: Thu, 2 Feb 2017 12:00:47 +0100 Subject: [PATCH] Custom block inheritance, highly experimental and under construction --- byob.js | 21 +++++++++++++---- history.txt | 4 ++++ objects.js | 68 +++++++++++++++++++++++++++++++++-------------------- 3 files changed, 63 insertions(+), 30 deletions(-) diff --git a/byob.js b/byob.js index b91c9e8a..64cc7965 100644 --- a/byob.js +++ b/byob.js @@ -108,7 +108,7 @@ BooleanSlotMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.byob = '2017-January-24'; +modules.byob = '2017-February-02'; // Declarations @@ -734,7 +734,7 @@ CustomCommandBlockMorph.prototype.mouseClickLeft = function () { }; CustomCommandBlockMorph.prototype.edit = function () { - var myself = this, editor, block, hat; + var myself = this, editor, block, hat, rcvr; if (this.isPrototype) { block = this.definition.blockInstance(); @@ -759,6 +759,16 @@ CustomCommandBlockMorph.prototype.edit = function () { myself.isInUse() ); } else { + // checking for custom block inheritance, highly experimental + rcvr = this.receiver(); + if (rcvr && contains( + Object.keys(rcvr.inheritedBlocks()), + this.definition.blockSpec() + ) + ) { + this.duplicateBlockDefinition(); + return; + } Morph.prototype.trackChanges = false; editor = new BlockEditorMorph(this.definition, this.receiver()); editor.popUp(); @@ -932,16 +942,17 @@ CustomCommandBlockMorph.prototype.exportBlockDefinition = function () { }; CustomCommandBlockMorph.prototype.duplicateBlockDefinition = function () { - var dup = this.definition.copyAndBindTo(this.receiver), + var rcvr = this.receiver(), + dup = this.definition.copyAndBindTo(rcvr), ide = this.parentThatIsA(IDE_Morph); if (this.definition.isGlobal) { ide.stage.globalBlocks.push(dup); } else { - this.definition.receiver.customBlocks.push(dup); + rcvr.customBlocks.push(dup); } ide.flushPaletteCache(); ide.refreshPalette(); - new BlockEditorMorph(dup, this.definition.receiver).popUp(); + new BlockEditorMorph(dup, rcvr).popUp(); }; CustomCommandBlockMorph.prototype.deleteBlockDefinition = function () { diff --git a/history.txt b/history.txt index 99171a06..8816d23d 100755 --- a/history.txt +++ b/history.txt @@ -3349,3 +3349,7 @@ Fixes: 170201 ------ * GUI: let costume icons indicate svg costumes + +170202 +------ +* Objects, BYOB: highly experimental custom block inheritance, under construction… diff --git a/objects.js b/objects.js index 1b1b38f1..b2026d2f 100644 --- a/objects.js +++ b/objects.js @@ -82,7 +82,7 @@ SpeechBubbleMorph, RingMorph, isNil, FileReader, TableDialogMorph, BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize, TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph*/ -modules.objects = '2017-January-27'; +modules.objects = '2017-February-02'; var SpriteMorph; var StageMorph; @@ -2417,6 +2417,28 @@ SpriteMorph.prototype.freshPalette = function (category) { } }); + // inherited custom blocks: (under construction...) + // y += unit * 1.6; + if (this.exemplar) { + this.inheritedBlocks(true).forEach(function (definition) { + var block; + if (definition.category === category || + (category === 'variables' + && contains( + ['lists', 'other'], + definition.category + ))) { + block = definition.templateInstance(); + y += unit * 0.3; + block.setPosition(new Point(x, y)); + palette.addContents(block); + block.ghost(); + x = 0; + y += block.height(); + } + }); + } + //layout palette.scrollX(palette.padding); @@ -4422,6 +4444,25 @@ SpriteMorph.prototype.reportThreadCount = function () { return 0; }; +// SpriteMorph variable refactoring + +SpriteMorph.prototype.refactorVariableInstances = function ( + oldName, + newName, + isGlobal +) { + if (isGlobal && this.hasSpriteVariable(oldName)) { + return; + } + + this.scripts.children.forEach(function (child) { + if (child instanceof BlockMorph) { + child.refactorVarInStack(oldName, newName); + } + }); + +}; + // SpriteMorph variable watchers (for palette checkbox toggling) SpriteMorph.prototype.findVariableWatcher = function (varName) { @@ -4887,29 +4928,8 @@ SpriteMorph.prototype.hasSpriteVariable = function (varName) { return contains(this.variables.names(), varName); }; -// Variable refactoring - -SpriteMorph.prototype.refactorVariableInstances = function ( - oldName, - newName, - isGlobal -) { - if (isGlobal && this.hasSpriteVariable(oldName)) { - return; - } - - this.scripts.children.forEach(function (child) { - if (child instanceof BlockMorph) { - child.refactorVarInStack(oldName, newName); - } - }); - -}; - // SpriteMorph inheritance - custom blocks - -/* -// under construction, commented out for now +// under construction SpriteMorph.prototype.ownBlocks = function () { var dict = {}; @@ -4951,8 +4971,6 @@ SpriteMorph.prototype.inheritedBlocks = function (valuesOnly) { return dict; }; -*/ - // SpriteMorph thumbnail SpriteMorph.prototype.thumbnail = function (extentPoint) {