Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
49 changes: 49 additions & 0 deletions blocks_vertical/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,3 +530,52 @@ Blockly.Blocks['control_all_at_once'] = {
});
}
};

Blockly.Blocks['control_foreach_in_range'] = {
/**
* Block for each number from range.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.CONTROL_FOREACHINRANGE,
"message1": "%1", // Statement
"args0": [
{
"type": "input_value",
"name": "ITEM"
},
{
"type": "input_value",
"name": "FROM",
},
{
"type": "input_value",
"name": "TO",
},
],
"args1": [
{
"type": "input_statement",
"name": "SUBSTACK"
}
],
"category": Blockly.Categories.json,
"extensions": ["colours_control", "shape_statement"],
});
}
};

Blockly.Blocks['control_foreach_in_range_item'] = {
/**
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.CONTROL_FOREACHINRANGE_ITEM,
"category": Blockly.Categories.json,
"duplicateOnDrag": true,
"extensions": ["colours_control", "output_number"]
});
}
};
47 changes: 47 additions & 0 deletions blocks_vertical/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,53 @@ Blockly.Blocks['data_hidelist'] = {
}
};

Blockly.Blocks['data_listasarray'] = {
/**
* Block for turning list into array.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.DATA_LISTASARRAY,
"args0": [
{
"type": "field_variable",
"name": "LIST",
"variableTypes": [Blockly.LIST_VARIABLE_TYPE]
}
],
"category": Blockly.Categories.dataLists,
"extensions": ["colours_data_lists", "output_array"]
});
}
};

Blockly.Blocks['data_setlistarray'] = {
/**
* Block to set a list to array.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.DATA_SETLISTARRAY,
"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_tablecontents'] = {
/**
* Table reporter.
Expand Down
36 changes: 36 additions & 0 deletions blocks_vertical/default_toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,22 @@ Blockly.Blocks.defaultToolbox = '<xml id="toolbox-categories" style="display: no
'</shadow>' +
'</value>' +
'</block>' +
'<block type="control_foreach_in_range" id="control_foreach_in_range">' +
'<value name="ITEM">' +
'<shadow type="control_foreach_in_range_item">' +
'</shadow>' +
'</value>' +
'<value name="FROM">' +
'<shadow type="math_number">' +
'<field name="NUM">1</field>' +
'</shadow>' +
'</value>' +
'<value name="TO">' +
'<shadow type="math_number">' +
'<field name="NUM">10</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="control_forever" id="control_forever"></block>' +
'<block type="control_if" id="control_if"></block>' +
'<block type="control_if_else" id="control_if_else"></block>' +
Expand Down Expand Up @@ -531,6 +547,8 @@ Blockly.Blocks.defaultToolbox = '<xml id="toolbox-categories" style="display: no
' </shadow>' +
' </value>' +
'</block>' +
'<block type="operator_typeof">' +
'</block>' +
'</category>' +
'<category name="%{BKY_CATEGORY_VARIABLES}" id="data" colour="#FF8C1A" secondaryColour="#DB6E00" custom="VARIABLE">' +
'</category>' +
Expand Down Expand Up @@ -629,13 +647,25 @@ Blockly.Blocks.defaultToolbox = '<xml id="toolbox-categories" style="display: no
'</block>' +
'<block type="json_merge_array" id="json_merge_array">' +
'</block>' +
'<block type="json_reverse_array" id="json_reverse_array">' +
'</block>' +
'<block type="json_has_item" id="json_has_item">' +
'<value name="ITEM">' +
'<shadow type="text">' +
'<field name="TEXT">bar</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="json_foreach" id="json_foreach">' +
'<value name="VALUE">' +
'<shadow type="json_foreach_value">' +
'</shadow>' +
'</value>' +
'<value name="INDEX">' +
'<shadow type="json_foreach_index">' +
'</shadow>' +
'</value>' +
'</block>' +
'</category>' +
'<category name="%{BKY_CATEGORY_MYBLOCKS}" id="more" colour="#FF6680" secondaryColour="#FF4D6A" custom="PROCEDURE">' +
'</category>' +
Expand Down Expand Up @@ -719,6 +749,12 @@ Blockly.Blocks.defaultToolbox = '<xml id="toolbox-categories" style="display: no
'</shadow>' +
'</value>' +
'</block>' +
'<block type="extension_input">' +
' <value name="VALUE">' +
' <shadow type="extension_blockduplicateondrag">' +
' </shadow>' +
' </value>' +
'</block>' +
'<sep gap="36"></sep>' +
'<block type="extension_pen_down" id="extension_pen_down"></block>' +
'<block type="extension_music_drum" id="extension_music_drum">' +
Expand Down
27 changes: 27 additions & 0 deletions blocks_vertical/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,33 @@ Blockly.Blocks['extension_checkbox_test_legacy_json2'] = {
}
};

Blockly.Blocks['extension_input'] = {
init: function () {
this.jsonInit({
"message0": 'input %1',
"args0": [
{
"type": "input_value",
"name": "VALUE"
}
],
"category": Blockly.Categories.more,
"extensions": ["colours_more", "shape_statement"]
});
}
};

Blockly.Blocks['extension_blockduplicateondrag'] = {
init: function () {
this.jsonInit({
"message0": 'duplicate on drag',
"duplicateOnDrag": true,
"category": Blockly.Categories.more,
"extensions": ["colours_more", "output_string"]
});
}
};

Blockly.Blocks['extension_pen_down'] = {
/**
* @this Blockly.Block
Expand Down
66 changes: 66 additions & 0 deletions blocks_vertical/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,3 +483,69 @@ Blockly.Blocks['json_reverse_array'] = {
});
}
};

Blockly.Blocks['json_foreach'] = {
/**
* Block for each item and index in array.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.JSON_FOREACH,
"message1": "%1", // Statement
"args0": [
{
"type": "input_value",
"name": "VALUE"
},
{
"type": "input_value",
"name": "INDEX"
},
{
"type": "input_value",
"name": "ARRAY",
"check": "Array"
},
],
"args1": [
{
"type": "input_statement",
"name": "SUBSTACK"
}
],
"category": Blockly.Categories.json,
"extensions": ["colours_json", "shape_statement"],
});
}
};

Blockly.Blocks['json_foreach_value'] = {
/**
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.JSON_FOREACH_VALUE,
"output": null,
"outputShape": Blockly.OUTPUT_SHAPE_ROUND,
"category": Blockly.Categories.json,
"duplicateOnDrag": true,
"extensions": ["colours_json"],
});
}
};

Blockly.Blocks['json_foreach_index'] = {
/**
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.JSON_FOREACH_INDEX,
"category": Blockly.Categories.json,
"duplicateOnDrag": true,
"extensions": ["colours_json", "output_number"]
});
}
};
24 changes: 22 additions & 2 deletions blocks_vertical/operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,8 @@ Blockly.Blocks['operator_cast'] = {
[Blockly.Msg.OPERATORS_CAST_STRING, "string"],
[Blockly.Msg.OPERATORS_CAST_NUMBER, "number"],
[Blockly.Msg.OPERATORS_CAST_BOOLEAN, "boolean"],
[Blockly.Msg.OPERATORS_CAST_ARRAY, "array"],
[Blockly.Msg.OPERATORS_CAST_OBJECT, "object"]
[Blockly.Msg.OPERATORS_CAST_OBJECT, "object"],
[Blockly.Msg.OPERATORS_CAST_ARRAY, "array"]
]
}
],
Expand All @@ -501,3 +501,23 @@ Blockly.Blocks['operator_cast'] = {
});
}
};

Blockly.Blocks['operator_typeof'] = {
/**
* Get the specific type of a value.
* @this Blockly.Block
*/
init: function () {
this.jsonInit({
message0: Blockly.Msg.OPERATORS_TYPEOF,
args0: [
{
type: "input_value",
name: "VALUE"
}
],
category: Blockly.Categories.operators,
extensions: ["colours_operators", "output_string"]
});
}
};
25 changes: 25 additions & 0 deletions core/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ Blockly.Block = function(workspace, prototypeName, opt_id) {
*/
this.outputShape_ = null;

/**
* @type {boolean}
* @private
*/
this.duplicateOnDrag_ = false;

/**
* @type {?string}
* @private
Expand Down Expand Up @@ -1325,6 +1331,9 @@ Blockly.Block.prototype.jsonInit = function(json) {
var localizedValue = Blockly.utils.replaceMessageReferences(rawValue);
this.setHelpUrl(localizedValue);
}
if (json['duplicateOnDrag'] !== undefined) {
this.setDuplicateOnDrag(json['duplicateOnDrag']);
}
if (goog.isString(json['extensions'])) {
console.warn('JSON attribute \'extensions\' should be an array of ' +
'strings. Found raw string in JSON for \'' + json['type'] + '\' block.');
Expand Down Expand Up @@ -1839,3 +1848,19 @@ Blockly.Block.prototype.toDevString = function() {
}
return msg;
};

/**
* Set whether this block can duplicate on drag and if it's a shadow block.
* @param {boolean} value True if this block should duplicate on drag.
*/
Blockly.Block.prototype.setDuplicateOnDrag = function(value) {
this.duplicateOnDrag_ = value;
};

/**
* Get whether this block can duplicate on drag and if it's a shadow block.
* @return {boolean} True if this block can duplicate on drag.
*/
Blockly.Block.prototype.canDuplicateOnDrag = function() {
return this.duplicateOnDrag_ && this.isShadow();
};
9 changes: 4 additions & 5 deletions core/block_render_svg_vertical.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,7 @@ Blockly.BlockSvg.DEFINE_BLOCK_PADDING_RIGHT = 2 * Blockly.BlockSvg.GRID_UNIT;
*/
Blockly.BlockSvg.prototype.updateColour = function() {
var strokeColour = this.getColourTertiary();
var renderShadowed = this.isShadow() &&
!Blockly.scratchBlocksUtils.isShadowArgumentReporter(this);
var renderShadowed = !this.canDuplicateOnDrag() && this.isShadow() && !Blockly.scratchBlocksUtils.isShadowArgumentReporter(this);

if (renderShadowed && this.parentBlock_) {
// Pull shadow block stroke colour from parent block's tertiary if possible.
Expand Down Expand Up @@ -989,7 +988,7 @@ Blockly.BlockSvg.prototype.computeInputWidth_ = function(input) {
Blockly.BlockSvg.prototype.computeInputHeight_ = function(input, row,
previousRow) {
if (this.inputList.length === 1 && this.outputConnection &&
(this.isShadow() &&
(!this.canDuplicateOnDrag() && this.isShadow() &&
!Blockly.scratchBlocksUtils.isShadowArgumentReporter(this))) {
// "Lone" field blocks are smaller.
return Blockly.BlockSvg.MIN_BLOCK_Y_SINGLE_FIELD_OUTPUT;
Expand Down Expand Up @@ -1049,7 +1048,7 @@ Blockly.BlockSvg.prototype.computeRightEdge_ = function(curEdge, hasStatement) {
// Blocks with notches
edge = Math.max(edge, Blockly.BlockSvg.MIN_BLOCK_X);
} else if (this.outputConnection) {
if (this.isShadow() &&
if (!this.canDuplicateOnDrag() && this.isShadow() &&
!Blockly.scratchBlocksUtils.isShadowArgumentReporter(this)) {
// Single-fields
edge = Math.max(edge, Blockly.BlockSvg.MIN_BLOCK_X_SHADOW_OUTPUT);
Expand Down Expand Up @@ -1080,7 +1079,7 @@ Blockly.BlockSvg.prototype.computeRightEdge_ = function(curEdge, hasStatement) {
Blockly.BlockSvg.prototype.computeOutputPadding_ = function(inputRows) {
// Only apply to blocks with outputs and not single fields (shadows).
if (!this.getOutputShape() || !this.outputConnection ||
(this.isShadow() &&
(!this.canDuplicateOnDrag() && this.isShadow() &&
!Blockly.scratchBlocksUtils.isShadowArgumentReporter(this))) {
return;
}
Expand Down
Loading