Skip to content

Commit 5a5b300

Browse files
Merge branch 'develop' into develop-builds
2 parents 353af8b + 4c7e35f commit 5a5b300

File tree

6 files changed

+169
-19
lines changed

6 files changed

+169
-19
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Playgrounds
22

3-
- **Vertical blocks**: https://turbowarp.github.io/scratch-blocks/tests/vertical_playground_compressed.html
3+
- **Vertical blocks**: https://nitro-bolt.github.io/scratch-blocks/tests/vertical_playground_compressed.html
44

55
## Local development
66

blocks_vertical/data.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,35 @@ Blockly.Blocks['data_listindexrandom'] = {
226226
}
227227
};
228228

229+
Blockly.Blocks['data_listindex'] = {
230+
/**
231+
* List index menu, with all secret options.
232+
* @this Blockly.Block
233+
*/
234+
init: function() {
235+
this.jsonInit({
236+
"message0": "%1",
237+
"args0": [
238+
{
239+
"type": "field_numberdropdown",
240+
"name": "INDEX",
241+
"value": "1",
242+
"min": 1,
243+
"precision": 1,
244+
"options": [
245+
["1", "1"],
246+
[Blockly.Msg.DATA_INDEX_LAST, "last"],
247+
[Blockly.Msg.DATA_INDEX_ALL, "all"],
248+
[Blockly.Msg.DATA_INDEX_RANDOM, "random"]
249+
]
250+
}
251+
],
252+
"category": Blockly.Categories.data,
253+
"extensions": ["colours_textfield", "output_string"]
254+
});
255+
}
256+
};
257+
229258
Blockly.Blocks['data_addtolist'] = {
230259
/**
231260
* Block to add item to list.
@@ -497,6 +526,53 @@ Blockly.Blocks['data_hidelist'] = {
497526
}
498527
};
499528

529+
Blockly.Blocks['data_listasarray'] = {
530+
/**
531+
* Block for turning list into array.
532+
* @this Blockly.Block
533+
*/
534+
init: function() {
535+
this.jsonInit({
536+
"message0": Blockly.Msg.DATA_LISTASARRAY,
537+
"args0": [
538+
{
539+
"type": "field_variable",
540+
"name": "LIST",
541+
"variableTypes": [Blockly.LIST_VARIABLE_TYPE]
542+
}
543+
],
544+
"category": Blockly.Categories.dataLists,
545+
"extensions": ["colours_data_lists", "output_array"]
546+
});
547+
}
548+
};
549+
550+
Blockly.Blocks['data_setlistarray'] = {
551+
/**
552+
* Block to set a list to array.
553+
* @this Blockly.Block
554+
*/
555+
init: function() {
556+
this.jsonInit({
557+
"message0": Blockly.Msg.DATA_SETLISTARRAY,
558+
"args0": [
559+
{
560+
"type": "field_variable",
561+
"name": "LIST",
562+
"variableTypes": [Blockly.LIST_VARIABLE_TYPE]
563+
},
564+
{
565+
"type": "input_value",
566+
"name": "ARRAY",
567+
"check": "Array"
568+
},
569+
],
570+
"category": Blockly.Categories.dataLists,
571+
"extensions": ["colours_data_lists", "shape_statement"]
572+
});
573+
}
574+
};
575+
500576
Blockly.Blocks['data_tablecontents'] = {
501577
/**
502578
* Table reporter.

core/data_category.js

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,19 @@ Blockly.DataCategory = function(workspace) {
7676
Blockly.DataCategory.addAddToList(xmlList, firstVariable);
7777
Blockly.DataCategory.addSep(xmlList);
7878
Blockly.DataCategory.addDeleteOfList(xmlList, firstVariable);
79-
Blockly.DataCategory.addDeleteAllOfList(xmlList, firstVariable);
79+
// Blockly.DataCategory.addDeleteAllOfList(xmlList, firstVariable);
8080
Blockly.DataCategory.addInsertAtList(xmlList, firstVariable);
8181
Blockly.DataCategory.addReplaceItemOfList(xmlList, firstVariable);
8282
Blockly.DataCategory.addSep(xmlList);
8383
Blockly.DataCategory.addItemOfList(xmlList, firstVariable);
8484
Blockly.DataCategory.addItemNumberOfList(xmlList, firstVariable);
8585
Blockly.DataCategory.addLengthOfList(xmlList, firstVariable);
86+
Blockly.DataCategory.addListAsArray(xmlList, firstVariable);
8687
Blockly.DataCategory.addListContainsItem(xmlList, firstVariable);
8788
Blockly.DataCategory.addSep(xmlList);
8889
Blockly.DataCategory.addShowList(xmlList, firstVariable);
8990
Blockly.DataCategory.addHideList(xmlList, firstVariable);
91+
Blockly.DataCategory.addSetListArray(xmlList, firstVariable);
9092
}
9193

9294
// Now add table variables to the flyout
@@ -249,27 +251,30 @@ Blockly.DataCategory.addDeleteOfList = function(xmlList, variable) {
249251
// <block type="data_deleteoflist">
250252
// <field name="LIST" variabletype="list" id="">variablename</field>
251253
// <value name="INDEX">
252-
// <shadow type="math_integer">
254+
// <shadow type="data_listindex">
253255
// <field name="NUM">1</field>
254256
// </shadow>
255257
// </value>
256258
// </block>
257259
Blockly.DataCategory.addBlock(xmlList, variable, 'data_deleteoflist', 'LIST',
258-
[['INDEX', 'math_integer', 1]]);
260+
[['INDEX', 'data_listindex', 1]]);
259261
};
260262

261263
/**
262264
* Construct and add a data_deleteoflist block to xmlList.
265+
* Removed from NitroBolt
263266
* @param {!Array.<!Element>} xmlList Array of XML block elements.
264267
* @param {?Blockly.VariableModel} variable Variable to select in the field.
265268
*/
269+
/*
266270
Blockly.DataCategory.addDeleteAllOfList = function(xmlList, variable) {
267271
// <block type="data_deletealloflist">
268272
// <field name="LIST" variabletype="list" id="">variablename</field>
269273
// </block>
270274
Blockly.DataCategory.addBlock(xmlList, variable, 'data_deletealloflist',
271275
'LIST');
272276
};
277+
*/
273278

274279
/**
275280
* Construct and add a data_insertatlist block to xmlList.
@@ -280,7 +285,7 @@ Blockly.DataCategory.addInsertAtList = function(xmlList, variable) {
280285
// <block type="data_insertatlist">
281286
// <field name="LIST" variabletype="list" id="">variablename</field>
282287
// <value name="INDEX">
283-
// <shadow type="math_integer">
288+
// <shadow type="data_listindexrandom">
284289
// <field name="NUM">1</field>
285290
// </shadow>
286291
// </value>
@@ -291,7 +296,7 @@ Blockly.DataCategory.addInsertAtList = function(xmlList, variable) {
291296
// </value>
292297
// </block>
293298
Blockly.DataCategory.addBlock(xmlList, variable, 'data_insertatlist', 'LIST',
294-
[['INDEX', 'math_integer', 1], ['ITEM', 'text', Blockly.Msg.DEFAULT_LIST_ITEM]]);
299+
[['INDEX', 'data_listindexrandom', 1], ['ITEM', 'text', Blockly.Msg.DEFAULT_LIST_ITEM]]);
295300
};
296301

297302
/**
@@ -303,7 +308,7 @@ Blockly.DataCategory.addReplaceItemOfList = function(xmlList, variable) {
303308
// <block type="data_replaceitemoflist">
304309
// <field name="LIST" variabletype="list" id="">variablename</field>
305310
// <value name="INDEX">
306-
// <shadow type="math_integer">
311+
// <shadow type="data_listindexrandom">
307312
// <field name="NUM">1</field>
308313
// </shadow>
309314
// </value>
@@ -314,7 +319,7 @@ Blockly.DataCategory.addReplaceItemOfList = function(xmlList, variable) {
314319
// </value>
315320
// </block>
316321
Blockly.DataCategory.addBlock(xmlList, variable, 'data_replaceitemoflist',
317-
'LIST', [['INDEX', 'math_integer', 1], ['ITEM', 'text', Blockly.Msg.DEFAULT_LIST_ITEM]]);
322+
'LIST', [['INDEX', 'data_listindexrandom', 1], ['ITEM', 'text', Blockly.Msg.DEFAULT_LIST_ITEM]]);
318323
};
319324

320325
/**
@@ -326,13 +331,13 @@ Blockly.DataCategory.addItemOfList = function(xmlList, variable) {
326331
// <block type="data_itemoflist">
327332
// <field name="LIST" variabletype="list" id="">variablename</field>
328333
// <value name="INDEX">
329-
// <shadow type="math_integer">
334+
// <shadow type="data_listindexrandom">
330335
// <field name="NUM">1</field>
331336
// </shadow>
332337
// </value>
333338
// </block>
334339
Blockly.DataCategory.addBlock(xmlList, variable, 'data_itemoflist', 'LIST',
335-
[['INDEX', 'math_integer', 1]]);
340+
[['INDEX', 'data_listindexrandom', 1]]);
336341
};
337342

338343
/** Construct and add a data_itemnumoflist block to xmlList.
@@ -406,6 +411,30 @@ Blockly.DataCategory.addHideList = function(xmlList, variable) {
406411
Blockly.DataCategory.addBlock(xmlList, variable, 'data_hidelist', 'LIST');
407412
};
408413

414+
/**
415+
* Construct and add a data_lengthoflist block to xmlList.
416+
* @param {!Array.<!Element>} xmlList Array of XML block elements.
417+
* @param {?Blockly.VariableModel} variable Variable to select in the field.
418+
*/
419+
Blockly.DataCategory.addListAsArray = function(xmlList, variable) {
420+
// <block type="data_listasarray">
421+
// <field name="LIST" variabletype="list" id="">variablename</field>
422+
// </block>
423+
Blockly.DataCategory.addBlock(xmlList, variable, 'data_listasarray', 'LIST');
424+
};
425+
426+
/**
427+
* Construct and add a data_lengthoflist block to xmlList.
428+
* @param {!Array.<!Element>} xmlList Array of XML block elements.
429+
* @param {?Blockly.VariableModel} variable Variable to select in the field.
430+
*/
431+
Blockly.DataCategory.addSetListArray = function(xmlList, variable) {
432+
// <block type="data_setlistarray">
433+
// <field name="LIST" variabletype="list" id="">variablename</field>
434+
// </block>
435+
Blockly.DataCategory.addBlock(xmlList, variable, 'data_setlistarray', 'LIST');
436+
};
437+
409438
/**
410439
* Construct and add a data_tablecontents block to xmlList.
411440
* @param {!Array.<!Element>} xmlList Array of XML block elements.
@@ -510,13 +539,13 @@ Blockly.DataCategory.addDeleteDimensionInTable = function(xmlList, variable) {
510539
// <block type="data_deletedimensionintable">
511540
// <field name="TABLE" variabletype="table" id="">variablename</field>
512541
// <value name="INDEX">
513-
// <shadow type="math_integer">
542+
// <shadow type="data_listindexrandom">
514543
// <field name="NUM">1</field>
515544
// </shadow>
516545
// </value>
517546
// </block>
518547
Blockly.DataCategory.addBlock(xmlList, variable, 'data_deletedimensionintable', 'TABLE',
519-
[['INDEX', 'math_integer', 1]]);
548+
[['INDEX', 'data_listindexrandom', 1]]);
520549
};
521550

522551
/**
@@ -564,13 +593,13 @@ Blockly.DataCategory.addItemsOfDimensionOfTable = function(xmlList, variable) {
564593
// <block type="data_itemsofdimensionoftable">
565594
// <field name="TABLE" variabletype="table" id="">variablename</field>
566595
// <value name="INDEX">
567-
// <shadow type="math_integer">
596+
// <shadow type="data_listindexrandom">
568597
// <field name="NUM">1</field>
569598
// </shadow>
570599
// </value>
571600
// </block>
572601
Blockly.DataCategory.addBlock(xmlList, variable, 'data_itemsofdimensionoftable', 'TABLE',
573-
[['INDEX', 'math_integer', 1]]);
602+
[['INDEX', 'data_listindexrandom', 1]]);
574603
};
575604

576605
/**
@@ -582,13 +611,13 @@ Blockly.DataCategory.addLengthOfDimensionOfTable = function(xmlList, variable) {
582611
// <block type="data_lengthofdimensionoftable">
583612
// <field name="TABLE" variabletype="table" id="">variablename</field>
584613
// <value name="INDEX">
585-
// <shadow type="math_integer">
614+
// <shadow type="data_listindexrandom">
586615
// <field name="NUM">1</field>
587616
// </shadow>
588617
// </value>
589618
// </block>
590619
Blockly.DataCategory.addBlock(xmlList, variable, 'data_lengthofdimensionoftable', 'TABLE',
591-
[['INDEX', 'math_integer', 1]]);
620+
[['INDEX', 'data_listindexrandom', 1]]);
592621
};
593622

594623
/**

core/field_textdropdown.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ Blockly.FieldTextDropdown.prototype.init = function() {
9696
'width': this.arrowSize_ + 'px'
9797
});
9898
this.arrow_.setAttributeNS('http://www.w3.org/1999/xlink',
99-
'xlink:href', Blockly.mainWorkspace.options.pathToMedia + 'dropdown-arrow-dark.svg');
99+
'xlink:href', Blockly.mainWorkspace.options.pathToMedia +
100+
Blockly.FieldTextInput.getTextMenuArrowAsset());
100101
this.arrow_.style.cursor = 'pointer';
101102
this.fieldGroup_.appendChild(this.arrow_);
102103
this.mouseUpWrapper_ =
@@ -140,7 +141,32 @@ Blockly.FieldTextDropdown.prototype.showEditor_ = function() {
140141
* (human-readable text, language-neutral name).
141142
* @private
142143
*/
143-
Blockly.FieldTextDropdown.prototype.getOptions_ = Blockly.FieldDropdown.prototype.getOptions_;
144+
Blockly.FieldTextDropdown.prototype.getOptions = Blockly.FieldDropdown.prototype.getOptions;
145+
146+
/**
147+
* Handle the selection of an item in the dropdown menu.
148+
* @param {!goog.ui.Menu} menu The Menu component clicked.
149+
* @param {!goog.ui.MenuItem} menuItem The MenuItem selected within menu.
150+
*/
151+
Blockly.FieldTextDropdown.prototype.onItemSelected = Blockly.FieldDropdown.prototype.onItemSelected;
152+
153+
/**
154+
* Get the language-neutral value from this dropdown menu.
155+
* @return {string} Current text.
156+
*/
157+
Blockly.FieldTextDropdown.prototype.getValue = Blockly.FieldDropdown.prototype.getValue;
158+
159+
/**
160+
* Set the language-neutral value for this dropdown menu.
161+
* @param {string} newValue New value to set.
162+
*/
163+
Blockly.FieldTextDropdown.prototype.setValue = Blockly.FieldDropdown.prototype.setValue;
164+
165+
/**
166+
* @return {boolean} True if the option list is generated by a function.
167+
* Otherwise false.
168+
*/
169+
Blockly.FieldTextDropdown.prototype.isOptionListDynamic = Blockly.FieldDropdown.prototype.isOptionListDynamic;
144170

145171
/**
146172
* Position a drop-down arrow at the appropriate location at render-time.

core/field_textinput.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,22 @@ Blockly.FieldTextInput.TEXT_MEASURE_PADDING_MAGIC = 45;
9696
*/
9797
Blockly.FieldTextInput.htmlInput_ = null;
9898

99+
/**
100+
* Select caret asset for text menus based on native theme mode.
101+
* In default mode, keep the original text-dropdown caret.
102+
* In non-default modes, use the regular dropdown caret.
103+
*
104+
* This is a bit hacky, but it works
105+
* @returns {string} Relative media file name.
106+
* @package
107+
*/
108+
Blockly.FieldTextInput.getTextMenuArrowAsset = function() {
109+
var textField = String(Blockly.Colours.textField || '').trim().toLowerCase();
110+
var textFieldText = String(Blockly.Colours.textFieldText || '').trim().toLowerCase();
111+
var defaultTheme = textField === '#ffffff' && textFieldText === '#575e75';
112+
return defaultTheme ? 'dropdown-arrow-dark.svg' : 'dropdown-arrow.svg';
113+
};
114+
99115
/**
100116
* Mouse cursor style when over the hotspot that initiates the editor.
101117
*/
@@ -248,7 +264,8 @@ Blockly.FieldTextInput.prototype.showEditor_ = function(
248264
var dropDownArrow =
249265
goog.dom.createDom(goog.dom.TagName.IMG, 'blocklyTextDropDownArrow');
250266
dropDownArrow.setAttribute('src',
251-
Blockly.mainWorkspace.options.pathToMedia + 'dropdown-arrow-dark.svg');
267+
Blockly.mainWorkspace.options.pathToMedia +
268+
Blockly.FieldTextInput.getTextMenuArrowAsset());
252269
dropDownArrow.style.width = this.arrowSize_ + 'px';
253270
dropDownArrow.style.height = this.arrowSize_ + 'px';
254271
dropDownArrow.style.top = this.arrowY_ + 'px';

msg/messages.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ Blockly.Msg.DATA_LENGTHOFLIST = 'length of %1';
7272
Blockly.Msg.DATA_LISTCONTAINSITEM = '%1 contains %2?';
7373
Blockly.Msg.DATA_SHOWLIST = 'show list %1';
7474
Blockly.Msg.DATA_HIDELIST = 'hide list %1';
75+
Blockly.Msg.DATA_LISTASARRAY = '%1 as array';
76+
Blockly.Msg.DATA_SETLISTARRAY = 'set list %1 to %2';
7577
Blockly.Msg.DATA_INDEX_ALL = 'all';
7678
Blockly.Msg.DATA_INDEX_LAST = 'last';
7779
Blockly.Msg.DATA_INDEX_RANDOM = 'random';

0 commit comments

Comments
 (0)