experimental "blockify list" feature

pull/95/head
jmoenig 2020-05-17 14:13:10 +02:00
rodzic c112d8bbd6
commit a36327842f
3 zmienionych plików z 45 dodań i 1 usunięć

Wyświetl plik

@ -148,7 +148,7 @@ CustomCommandBlockMorph, SymbolMorph, ToggleButtonMorph, DialMorph*/
// Global stuff ////////////////////////////////////////////////////////
modules.blocks = '2020-May-16';
modules.blocks = '2020-May-17';
var SyntaxElementMorph;
var BlockMorph;
@ -11060,6 +11060,7 @@ MultiArgMorph.prototype.addInput = function (contents) {
this.children.splice(idx, 0, newPart);
newPart.fixLayout();
this.fixLayout();
return newPart;
};
MultiArgMorph.prototype.removeInput = function () {

Wyświetl plik

@ -612,6 +612,43 @@ List.prototype.hasOnlyAtomicData = function () {
});
};
// List-to-block (experimental)
List.prototype.blockify = function (limit = 100) {
var block = SpriteMorph.prototype.blockForSelector('reportNewList'),
slots = block.inputs()[0],
bool,
i, len, value;
block.isDraggable = true;
slots.removeInput();
// fill the slots with the data
len = Math.min(this.length(), limit);
for (i = 0; i < len; i += 1) {
value = this.at(i + 1);
if (value instanceof List) {
slots.replaceInput(
slots.addInput(),
value.blockify(limit - i)
);
} else if (typeof value === 'boolean') {
bool = SpriteMorph.prototype.blockForSelector('reportBoolean');
bool.inputs()[0].setContents(value);
bool.isDraggable = true;
slots.replaceInput(
slots.addInput(),
bool
);
} else {
slots.addInput(value);
}
}
slots.fixBlockColor(null, true);
return block;
};
// ListWatcherMorph ////////////////////////////////////////////////////
/*

Wyświetl plik

@ -11435,6 +11435,12 @@ WatcherMorph.prototype.userMenu = function () {
null,
new Color(100, 0, 0)
);
menu.addItem( // experimental
'blockify...',
() => this.currentValue.blockify().pickUp(this.world()),
null,
new Color(100, 0, 0)
);
}
}
if (isString(this.currentValue) || !isNaN(+this.currentValue)) {