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
28 changes: 28 additions & 0 deletions src/engine/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@
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 @@ -1583,6 +1593,22 @@
};
}

/**
* 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.variableTypes ? (Array.isArray(argInfo.variableTypes) ? argInfo.variableTypes : [argInfo.variableTypes]) : [''],

Check failure on line 1607 in src/engine/runtime.js

View workflow job for this annotation

GitHub Actions / build

This line has a length of 136. Maximum allowed is 120
variable: (argInfo.variableTypes === '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 @@ -1610,6 +1636,8 @@
// 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;
Loading