Custom block inheritance, highly experimental and under construction

upd4.1
Jens Mönig 2017-02-02 12:00:47 +01:00
rodzic c00c9267b0
commit 00e68ade1a
3 zmienionych plików z 63 dodań i 30 usunięć

21
byob.js
Wyświetl plik

@ -108,7 +108,7 @@ BooleanSlotMorph*/
// Global stuff //////////////////////////////////////////////////////// // Global stuff ////////////////////////////////////////////////////////
modules.byob = '2017-January-24'; modules.byob = '2017-February-02';
// Declarations // Declarations
@ -734,7 +734,7 @@ CustomCommandBlockMorph.prototype.mouseClickLeft = function () {
}; };
CustomCommandBlockMorph.prototype.edit = function () { CustomCommandBlockMorph.prototype.edit = function () {
var myself = this, editor, block, hat; var myself = this, editor, block, hat, rcvr;
if (this.isPrototype) { if (this.isPrototype) {
block = this.definition.blockInstance(); block = this.definition.blockInstance();
@ -759,6 +759,16 @@ CustomCommandBlockMorph.prototype.edit = function () {
myself.isInUse() myself.isInUse()
); );
} else { } 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; Morph.prototype.trackChanges = false;
editor = new BlockEditorMorph(this.definition, this.receiver()); editor = new BlockEditorMorph(this.definition, this.receiver());
editor.popUp(); editor.popUp();
@ -932,16 +942,17 @@ CustomCommandBlockMorph.prototype.exportBlockDefinition = function () {
}; };
CustomCommandBlockMorph.prototype.duplicateBlockDefinition = 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); ide = this.parentThatIsA(IDE_Morph);
if (this.definition.isGlobal) { if (this.definition.isGlobal) {
ide.stage.globalBlocks.push(dup); ide.stage.globalBlocks.push(dup);
} else { } else {
this.definition.receiver.customBlocks.push(dup); rcvr.customBlocks.push(dup);
} }
ide.flushPaletteCache(); ide.flushPaletteCache();
ide.refreshPalette(); ide.refreshPalette();
new BlockEditorMorph(dup, this.definition.receiver).popUp(); new BlockEditorMorph(dup, rcvr).popUp();
}; };
CustomCommandBlockMorph.prototype.deleteBlockDefinition = function () { CustomCommandBlockMorph.prototype.deleteBlockDefinition = function () {

Wyświetl plik

@ -3349,3 +3349,7 @@ Fixes:
170201 170201
------ ------
* GUI: let costume icons indicate svg costumes * GUI: let costume icons indicate svg costumes
170202
------
* Objects, BYOB: highly experimental custom block inheritance, under construction…

Wyświetl plik

@ -82,7 +82,7 @@ SpeechBubbleMorph, RingMorph, isNil, FileReader, TableDialogMorph,
BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize, BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize,
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph*/ TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph*/
modules.objects = '2017-January-27'; modules.objects = '2017-February-02';
var SpriteMorph; var SpriteMorph;
var StageMorph; 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 //layout
palette.scrollX(palette.padding); palette.scrollX(palette.padding);
@ -4422,6 +4444,25 @@ SpriteMorph.prototype.reportThreadCount = function () {
return 0; 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 variable watchers (for palette checkbox toggling)
SpriteMorph.prototype.findVariableWatcher = function (varName) { SpriteMorph.prototype.findVariableWatcher = function (varName) {
@ -4887,29 +4928,8 @@ SpriteMorph.prototype.hasSpriteVariable = function (varName) {
return contains(this.variables.names(), 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 // SpriteMorph inheritance - custom blocks
// under construction
/*
// under construction, commented out for now
SpriteMorph.prototype.ownBlocks = function () { SpriteMorph.prototype.ownBlocks = function () {
var dict = {}; var dict = {};
@ -4951,8 +4971,6 @@ SpriteMorph.prototype.inheritedBlocks = function (valuesOnly) {
return dict; return dict;
}; };
*/
// SpriteMorph thumbnail // SpriteMorph thumbnail
SpriteMorph.prototype.thumbnail = function (extentPoint) { SpriteMorph.prototype.thumbnail = function (extentPoint) {