mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-28 22:30:40 -04:00
Update to use explicit procedure names and ids
This commit is contained in:
parent
80b4dab104
commit
5a53323715
4 changed files with 12 additions and 11 deletions
|
@ -27,7 +27,7 @@ class Scratch3ProcedureBlocks {
|
|||
call (args, util) {
|
||||
if (!util.stackFrame.executed) {
|
||||
const procedureCode = args.mutation.proccode;
|
||||
const paramNames = util.getProcedureParamNames(procedureCode);
|
||||
const [paramNames, paramIds] = util.getProcedureParamNamesAndIds(procedureCode);
|
||||
|
||||
// If null, procedure could not be found, which can happen if custom
|
||||
// block is dragged between sprites without the definition.
|
||||
|
@ -36,9 +36,9 @@ class Scratch3ProcedureBlocks {
|
|||
return;
|
||||
}
|
||||
|
||||
for (let i = 0; i < paramNames.length; i++) {
|
||||
if (args.hasOwnProperty(`input${i}`)) {
|
||||
util.pushParam(paramNames[i], args[`input${i}`]);
|
||||
for (let i = 0; i < paramIds.length; i++) {
|
||||
if (args.hasOwnProperty(paramIds[i])) {
|
||||
util.pushParam(paramNames[i], args[paramIds[i]]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -97,8 +97,8 @@ class BlockUtility {
|
|||
* @param {string} procedureCode Procedure code for procedure to query.
|
||||
* @return {Array.<string>} List of param names for a procedure.
|
||||
*/
|
||||
getProcedureParamNames (procedureCode) {
|
||||
return this.thread.target.blocks.getProcedureParamNames(procedureCode);
|
||||
getProcedureParamNamesAndIds (procedureCode) {
|
||||
return this.thread.target.blocks.getProcedureParamNamesAndIds(procedureCode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -206,7 +206,7 @@ class Blocks {
|
|||
* @param {?string} name Name of procedure to query.
|
||||
* @return {?Array.<string>} List of param names for a procedure.
|
||||
*/
|
||||
getProcedureParamNames (name) {
|
||||
getProcedureParamNamesAndIds (name) {
|
||||
const cachedNames = this._cache.procedureParamNames[name];
|
||||
if (typeof cachedNames !== 'undefined') {
|
||||
return cachedNames;
|
||||
|
@ -217,9 +217,10 @@ class Blocks {
|
|||
const block = this._blocks[id];
|
||||
if (block.opcode === 'procedures_prototype' &&
|
||||
block.mutation.proccode === name) {
|
||||
const paramNames = JSON.parse(block.mutation.argumentnames);
|
||||
this._cache.procedureParamNames[name] = paramNames;
|
||||
return paramNames;
|
||||
const names = JSON.parse(block.mutation.argumentnames);
|
||||
const ids = JSON.parse(block.mutation.argumentids);
|
||||
this._cache.procedureParamNames[name] = [names, ids];
|
||||
return this._cache.procedureParamNames[name];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ test('calling a custom block with no definition does not throw', t => {
|
|||
}
|
||||
};
|
||||
const util = {
|
||||
getProcedureParamNames: () => null,
|
||||
getProcedureParamNamesAndIds: () => null,
|
||||
stackFrame: {
|
||||
executed: false
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue