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

refactor: convert some block generators to goog.module #5762

Merged
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
54d2354
refactor: convert generators/javascript.js to goog.module
rachel-fenichel Dec 1, 2021
d373d4f
refactor: convert generators/javascript.js to named requires
rachel-fenichel Dec 1, 2021
f33a56e
chore: run clang-format
rachel-fenichel Dec 1, 2021
7acbf53
refactor: convert generators/dart/variables.js to goog.module
rachel-fenichel Dec 1, 2021
913be91
refactor: convert generators/dart/variables.js to named requires
rachel-fenichel Dec 1, 2021
5775692
chore: run clang-format
rachel-fenichel Dec 1, 2021
4a28b9c
refactor: convert generators/dart/variables_dynamic.js to goog.module
rachel-fenichel Dec 1, 2021
86b0bc2
refactor: convert generators/dart/variables_dynamic.js to named requires
rachel-fenichel Dec 1, 2021
5d32b2a
refactor: convert generators/dart/text.js to goog.module
rachel-fenichel Dec 1, 2021
c01e9bf
refactor: convert generators/dart/text.js to named requires
rachel-fenichel Dec 1, 2021
6b322bd
chore: run clang-format
rachel-fenichel Dec 1, 2021
1f2fd36
refactor: convert generators/dart/procedures.js to goog.module
rachel-fenichel Dec 1, 2021
aa4ef04
refactor: convert generators/dart/procedures.js to named requires
rachel-fenichel Dec 1, 2021
d2e6eb9
chore: run clang-format
rachel-fenichel Dec 1, 2021
6fc430b
refactor: convert generators/dart/math.js to goog.module
rachel-fenichel Dec 1, 2021
ff6cb03
refactor: convert generators/dart/math.js to named requires
rachel-fenichel Dec 1, 2021
ab9e02c
chore: run clang-format
rachel-fenichel Dec 1, 2021
b2bd223
refactor: convert generators/dart/loops.js to goog.module
rachel-fenichel Dec 1, 2021
4de1d03
refactor: convert generators/dart/loops.js to named requires
rachel-fenichel Dec 1, 2021
52f866b
chore: run clang-format
rachel-fenichel Dec 1, 2021
dfeed31
refactor: convert generators/dart/logic.js to goog.module
rachel-fenichel Dec 1, 2021
c09eca3
refactor: convert generators/dart/logic.js to named requires
rachel-fenichel Dec 1, 2021
b37a350
chore: run clang-format
rachel-fenichel Dec 1, 2021
fa2224c
refactor: convert generators/dart/lists.js to goog.module
rachel-fenichel Dec 1, 2021
3c98e3d
refactor: convert generators/dart/lists.js to named requires
rachel-fenichel Dec 1, 2021
471e3e4
chore: run clang-format
rachel-fenichel Dec 1, 2021
6408369
refactor: convert generators/dart/colour.js to goog.module
rachel-fenichel Dec 1, 2021
a6a37a1
refactor: convert generators/dart/colour.js to named requires
rachel-fenichel Dec 1, 2021
b33cdc5
chore: rebuild deps.js
rachel-fenichel Dec 1, 2021
4f0cdf3
chore: lint
rachel-fenichel Dec 1, 2021
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
66 changes: 33 additions & 33 deletions generators/dart/colour.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,50 @@
*/
'use strict';

goog.provide('Blockly.Dart.colour');
goog.module('Blockly.Dart.colour');

goog.require('Blockly.Dart');
const Dart = goog.require('Blockly.Dart');


Blockly.Dart.addReservedWords('Math');
Dart.addReservedWords('Math');

