Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ArgumentType.VARIABLE and ArgumentType.BROADCAST #178

Closed
wants to merge 12 commits into from
27 changes: 27 additions & 0 deletions src/engine/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ const ArgumentTypeMap = (() => {
fieldName: 'SOUND_MENU'
}
};
map[ArgumentType.VARIABLE] = {
fieldType: 'field_variable',
fieldName: 'VARIABLE'
};
map[ArgumentType.BROADCAST] = {
shadow: {
type: 'event_broadcast_menu',
fieldName: 'BROADCAST_OPTION'
}
};
return map;
})();

Expand Down Expand Up @@ -1532,6 +1542,21 @@ class Runtime extends EventEmitter {
};
}

/**
* Helper for _convertPlaceholdes which handles variable fields which are a specialized case of block "arguments".
* @param {object} argInfo Metadata about the inline image as specified by the extension
* @return {object} JSON blob for a scratch-blocks variable field.
* @private
*/
_constructVariableJson (argInfo, placeholder) {
return {
type: 'field_variable',
name: placeholder,
variableTypes: [argInfo.variableType] ?? [''],
LilyMakesThings marked this conversation as resolved.
Show resolved Hide resolved
variable: (argInfo.variableType === 'broadcast_msg') ? 'message1' : null
};
}

/**
* Helper for _convertForScratchBlocks which handles linearization of argument placeholders. Called as a callback
* from string#replace. In addition to the return value the JSON and XML items in the context will be filled.
Expand Down Expand Up @@ -1559,6 +1584,8 @@ class Runtime extends EventEmitter {
// check if this is not one of those cases. E.g. an inline image on a block.
if (argTypeInfo.fieldType === 'field_image') {
argJSON = this._constructInlineImageJson(argInfo);
} else if (argTypeInfo.fieldType === 'field_variable') {
argJSON = this._constructVariableJson(argInfo, placeholder);
} else {
// Construct input value

Expand Down
13 changes: 12 additions & 1 deletion src/extension-support/argument-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,18 @@ const ArgumentType = {
/**
* Name of sound in the current target
*/
SOUND: 'sound'
SOUND: 'sound',

/**
* Name of variable in the current target
* (Can be a list of variables, lists, and broadcasts)
*/
VARIABLE: 'variable',

/**
* Name of broadcast in the project
*/
BROADCAST: 'broadcast'
};

module.exports = ArgumentType;