mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Merge pull request #753 from paulkaplan/provide-argument-ids
Provide argument id list with callers and procdef blocks
This commit is contained in:
commit
e2ac6947af
1 changed files with 15 additions and 1 deletions
|
@ -52,6 +52,18 @@ const parseProcedureArgMap = function (procCode) {
|
||||||
return argMap;
|
return argMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a list of "argument IDs" for procdefs and caller mutations.
|
||||||
|
* IDs just end up being `input0`, `input1`, ... which is good enough.
|
||||||
|
* @param {string} procCode Scratch 2.0 procedure string.
|
||||||
|
* @return {Array.<string>} Array of argument id strings.
|
||||||
|
*/
|
||||||
|
const parseProcedureArgIds = function (procCode) {
|
||||||
|
return parseProcedureArgMap(procCode)
|
||||||
|
.map(arg => arg.inputName)
|
||||||
|
.filter(name => name); // Filter out unnamed inputs which are labels
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flatten a block tree into a block list.
|
* Flatten a block tree into a block list.
|
||||||
* Children are temporarily stored on the `block.children` property.
|
* Children are temporarily stored on the `block.children` property.
|
||||||
|
@ -501,6 +513,7 @@ const parseBlock = function (sb2block, getVariableId) {
|
||||||
tagName: 'mutation',
|
tagName: 'mutation',
|
||||||
proccode: procData[0], // e.g., "abc %n %b %s"
|
proccode: procData[0], // e.g., "abc %n %b %s"
|
||||||
argumentnames: JSON.stringify(procData[1]), // e.g. ['arg1', 'arg2']
|
argumentnames: JSON.stringify(procData[1]), // e.g. ['arg1', 'arg2']
|
||||||
|
argumentids: JSON.stringify(parseProcedureArgIds(procData[0])),
|
||||||
argumentdefaults: JSON.stringify(procData[2]), // e.g., [1, 'abc']
|
argumentdefaults: JSON.stringify(procData[2]), // e.g., [1, 'abc']
|
||||||
warp: procData[3], // Warp mode, e.g., true/false.
|
warp: procData[3], // Warp mode, e.g., true/false.
|
||||||
children: []
|
children: []
|
||||||
|
@ -512,7 +525,8 @@ const parseBlock = function (sb2block, getVariableId) {
|
||||||
activeBlock.mutation = {
|
activeBlock.mutation = {
|
||||||
tagName: 'mutation',
|
tagName: 'mutation',
|
||||||
children: [],
|
children: [],
|
||||||
proccode: sb2block[1]
|
proccode: sb2block[1],
|
||||||
|
argumentids: JSON.stringify(parseProcedureArgIds(sb2block[1]))
|
||||||
};
|
};
|
||||||
} else if (oldOpcode === 'getParam') {
|
} else if (oldOpcode === 'getParam') {
|
||||||
// Mutation for procedure parameter.
|
// Mutation for procedure parameter.
|
||||||
|
|
Loading…
Reference in a new issue