functions
This commit is contained in:
parent
3646ca84ef
commit
371b7e2fdb
2 changed files with 102 additions and 0 deletions
|
|
@ -78,6 +78,13 @@
|
|||
<block type="blocks_get" />
|
||||
<block type="blocks_return" />
|
||||
</category>
|
||||
<category name="Functions" colour="#5531D6">
|
||||
<block type="functions_create" />
|
||||
<block type="functions_return" />
|
||||
<sep gap="48"></sep>
|
||||
<block type="functions_call" />
|
||||
<block type="functions_callreporter" />
|
||||
</category>
|
||||
<category name="Debug" colour="#666666">
|
||||
<block type="debug_log" />
|
||||
<block type="debug_warn" />
|
||||
|
|
|
|||
95
src/resources/blocks/functions.js
Normal file
95
src/resources/blocks/functions.js
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
import javascriptGenerator from '../javascriptGenerator';
|
||||
import registerBlock from '../register';
|
||||
|
||||
const categoryPrefix = 'functions_';
|
||||
const categoryColor = '#5531D6';
|
||||
|
||||
function register() {
|
||||
// function
|
||||
registerBlock(`${categoryPrefix}create`, {
|
||||
message0: 'function %1 %2 %3',
|
||||
args0: [
|
||||
{
|
||||
"type": "field_input",
|
||||
"name": "ID",
|
||||
"text": "id",
|
||||
"spellcheck": false
|
||||
},
|
||||
{
|
||||
"type": "input_dummy"
|
||||
},
|
||||
{
|
||||
"type": "input_statement",
|
||||
"name": "FUNC"
|
||||
}
|
||||
],
|
||||
nextStatement: null,
|
||||
inputsInline: true,
|
||||
colour: categoryColor,
|
||||
}, (block) => {
|
||||
const ID = block.getFieldValue('ID')
|
||||
const FUNC = javascriptGenerator.statementToCode(block, 'FUNC');
|
||||
|
||||
const code = `function ${ID}() { ${FUNC} }`;
|
||||
return `${code}\n`;
|
||||
})
|
||||
|
||||
// return
|
||||
registerBlock(`${categoryPrefix}return`, {
|
||||
message0: 'return %1',
|
||||
args0: [
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "VALUE",
|
||||
}
|
||||
],
|
||||
previousStatement: null,
|
||||
inputsInline: true,
|
||||
colour: categoryColor,
|
||||
}, (block) => {
|
||||
const VALUE = javascriptGenerator.valueToCode(block, 'VALUE', javascriptGenerator.ORDER_ATOMIC);
|
||||
const code = `return ${VALUE || ''}`;
|
||||
return `${code}\n`;
|
||||
})
|
||||
|
||||
// call
|
||||
registerBlock(`${categoryPrefix}call`, {
|
||||
message0: 'call %1',
|
||||
args0: [
|
||||
{
|
||||
"type": "field_input",
|
||||
"name": "ID",
|
||||
"text": "id",
|
||||
"spellcheck": false
|
||||
},
|
||||
],
|
||||
previousStatement: null,
|
||||
nextStatement: null,
|
||||
inputsInline: true,
|
||||
colour: categoryColor,
|
||||
}, (block) => {
|
||||
const ID = block.getFieldValue('ID')
|
||||
const code = `${ID}()`;
|
||||
return `${code}\n`;
|
||||
})
|
||||
|
||||
// call
|
||||
registerBlock(`${categoryPrefix}callreporter`, {
|
||||
message0: 'call %1',
|
||||
args0: [
|
||||
{
|
||||
"type": "field_input",
|
||||
"name": "ID",
|
||||
"text": "id",
|
||||
"spellcheck": false
|
||||
},
|
||||
],
|
||||
output: null,
|
||||
inputsInline: true,
|
||||
colour: categoryColor,
|
||||
}, (block) => {
|
||||
const ID = block.getFieldValue('ID')
|
||||
return [`${ID}()\n`, javascriptGenerator.ORDER_ATOMIC];
|
||||
})
|
||||
}
|
||||
export default register;
|
||||
Loading…
Add table
Add a link
Reference in a new issue