Blockly.Dart['colour_picker'] = function(block) {
Dart['colour_picker'] = function(block) {
// Colour picker.
const code = Blockly.Dart.quote_(block.getFieldValue('COLOUR'));
return [code, Blockly.Dart.ORDER_ATOMIC];
const code = Dart.quote_(block.getFieldValue('COLOUR'));
return [code, Dart.ORDER_ATOMIC];
};

Blockly.Dart['colour_random'] = function(block) {
Dart['colour_random'] = function(block) {
// Generate a random colour.
Blockly.Dart.definitions_['import_dart_math'] =
Dart.definitions_['import_dart_math'] =
'import \'dart:math\' as Math;';
const functionName = Blockly.Dart.provideFunction_(
const functionName = Dart.provideFunction_(
'colour_random',
['String ' + Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_ + '() {',
['String ' + Dart.FUNCTION_NAME_PLACEHOLDER_ + '() {',
' String hex = \'0123456789abcdef\';',
' var rnd = new Math.Random();',
' return \'#${hex[rnd.nextInt(16)]}${hex[rnd.nextInt(16)]}\'',
' \'${hex[rnd.nextInt(16)]}${hex[rnd.nextInt(16)]}\'',
' \'${hex[rnd.nextInt(16)]}${hex[rnd.nextInt(16)]}\';',
'}']);
const code = functionName + '()';
return [code, Blockly.Dart.ORDER_UNARY_POSTFIX];
return [code, Dart.ORDER_UNARY_POSTFIX];
};

Blockly.Dart['colour_rgb'] = function(block) {
Dart['colour_rgb'] = function(block) {
// Compose a colour from RGB components expressed as percentages.
const red = Blockly.Dart.valueToCode(block, 'RED',
Blockly.Dart.ORDER_NONE) || 0;
const green = Blockly.Dart.valueToCode(block, 'GREEN',
Blockly.Dart.ORDER_NONE) || 0;
const blue = Blockly.Dart.valueToCode(block, 'BLUE',
Blockly.Dart.ORDER_NONE) || 0;
const red = Dart.valueToCode(block, 'RED',
Dart.ORDER_NONE) || 0;
const green = Dart.valueToCode(block, 'GREEN',
Dart.ORDER_NONE) || 0;
const blue = Dart.valueToCode(block, 'BLUE',
Dart.ORDER_NONE) || 0;

Blockly.Dart.definitions_['import_dart_math'] =
Dart.definitions_['import_dart_math'] =
'import \'dart:math\' as Math;';
const functionName = Blockly.Dart.provideFunction_(
const functionName = Dart.provideFunction_(
'colour_rgb',
['String ' + Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_ +
['String ' + Dart.FUNCTION_NAME_PLACEHOLDER_ +
'(num r, num g, num b) {',
' num rn = (Math.max(Math.min(r, 100), 0) * 2.55).round();',
' String rs = rn.toInt().toRadixString(16);',
Expand All @@ -69,23 +69,23 @@ Blockly.Dart['colour_rgb'] = function(block) {
' return \'#$rs$gs$bs\';',
'}']);
const code = functionName + '(' + red + ', ' + green + ', ' + blue + ')';
return [code, Blockly.Dart.ORDER_UNARY_POSTFIX];
return [code, Dart.ORDER_UNARY_POSTFIX];
};

Blockly.Dart['colour_blend'] = function(block) {
Dart['colour_blend'] = function(block) {
// Blend two colours together.
const c1 = Blockly.Dart.valueToCode(block, 'COLOUR1',
Blockly.Dart.ORDER_NONE) || '\'#000000\'';
const c2 = Blockly.Dart.valueToCode(block, 'COLOUR2',
Blockly.Dart.ORDER_NONE) || '\'#000000\'';
const ratio = Blockly.Dart.valueToCode(block, 'RATIO',
Blockly.Dart.ORDER_NONE) || 0.5;
const c1 = Dart.valueToCode(block, 'COLOUR1',
Dart.ORDER_NONE) || '\'#000000\'';
const c2 = Dart.valueToCode(block, 'COLOUR2',
Dart.ORDER_NONE) || '\'#000000\'';
const ratio = Dart.valueToCode(block, 'RATIO',
Dart.ORDER_NONE) || 0.5;

Blockly.Dart.definitions_['import_dart_math'] =
Dart.definitions_['import_dart_math'] =
'import \'dart:math\' as Math;';
const functionName = Blockly.Dart.provideFunction_(
const functionName = Dart.provideFunction_(
'colour_blend',
['String ' + Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_ +
['String ' + Dart.FUNCTION_NAME_PLACEHOLDER_ +
'(String c1, String c2, num ratio) {',
' ratio = Math.max(Math.min(ratio, 1), 0);',
' int r1 = int.parse(\'0x${c1.substring(1, 3)}\');',
Expand All @@ -109,5 +109,5 @@ Blockly.Dart['colour_blend'] = function(block) {
' return \'#$rs$gs$bs\';',
'}']);
const code = functionName + '(' + c1 + ', ' + c2 + ', ' + ratio + ')';
return [code, Blockly.Dart.ORDER_UNARY_POSTFIX];
return [code, Dart.ORDER_UNARY_POSTFIX];
};
Loading