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

JSON: "Set list to array" block (SB) #25

Merged
merged 5 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions blocks_vertical/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,33 @@ Blockly.Blocks['data_replaceitemoflist'] = {
}
};


Blockly.Blocks['data_setlist'] = {
/**
* Block to insert item to list.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.DATA_SETLIST,
"args0": [
{
"type": "field_variable",
"name": "LIST",
"variableTypes": [Blockly.LIST_VARIABLE_TYPE]
},
{
"type": "input_value",
"name": "ARRAY",
"check": "Array"
}
],
"category": Blockly.Categories.dataLists,
"extensions": ["colours_data_lists", "shape_statement"]
});
}
};

Blockly.Blocks['data_itemoflist'] = {
/**
* Block for reporting item of list.
Expand Down
14 changes: 14 additions & 0 deletions core/data_category.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Blockly.DataCategory = function(workspace) {
// Blockly.DataCategory.addDeleteAllOfList(xmlList, firstVariable);
Blockly.DataCategory.addInsertAtList(xmlList, firstVariable);
Blockly.DataCategory.addReplaceItemOfList(xmlList, firstVariable);
Blockly.DataCategory.addSetList(xmlList, firstVariable);
Blockly.DataCategory.addSep(xmlList);
Blockly.DataCategory.addItemOfList(xmlList, firstVariable);
Blockly.DataCategory.addItemNumberOfList(xmlList, firstVariable);
Expand Down Expand Up @@ -310,6 +311,16 @@ Blockly.DataCategory.addReplaceItemOfList = function(xmlList, variable) {
'LIST', ['INDEX', 'data_listindexrandom', 1], ['ITEM', 'text', Blockly.Msg.DEFAULT_LIST_ITEM]);
};

/**
* Construct and add a data_setlist block to xmlList.
* @param {!Array.<!Element>} xmlList Array of XML block elements.
* @param {?Blockly.VariableModel} variable Variable to select in the field.
*/
Blockly.DataCategory.addSetList = function(xmlList, variable) {
Blockly.DataCategory.addBlock(xmlList, variable, 'data_setlist',
'LIST', 'ARRAY');
};

/**
* Construct and add a data_itemoflist block to xmlList.
* @param {!Array.<!Element>} xmlList Array of XML block elements.
Expand Down Expand Up @@ -476,6 +487,9 @@ Blockly.DataCategory.addBlock = function(xmlList, variable, blockType,
*/
Blockly.DataCategory.createValue = function(valueName, type, value) {
var fieldName;
if (valueName === 'ARRAY') {
return '<value name="' + valueName + '"></value>';
}
switch (valueName) {
case 'ITEM':
fieldName = 'TEXT';
Expand Down
1 change: 1 addition & 0 deletions msg/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Blockly.Msg.DATA_DELETEOFLIST = 'delete %1 of %2';
Blockly.Msg.DATA_DELETEALLOFLIST = 'delete all of %1';
Blockly.Msg.DATA_INSERTATLIST = 'insert %1 at %2 of %3';
Blockly.Msg.DATA_REPLACEITEMOFLIST = 'replace item %1 of %2 with %3';
Blockly.Msg.DATA_SETLIST = 'set list %1 to %2';
Blockly.Msg.DATA_ITEMOFLIST = 'item %1 of %2';
Blockly.Msg.DATA_ITEMNUMOFLIST = 'item # of %1 in %2';
Blockly.Msg.DATA_LENGTHOFLIST = 'length of %1';
Expand Down
Loading