From 5b9d4ae23e6da83663d2f34dc986db2d9dd49e70 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Thu, 2 Nov 2017 17:03:12 -0400 Subject: [PATCH 1/2] Provide argument id list with callers and procdef blocks --- src/serialization/sb2.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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. From 007fe2ed53892ba4de9472ca2a8c8f465243846d Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Thu, 2 Nov 2017 17:14:00 -0400 Subject: [PATCH 2/2] Fix linting --- src/serialization/sb2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/serialization/sb2.js b/src/serialization/sb2.js index c56479aae..092bdfc9e 100644 --- a/src/serialization/sb2.js +++ b/src/serialization/sb2.js @@ -62,7 +62,7 @@ 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.