diff --git a/src/serialization/sb2.js b/src/serialization/sb2.js index 5225614a4..c56479aae 100644 --- a/src/serialization/sb2.js +++ b/src/serialization/sb2.js @@ -52,6 +52,18 @@ const parseProcedureArgMap = function (procCode) { 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.} 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. * Children are temporarily stored on the `block.children` property. @@ -501,6 +513,7 @@ const parseBlock = function (sb2block, getVariableId) { tagName: 'mutation', proccode: procData[0], // e.g., "abc %n %b %s" argumentnames: JSON.stringify(procData[1]), // e.g. ['arg1', 'arg2'] + argumentids: JSON.stringify(parseProcedureArgIds(procData[0])), argumentdefaults: JSON.stringify(procData[2]), // e.g., [1, 'abc'] warp: procData[3], // Warp mode, e.g., true/false. children: [] @@ -512,7 +525,8 @@ const parseBlock = function (sb2block, getVariableId) { activeBlock.mutation = { tagName: 'mutation', children: [], - proccode: sb2block[1] + proccode: sb2block[1], + argumentids: JSON.stringify(parseProcedureArgIds(sb2block[1])) }; } else if (oldOpcode === 'getParam') { // Mutation for procedure parameter.