mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
adjust getBlocksXML to return categories separately
before: getBlocksXML returns one big XML string after: getBlocksXML returns an array of {id,xml}, one entry per category
This commit is contained in:
parent
0247447792
commit
107e49245f
1 changed files with 10 additions and 9 deletions
|
@ -1243,11 +1243,12 @@ class Runtime extends EventEmitter {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} scratch-blocks XML description for all dynamic blocks, wrapped in <category> elements.
|
||||
* @returns {Array.<object>} scratch-blocks XML for each category of extension blocks, in category order.
|
||||
* @property {string} id - the category / extension ID
|
||||
* @property {string} xml - the XML text for this category, starting with `<category>` and ending with `</category>`
|
||||
*/
|
||||
getBlocksXML () {
|
||||
const xmlParts = [];
|
||||
for (const categoryInfo of this._blockInfo) {
|
||||
return this._blockInfo.map(categoryInfo => {
|
||||
const {name, color1, color2} = categoryInfo;
|
||||
const paletteBlocks = categoryInfo.blocks.filter(block => !block.info.hideFromPalette);
|
||||
const colorXML = `colour="${color1}" secondaryColour="${color2}"`;
|
||||
|
@ -1268,12 +1269,12 @@ class Runtime extends EventEmitter {
|
|||
statusButtonXML = 'showStatusButton="true"';
|
||||
}
|
||||
|
||||
xmlParts.push(`<category name="${name}" id="${categoryInfo.id}"
|
||||
${statusButtonXML} ${colorXML} ${menuIconXML}>`);
|
||||
xmlParts.push.apply(xmlParts, paletteBlocks.map(block => block.xml));
|
||||
xmlParts.push('</category>');
|
||||
}
|
||||
return xmlParts.join('\n');
|
||||
return {
|
||||
id: categoryInfo.id,
|
||||
xml: `<category name="${name}" id="${categoryInfo.id}" ${statusButtonXML} ${colorXML} ${menuIconXML}>${
|
||||
paletteBlocks.map(block => block.xml).join('')}</category>`
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue