Add rudimentary toolbox filtering method

This commit is contained in:
Ray Schamp 2017-02-14 17:06:16 -05:00
parent 370f2c6a47
commit 99e1b24285

View file

@ -336,4 +336,23 @@ VirtualMachine.prototype.postSpriteInfo = function (data) {
this.editingTarget.postSpriteInfo(data); this.editingTarget.postSpriteInfo(data);
}; };
VirtualMachine.prototype.filterToolbox = function (toolboxDOM) {
var filteredToolbox = toolboxDOM.cloneNode();
var category = toolboxDOM.firstElementChild;
while (category) {
var filteredCategory = category.cloneNode();
var block = category.firstElementChild;
while (block) {
var opcode = block.getAttribute('type');
if (opcode in this.runtime._primitives || opcode in this.runtime._hats) {
filteredCategory.appendChild(block.cloneNode(true));
}
block = block.nextElementSibling;
}
if (filteredCategory.hasChildNodes()) filteredToolbox.appendChild(filteredCategory);
category = category.nextElementSibling;
}
return filteredToolbox;
};
module.exports = VirtualMachine; module.exports = VirtualMachine;