Я создаю блок и добавляю его на панель инструментов. Это мой test_blocks.ts
import * as Blockly from 'blockly';
let dynamicBlocks: { Name: string, Text: string }[] = [
{ "Name": "AIN_1", "Text": "Temperature" },
{ "Name": "AIN_2", "Text": "Pressure" },
{ "Name": "AIN_3", "Text": "Precipitation" }
];
let json: Array<object> = [];
for (let index = 0; index < dynamicBlocks.length; index++) {
console.log('tes', dynamicBlocks[index].Name)
json[index] = {
message0: ' %1 %2 ',
args0: [
{
type: 'field_label_serializable',
name: dynamicBlocks[index].Name,
text: dynamicBlocks[index].Text
},
{
type: 'input_value',
name: 'Name',
},
],
colour: 230,
tooltip: "",
helpUrl: ""
};
}
(Blockly as any).Blocks.my_custom_block_0 = {
init() {
this.jsonInit(json[0]);
}
};
(Blockly as any).Blocks.my_custom_block_1 = {
init() {
this.jsonInit(json[1]);
}
};
(Blockly as any).Blocks.my_custom_block_2 = {
init() {
this.jsonInit(json[2]);
}
};
console.log(json);
Но как мне создавать динамические блоки? И как я могу создать переменную (my_custom_block_1, my_custom_block_2, my_custom_block_3), например. И добавить в панель инструментов. Может быть, кто-то сталкивался с такой проблемой и может что-то посоветовать.