mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 23:12:24 -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 () {
|
getBlocksXML () {
|
||||||
const xmlParts = [];
|
return this._blockInfo.map(categoryInfo => {
|
||||||
for (const categoryInfo of this._blockInfo) {
|
|
||||||
const {name, color1, color2} = categoryInfo;
|
const {name, color1, color2} = categoryInfo;
|
||||||
const paletteBlocks = categoryInfo.blocks.filter(block => !block.info.hideFromPalette);
|
const paletteBlocks = categoryInfo.blocks.filter(block => !block.info.hideFromPalette);
|
||||||
const colorXML = `colour="${color1}" secondaryColour="${color2}"`;
|
const colorXML = `colour="${color1}" secondaryColour="${color2}"`;
|
||||||
|
@ -1268,12 +1269,12 @@ class Runtime extends EventEmitter {
|
||||||
statusButtonXML = 'showStatusButton="true"';
|
statusButtonXML = 'showStatusButton="true"';
|
||||||
}
|
}
|
||||||
|
|
||||||
xmlParts.push(`<category name="${name}" id="${categoryInfo.id}"
|
return {
|
||||||
${statusButtonXML} ${colorXML} ${menuIconXML}>`);
|
id: categoryInfo.id,
|
||||||
xmlParts.push.apply(xmlParts, paletteBlocks.map(block => block.xml));
|
xml: `<category name="${name}" id="${categoryInfo.id}" ${statusButtonXML} ${colorXML} ${menuIconXML}>${
|
||||||
xmlParts.push('</category>');
|
paletteBlocks.map(block => block.xml).join('')}</category>`
|
||||||
}
|
};
|
||||||
return xmlParts.join('\n');
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue