mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Prepend icon to each extension block
This commit is contained in:
parent
a115d47bb8
commit
2ac464c53e
1 changed files with 15 additions and 1 deletions
|
@ -421,6 +421,7 @@ class Runtime extends EventEmitter {
|
|||
const categoryInfo = {
|
||||
id: extensionInfo.id,
|
||||
name: extensionInfo.name,
|
||||
iconURI: extensionInfo.iconURI,
|
||||
color1: '#FF6680',
|
||||
color2: '#FF4D6A',
|
||||
color3: '#FF3355',
|
||||
|
@ -524,8 +525,21 @@ class Runtime extends EventEmitter {
|
|||
// but each `[ARG]` will need to be replaced with the number in this map instead of `args0.length`.
|
||||
const argsMap = {};
|
||||
|
||||
blockJSON.message0 = blockInfo.text.replace(/\[(.+?)]/g, (match, placeholder) => {
|
||||
blockJSON.message0 = '';
|
||||
|
||||
// If an icon for the extension exists, prepend it to each block
|
||||
if (categoryInfo.iconURI) {
|
||||
blockJSON.message0 = '%1';
|
||||
const iconJSON = {
|
||||
type: 'field_image',
|
||||
src: categoryInfo.iconURI,
|
||||
width: 40,
|
||||
height: 40
|
||||
};
|
||||
blockJSON.args0.push(iconJSON);
|
||||
}
|
||||
|
||||
blockJSON.message0 += blockInfo.text.replace(/\[(.+?)]/g, (match, placeholder) => {
|
||||
// Sanitize the placeholder to ensure valid XML
|
||||
placeholder = placeholder.replace(/[<"&]/, '_');
|
||||
|
||||
|
|
Loading…
Reference in a new issue