mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-28 22:30:40 -04:00
Remove filter toolbox utility (#496)
* Revert "Merge pull request #486 from rschamp/fix-filter-tests" This reverts commitba00db897f
, reversing changes made to739c5deb63
. * Revert "Show Categories that use custom code to load (variables, procedures) (#483)" This reverts commit739c5deb63
. * Revert "Merge pull request #461 from rschamp/filter-toolbox" This reverts commit343b5bfe8e
, reversing changes made to370f2c6a47
.
This commit is contained in:
parent
2ebb112d30
commit
b03768cad6
7 changed files with 0 additions and 940 deletions
|
@ -59,11 +59,6 @@ window.onload = function () {
|
|||
});
|
||||
window.workspace = workspace;
|
||||
|
||||
// Filter available blocks
|
||||
var toolbox = vm.filterToolbox(workspace.options.languageTree);
|
||||
// var toolbox = workspace.options.languageTree;
|
||||
workspace.updateToolbox(toolbox);
|
||||
|
||||
// Attach scratch-blocks events to VM.
|
||||
workspace.addChangeListener(vm.blockListener);
|
||||
var flyoutWorkspace = workspace.getFlyout().getWorkspace();
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
/**
|
||||
* Filter Blockly toolbox XML node containing blocks to only those with
|
||||
* valid opcodes. Return a copy of the node with valid blocks.
|
||||
* @param {HTMLElement} node Blockly toolbox XML node
|
||||
* @param {Array.<string>} opcodes Valid opcodes. Blocks producing other opcodes
|
||||
* will be filtered.
|
||||
* @returns {HTMLElement} filtered toolbox XML node
|
||||
*/
|
||||
var filterToolboxNode = function (node, opcodes) {
|
||||
var filteredCategory = node.cloneNode();
|
||||
for (var block = node.firstElementChild; block; block = block.nextElementSibling) {
|
||||
if (block.nodeName.toLowerCase() !== 'block') continue;
|
||||
var opcode = block.getAttribute('type').toLowerCase();
|
||||
if (opcodes.indexOf(opcode) !== -1) {
|
||||
filteredCategory.appendChild(block.cloneNode(true));
|
||||
}
|
||||
}
|
||||
return filteredCategory;
|
||||
};
|
||||
|
||||
/**
|
||||
* Filter Blockly toolbox XML and return a copy which only contains blocks with
|
||||
* existent opcodes. Categories with no valid children will be removed.
|
||||
* @param {HTMLElement} toolbox Blockly toolbox XML node
|
||||
* @param {Array.<string>} opcodes Valid opcodes. Blocks producing other opcodes
|
||||
* will be filtered.
|
||||
* @returns {HTMLElement} filtered toolbox XML node
|
||||
*/
|
||||
var filterToolbox = function (toolbox, opcodes) {
|
||||
if (!toolbox.hasChildNodes()) return toolbox;
|
||||
var filteredToolbox;
|
||||
if (toolbox.firstElementChild.nodeName.toLowerCase() === 'category') {
|
||||
filteredToolbox = toolbox.cloneNode();
|
||||
for (
|
||||
var category = toolbox.firstElementChild;
|
||||
category;
|
||||
category = category.nextElementSibling
|
||||
) {
|
||||
if (category.nodeName.toLowerCase() !== 'category') continue;
|
||||
var filteredCategory = filterToolboxNode(category, opcodes);
|
||||
if (filteredCategory.hasChildNodes() ||
|
||||
filteredCategory.hasAttribute('custom')
|
||||
) {
|
||||
filteredToolbox.appendChild(filteredCategory);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
filteredToolbox = filterToolboxNode(toolbox, opcodes);
|
||||
}
|
||||
return filteredToolbox;
|
||||
};
|
||||
|
||||
module.exports = filterToolbox;
|
|
@ -1,7 +1,6 @@
|
|||
var EventEmitter = require('events');
|
||||
var util = require('util');
|
||||
|
||||
var filterToolbox = require('./util/filter-toolbox');
|
||||
var Runtime = require('./engine/runtime');
|
||||
var sb2import = require('./import/sb2import');
|
||||
|
||||
|
@ -372,17 +371,4 @@ VirtualMachine.prototype.postSpriteInfo = function (data) {
|
|||
this.editingTarget.postSpriteInfo(data);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Filter Blockly toolbox XML and return a copy which only contains blocks with
|
||||
* existent opcodes. Categories with no valid children will be removed.
|
||||
* @param {HTMLElement} toolbox Blockly toolbox XML node
|
||||
* @returns {HTMLElement} filtered toolbox XML node
|
||||
*/
|
||||
VirtualMachine.prototype.filterToolbox = function (toolbox) {
|
||||
var opcodes = Object.keys(this.runtime._primitives)
|
||||
.concat(Object.keys(this.runtime._hats));
|
||||
return filterToolbox(toolbox, opcodes);
|
||||
};
|
||||
|
||||
module.exports = VirtualMachine;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue