kopia lustrzana https://github.com/backface/turtlestitch
Custom block inheritance, highly experimental and under construction
rodzic
c00c9267b0
commit
00e68ade1a
21
byob.js
21
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 () {
|
||||
|
|
|
@ -3349,3 +3349,7 @@ Fixes:
|
|||
170201
|
||||
------
|
||||
* GUI: let costume icons indicate svg costumes
|
||||
|
||||
170202
|
||||
------
|
||||
* Objects, BYOB: highly experimental custom block inheritance, under construction…
|
||||
|
|
68
objects.js
68
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) {
|
||||
|
|
Ładowanie…
Reference in New Issue