From 99e1b242852102b04b1f4a5ee79402d0cc3e0304 Mon Sep 17 00:00:00 2001 From: Ray Schamp Date: Tue, 14 Feb 2017 17:06:16 -0500 Subject: [PATCH] Add rudimentary toolbox filtering method --- src/virtual-machine.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/virtual-machine.js b/src/virtual-machine.js index 003c80e9f..52616e7c2 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -336,4 +336,23 @@ VirtualMachine.prototype.postSpriteInfo = function (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;