BYOB: new scriptsPicture() method for custom block definitions

pull/3/merge
jmoenig 2014-06-04 12:40:03 +02:00
rodzic ef3997cccf
commit 50203901ea
1 zmienionych plików z 38 dodań i 1 usunięć

39
byob.js
Wyświetl plik

@ -106,7 +106,7 @@ SymbolMorph, isNil*/
// Global stuff ////////////////////////////////////////////////////////
modules.byob = '2014-May-02';
modules.byob = '2014-Jun-04';
// Declarations
@ -336,6 +336,43 @@ CustomBlockDefinition.prototype.parseSpec = function (spec) {
return parts;
};
// CustomBlockDefinition picturing
CustomBlockDefinition.prototype.scriptsPicture = function () {
var scripts, proto, block, comment;
scripts = new ScriptsMorph();
scripts.cleanUpMargin = 10;
proto = new PrototypeHatBlockMorph(this);
proto.setPosition(scripts.position().add(10));
if (this.comment !== null) {
comment = this.comment.fullCopy();
proto.comment = comment;
comment.block = proto;
}
if (this.body !== null) {
proto.nextBlock(this.body.expression.fullCopy());
}
scripts.add(proto);
proto.fixBlockColor(null, true);
this.scripts.forEach(function (element) {
block = element.fullCopy();
block.setPosition(scripts.position().add(element.position()));
scripts.add(block);
if (block instanceof BlockMorph) {
block.allComments().forEach(function (comment) {
comment.align(block);
});
}
});
proto.allComments().forEach(function (comment) {
comment.align(proto);
});
proto.children[0].fixLayout();
scripts.fixMultiArgs();
return scripts.scriptsPicture();
};
// CustomCommandBlockMorph /////////////////////////////////////////////
// CustomCommandBlockMorph inherits from CommandBlockMorph: