mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-28 22:10:31 -04:00
Making 'list' specifiying variable type for list blocks a constant instead of a hardcoded value. Refactoring existing code to use this new constant. Updated name of constant referring to broadcast message variable type to make it more specific/match new name convention for variable type names.
This commit is contained in:
parent
208d1892fc
commit
a16fc794c2
5 changed files with 19 additions and 11 deletions
|
@ -79,7 +79,7 @@ Blockly.Blocks['event_whenbroadcastreceived'] = {
|
|||
{
|
||||
"type": "field_variable",
|
||||
"name": "BROADCAST_OPTION",
|
||||
"variableTypes": [Blockly.BROADCAST_MESSAGE_TYPE],
|
||||
"variableTypes": [Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE],
|
||||
"variable": Blockly.Msg.DEFAULT_BROADCAST_MESSAGE_NAME
|
||||
}
|
||||
],
|
||||
|
@ -152,7 +152,7 @@ Blockly.Blocks['event_broadcast_menu'] = {
|
|||
{
|
||||
"type": "field_variable",
|
||||
"name": "BROADCAST_OPTION",
|
||||
"variableTypes":[Blockly.BROADCAST_MESSAGE_TYPE],
|
||||
"variableTypes":[Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE],
|
||||
"variable": Blockly.Msg.DEFAULT_BROADCAST_MESSAGE_NAME
|
||||
}
|
||||
],
|
||||
|
@ -177,7 +177,7 @@ Blockly.Blocks['event_broadcast'] = {
|
|||
{
|
||||
"type": "field_variable",
|
||||
"name": "BROADCAST_OPTION",
|
||||
"variableTypes": [Blockly.BROADCAST_MESSAGE_TYPE],
|
||||
"variableTypes": [Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE],
|
||||
"variable": Blockly.Msg.DEFAULT_BROADCAST_MESSAGE_NAME
|
||||
}
|
||||
],
|
||||
|
@ -199,7 +199,7 @@ Blockly.Blocks['event_broadcastandwait'] = {
|
|||
{
|
||||
"type": "field_variable",
|
||||
"name": "BROADCAST_OPTION",
|
||||
"variableTypes": [Blockly.BROADCAST_MESSAGE_TYPE],
|
||||
"variableTypes": [Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE],
|
||||
"variable": Blockly.Msg.DEFAULT_BROADCAST_MESSAGE_NAME
|
||||
}
|
||||
],
|
||||
|
|
|
@ -342,7 +342,15 @@ Blockly.NEW_BROADCAST_MESSAGE_ID = 'NEW_BROADCAST_MESSAGE_ID';
|
|||
* indicates that the current variable is a broadcast message.
|
||||
* @const {string}
|
||||
*/
|
||||
Blockly.BROADCAST_MESSAGE_TYPE = 'broadcast_msg';
|
||||
Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE = 'broadcast_msg';
|
||||
|
||||
/**
|
||||
* String representing the variable type of list blocks.
|
||||
* This string, for use in differentiating between types of variables,
|
||||
* indicates that the current variable is a list.
|
||||
* @const {string}
|
||||
*/
|
||||
Blockly.LIST_VARIABLE_TYPE = 'list';
|
||||
|
||||
/**
|
||||
* The type of all procedure definition blocks.
|
||||
|
|
|
@ -63,7 +63,7 @@ Blockly.DataCategory = function(workspace) {
|
|||
|
||||
// Now add list variables to the flyout
|
||||
Blockly.DataCategory.addCreateButton(xmlList, workspace, 'LIST');
|
||||
variableModelList = workspace.getVariablesOfType('list');
|
||||
variableModelList = workspace.getVariablesOfType(Blockly.LIST_VARIABLE_TYPE);
|
||||
variableModelList.sort(Blockly.VariableModel.compareByName);
|
||||
for (var i = 0; i < variableModelList.length; i++) {
|
||||
Blockly.DataCategory.addDataList(xmlList, variableModelList[i]);
|
||||
|
@ -359,7 +359,7 @@ Blockly.DataCategory.addCreateButton = function(xmlList, workspace, type) {
|
|||
callbackKey = 'CREATE_LIST';
|
||||
callback = function(button) {
|
||||
Blockly.Variables.createVariable(button.getTargetWorkspace(), null,
|
||||
'list');};
|
||||
Blockly.LIST_VARIABLE_TYPE);};
|
||||
}
|
||||
button.setAttribute('text', msg);
|
||||
button.setAttribute('callbackKey', callbackKey);
|
||||
|
|
|
@ -190,7 +190,7 @@ Blockly.FieldVariable.dropdownCreate = function() {
|
|||
// doesn't modify the workspace's list.
|
||||
for (var i = 0; i < variableTypes.length; i++) {
|
||||
var variableType = variableTypes[i];
|
||||
if (variableType == Blockly.BROADCAST_MESSAGE_TYPE){
|
||||
if (variableType == Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE){
|
||||
isBroadcastType = true;
|
||||
}
|
||||
var variables = workspace.getVariablesOfType(variableType);
|
||||
|
@ -261,7 +261,7 @@ Blockly.FieldVariable.prototype.onItemSelected = function(menu, menuItem) {
|
|||
var setName = function(newName) {
|
||||
thisField.setValue(newName);
|
||||
};
|
||||
Blockly.Variables.createVariable(workspace, setName, Blockly.BROADCAST_MESSAGE_TYPE);
|
||||
Blockly.Variables.createVariable(workspace, setName, Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -176,9 +176,9 @@ Blockly.Variables.createVariable = function(workspace, opt_callback, opt_type) {
|
|||
// Decide on a modal message based on the opt_type. If opt_type was not
|
||||
// provided, default to the original message for scalar variables.
|
||||
var newMsg = '';
|
||||
if (opt_type === 'list') {
|
||||
if (opt_type === Blockly.LIST_VARIABLE_TYPE) {
|
||||
newMsg = Blockly.Msg.NEW_LIST_TITLE;
|
||||
} else if (opt_type === 'broadcast_msg') {
|
||||
} else if (opt_type === Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE) {
|
||||
newMsg = Blockly.Msg.NEW_BROADCAST_MESSAGE_TITLE;
|
||||
} else {
|
||||
newMsg = Blockly.Msg.NEW_VARIABLE_TITLE;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue