mirror of
https://github.com/google/blockly.git
synced 2025-12-16 06:10:12 +01:00
refactor: Migrate blocks/math.js to goog.module syntax (#5765)
* refactor: Migrate blocks/math.js to goog.module * refactor: Migrate blocks/math.js named requires * chore: clang-format blocks/math.js
This commit is contained in:
committed by
GitHub
parent
37a1e9725c
commit
d7b82cddfc
552
blocks/math.js
552
blocks/math.js
@@ -6,88 +6,91 @@
|
||||
|
||||
/**
|
||||
* @fileoverview Math blocks for Blockly.
|
||||
* @suppress {extraRequire|missingRequire|checkTypes}
|
||||
* @suppress {checkTypes}
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.provide('Blockly.blocks.math');
|
||||
goog.provide('Blockly.Constants.Math');
|
||||
goog.module('Blockly.blocks.math');
|
||||
|
||||
goog.require('Blockly');
|
||||
goog.require('Blockly.FieldDropdown');
|
||||
const Extensions = goog.require('Blockly.Extensions');
|
||||
/* eslint-disable-next-line no-unused-vars */
|
||||
const xmlUtils = goog.require('Blockly.utils.xml');
|
||||
/* eslint-disable-next-line no-unused-vars */
|
||||
const {Block} = goog.requireType('Blockly.Block');
|
||||
// N.B.: Blockly.FieldDropdown needed for type AND side-effects.
|
||||
/* eslint-disable-next-line no-unused-vars */
|
||||
const FieldDropdown = goog.require('Blockly.FieldDropdown');
|
||||
const {defineBlocksWithJsonArray} = goog.require('Blockly.common');
|
||||
/** @suppress {extraRequire} */
|
||||
goog.require('Blockly.FieldLabel');
|
||||
/** @suppress {extraRequire} */
|
||||
goog.require('Blockly.FieldNumber');
|
||||
/** @suppress {extraRequire} */
|
||||
goog.require('Blockly.FieldVariable');
|
||||
|
||||
|
||||
/**
|
||||
* Unused constant for the common HSV hue for all blocks in this category.
|
||||
* @deprecated Use Blockly.Msg['MATH_HUE']. (2018 April 5)
|
||||
*/
|
||||
Blockly.Constants.Math.HUE = 230;
|
||||
|
||||
Blockly.defineBlocksWithJsonArray([
|
||||
defineBlocksWithJsonArray([
|
||||
// Block for numeric value.
|
||||
{
|
||||
"type": "math_number",
|
||||
"message0": "%1",
|
||||
"args0": [{
|
||||
"type": "field_number",
|
||||
"name": "NUM",
|
||||
"value": 0,
|
||||
'type': 'math_number',
|
||||
'message0': '%1',
|
||||
'args0': [{
|
||||
'type': 'field_number',
|
||||
'name': 'NUM',
|
||||
'value': 0,
|
||||
}],
|
||||
"output": "Number",
|
||||
"helpUrl": "%{BKY_MATH_NUMBER_HELPURL}",
|
||||
"style": "math_blocks",
|
||||
"tooltip": "%{BKY_MATH_NUMBER_TOOLTIP}",
|
||||
"extensions": ["parent_tooltip_when_inline"],
|
||||
'output': 'Number',
|
||||
'helpUrl': '%{BKY_MATH_NUMBER_HELPURL}',
|
||||
'style': 'math_blocks',
|
||||
'tooltip': '%{BKY_MATH_NUMBER_TOOLTIP}',
|
||||
'extensions': ['parent_tooltip_when_inline'],
|
||||
},
|
||||
|
||||
// Block for basic arithmetic operator.
|
||||
{
|
||||
"type": "math_arithmetic",
|
||||
"message0": "%1 %2 %3",
|
||||
"args0": [
|
||||
'type': 'math_arithmetic',
|
||||
'message0': '%1 %2 %3',
|
||||
'args0': [
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "A",
|
||||
"check": "Number",
|
||||
'type': 'input_value',
|
||||
'name': 'A',
|
||||
'check': 'Number',
|
||||
},
|
||||
{
|
||||
"type": "field_dropdown",
|
||||
"name": "OP",
|
||||
"options": [
|
||||
["%{BKY_MATH_ADDITION_SYMBOL}", "ADD"],
|
||||
["%{BKY_MATH_SUBTRACTION_SYMBOL}", "MINUS"],
|
||||
["%{BKY_MATH_MULTIPLICATION_SYMBOL}", "MULTIPLY"],
|
||||
["%{BKY_MATH_DIVISION_SYMBOL}", "DIVIDE"],
|
||||
["%{BKY_MATH_POWER_SYMBOL}", "POWER"],
|
||||
'type': 'field_dropdown',
|
||||
'name': 'OP',
|
||||
'options': [
|
||||
['%{BKY_MATH_ADDITION_SYMBOL}', 'ADD'],
|
||||
['%{BKY_MATH_SUBTRACTION_SYMBOL}', 'MINUS'],
|
||||
['%{BKY_MATH_MULTIPLICATION_SYMBOL}', 'MULTIPLY'],
|
||||
['%{BKY_MATH_DIVISION_SYMBOL}', 'DIVIDE'],
|
||||
['%{BKY_MATH_POWER_SYMBOL}', 'POWER'],
|
||||
],
|
||||
},
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "B",
|
||||
"check": "Number",
|
||||
'type': 'input_value',
|
||||
'name': 'B',
|
||||
'check': 'Number',
|
||||
},
|
||||
],
|
||||
"inputsInline": true,
|
||||
"output": "Number",
|
||||
"style": "math_blocks",
|
||||
"helpUrl": "%{BKY_MATH_ARITHMETIC_HELPURL}",
|
||||
"extensions": ["math_op_tooltip"],
|
||||
'inputsInline': true,
|
||||
'output': 'Number',
|
||||
'style': 'math_blocks',
|
||||
'helpUrl': '%{BKY_MATH_ARITHMETIC_HELPURL}',
|
||||
'extensions': ['math_op_tooltip'],
|
||||
},
|
||||
|
||||
// Block for advanced math operators with single operand.
|
||||
{
|
||||
"type": "math_single",
|
||||
"message0": "%1 %2",
|
||||
"args0": [
|
||||
'type': 'math_single',
|
||||
'message0': '%1 %2',
|
||||
'args0': [
|
||||
{
|
||||
"type": "field_dropdown",
|
||||
"name": "OP",
|
||||
"options": [
|
||||
["%{BKY_MATH_SINGLE_OP_ROOT}", 'ROOT'],
|
||||
["%{BKY_MATH_SINGLE_OP_ABSOLUTE}", 'ABS'],
|
||||
'type': 'field_dropdown',
|
||||
'name': 'OP',
|
||||
'options': [
|
||||
['%{BKY_MATH_SINGLE_OP_ROOT}', 'ROOT'],
|
||||
['%{BKY_MATH_SINGLE_OP_ABSOLUTE}', 'ABS'],
|
||||
['-', 'NEG'],
|
||||
['ln', 'LN'],
|
||||
['log10', 'LOG10'],
|
||||
@@ -96,300 +99,300 @@ Blockly.defineBlocksWithJsonArray([
|
||||
],
|
||||
},
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "NUM",
|
||||
"check": "Number",
|
||||
'type': 'input_value',
|
||||
'name': 'NUM',
|
||||
'check': 'Number',
|
||||
},
|
||||
],
|
||||
"output": "Number",
|
||||
"style": "math_blocks",
|
||||
"helpUrl": "%{BKY_MATH_SINGLE_HELPURL}",
|
||||
"extensions": ["math_op_tooltip"],
|
||||
'output': 'Number',
|
||||
'style': 'math_blocks',
|
||||
'helpUrl': '%{BKY_MATH_SINGLE_HELPURL}',
|
||||
'extensions': ['math_op_tooltip'],
|
||||
},
|
||||
|
||||
// Block for trigonometry operators.
|
||||
{
|
||||
"type": "math_trig",
|
||||
"message0": "%1 %2",
|
||||
"args0": [
|
||||
'type': 'math_trig',
|
||||
'message0': '%1 %2',
|
||||
'args0': [
|
||||
{
|
||||
"type": "field_dropdown",
|
||||
"name": "OP",
|
||||
"options": [
|
||||
["%{BKY_MATH_TRIG_SIN}", "SIN"],
|
||||
["%{BKY_MATH_TRIG_COS}", "COS"],
|
||||
["%{BKY_MATH_TRIG_TAN}", "TAN"],
|
||||
["%{BKY_MATH_TRIG_ASIN}", "ASIN"],
|
||||
["%{BKY_MATH_TRIG_ACOS}", "ACOS"],
|
||||
["%{BKY_MATH_TRIG_ATAN}", "ATAN"],
|
||||
'type': 'field_dropdown',
|
||||
'name': 'OP',
|
||||
'options': [
|
||||
['%{BKY_MATH_TRIG_SIN}', 'SIN'],
|
||||
['%{BKY_MATH_TRIG_COS}', 'COS'],
|
||||
['%{BKY_MATH_TRIG_TAN}', 'TAN'],
|
||||
['%{BKY_MATH_TRIG_ASIN}', 'ASIN'],
|
||||
['%{BKY_MATH_TRIG_ACOS}', 'ACOS'],
|
||||
['%{BKY_MATH_TRIG_ATAN}', 'ATAN'],
|
||||
],
|
||||
},
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "NUM",
|
||||
"check": "Number",
|
||||
'type': 'input_value',
|
||||
'name': 'NUM',
|
||||
'check': 'Number',
|
||||
},
|
||||
],
|
||||
"output": "Number",
|
||||
"style": "math_blocks",
|
||||
"helpUrl": "%{BKY_MATH_TRIG_HELPURL}",
|
||||
"extensions": ["math_op_tooltip"],
|
||||
'output': 'Number',
|
||||
'style': 'math_blocks',
|
||||
'helpUrl': '%{BKY_MATH_TRIG_HELPURL}',
|
||||
'extensions': ['math_op_tooltip'],
|
||||
},
|
||||
|
||||
// Block for constants: PI, E, the Golden Ratio, sqrt(2), 1/sqrt(2), INFINITY.
|
||||
{
|
||||
"type": "math_constant",
|
||||
"message0": "%1",
|
||||
"args0": [
|
||||
'type': 'math_constant',
|
||||
'message0': '%1',
|
||||
'args0': [
|
||||
{
|
||||
"type": "field_dropdown",
|
||||
"name": "CONSTANT",
|
||||
"options": [
|
||||
["\u03c0", "PI"],
|
||||
["e", "E"],
|
||||
["\u03c6", "GOLDEN_RATIO"],
|
||||
["sqrt(2)", "SQRT2"],
|
||||
["sqrt(\u00bd)", "SQRT1_2"],
|
||||
["\u221e", "INFINITY"],
|
||||
'type': 'field_dropdown',
|
||||
'name': 'CONSTANT',
|
||||
'options': [
|
||||
['\u03c0', 'PI'],
|
||||
['e', 'E'],
|
||||
['\u03c6', 'GOLDEN_RATIO'],
|
||||
['sqrt(2)', 'SQRT2'],
|
||||
['sqrt(\u00bd)', 'SQRT1_2'],
|
||||
['\u221e', 'INFINITY'],
|
||||
],
|
||||
},
|
||||
],
|
||||
"output": "Number",
|
||||
"style": "math_blocks",
|
||||
"tooltip": "%{BKY_MATH_CONSTANT_TOOLTIP}",
|
||||
"helpUrl": "%{BKY_MATH_CONSTANT_HELPURL}",
|
||||
'output': 'Number',
|
||||
'style': 'math_blocks',
|
||||
'tooltip': '%{BKY_MATH_CONSTANT_TOOLTIP}',
|
||||
'helpUrl': '%{BKY_MATH_CONSTANT_HELPURL}',
|
||||
},
|
||||
|
||||
// Block for checking if a number is even, odd, prime, whole, positive,
|
||||
// negative or if it is divisible by certain number.
|
||||
{
|
||||
"type": "math_number_property",
|
||||
"message0": "%1 %2",
|
||||
"args0": [
|
||||
'type': 'math_number_property',
|
||||
'message0': '%1 %2',
|
||||
'args0': [
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "NUMBER_TO_CHECK",
|
||||
"check": "Number",
|
||||
'type': 'input_value',
|
||||
'name': 'NUMBER_TO_CHECK',
|
||||
'check': 'Number',
|
||||
},
|
||||
{
|
||||
"type": "field_dropdown",
|
||||
"name": "PROPERTY",
|
||||
"options": [
|
||||
["%{BKY_MATH_IS_EVEN}", "EVEN"],
|
||||
["%{BKY_MATH_IS_ODD}", "ODD"],
|
||||
["%{BKY_MATH_IS_PRIME}", "PRIME"],
|
||||
["%{BKY_MATH_IS_WHOLE}", "WHOLE"],
|
||||
["%{BKY_MATH_IS_POSITIVE}", "POSITIVE"],
|
||||
["%{BKY_MATH_IS_NEGATIVE}", "NEGATIVE"],
|
||||
["%{BKY_MATH_IS_DIVISIBLE_BY}", "DIVISIBLE_BY"],
|
||||
'type': 'field_dropdown',
|
||||
'name': 'PROPERTY',
|
||||
'options': [
|
||||
['%{BKY_MATH_IS_EVEN}', 'EVEN'],
|
||||
['%{BKY_MATH_IS_ODD}', 'ODD'],
|
||||
['%{BKY_MATH_IS_PRIME}', 'PRIME'],
|
||||
['%{BKY_MATH_IS_WHOLE}', 'WHOLE'],
|
||||
['%{BKY_MATH_IS_POSITIVE}', 'POSITIVE'],
|
||||
['%{BKY_MATH_IS_NEGATIVE}', 'NEGATIVE'],
|
||||
['%{BKY_MATH_IS_DIVISIBLE_BY}', 'DIVISIBLE_BY'],
|
||||
],
|
||||
},
|
||||
],
|
||||
"inputsInline": true,
|
||||
"output": "Boolean",
|
||||
"style": "math_blocks",
|
||||
"tooltip": "%{BKY_MATH_IS_TOOLTIP}",
|
||||
"mutator": "math_is_divisibleby_mutator",
|
||||
'inputsInline': true,
|
||||
'output': 'Boolean',
|
||||
'style': 'math_blocks',
|
||||
'tooltip': '%{BKY_MATH_IS_TOOLTIP}',
|
||||
'mutator': 'math_is_divisibleby_mutator',
|
||||
},
|
||||
|
||||
// Block for adding to a variable in place.
|
||||
{
|
||||
"type": "math_change",
|
||||
"message0": "%{BKY_MATH_CHANGE_TITLE}",
|
||||
"args0": [
|
||||
'type': 'math_change',
|
||||
'message0': '%{BKY_MATH_CHANGE_TITLE}',
|
||||
'args0': [
|
||||
{
|
||||
"type": "field_variable",
|
||||
"name": "VAR",
|
||||
"variable": "%{BKY_MATH_CHANGE_TITLE_ITEM}",
|
||||
'type': 'field_variable',
|
||||
'name': 'VAR',
|
||||
'variable': '%{BKY_MATH_CHANGE_TITLE_ITEM}',
|
||||
},
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "DELTA",
|
||||
"check": "Number",
|
||||
'type': 'input_value',
|
||||
'name': 'DELTA',
|
||||
'check': 'Number',
|
||||
},
|
||||
],
|
||||
"previousStatement": null,
|
||||
"nextStatement": null,
|
||||
"style": "variable_blocks",
|
||||
"helpUrl": "%{BKY_MATH_CHANGE_HELPURL}",
|
||||
"extensions": ["math_change_tooltip"],
|
||||
'previousStatement': null,
|
||||
'nextStatement': null,
|
||||
'style': 'variable_blocks',
|
||||
'helpUrl': '%{BKY_MATH_CHANGE_HELPURL}',
|
||||
'extensions': ['math_change_tooltip'],
|
||||
},
|
||||
|
||||
// Block for rounding functions.
|
||||
{
|
||||
"type": "math_round",
|
||||
"message0": "%1 %2",
|
||||
"args0": [
|
||||
'type': 'math_round',
|
||||
'message0': '%1 %2',
|
||||
'args0': [
|
||||
{
|
||||
"type": "field_dropdown",
|
||||
"name": "OP",
|
||||
"options": [
|
||||
["%{BKY_MATH_ROUND_OPERATOR_ROUND}", "ROUND"],
|
||||
["%{BKY_MATH_ROUND_OPERATOR_ROUNDUP}", "ROUNDUP"],
|
||||
["%{BKY_MATH_ROUND_OPERATOR_ROUNDDOWN}", "ROUNDDOWN"],
|
||||
'type': 'field_dropdown',
|
||||
'name': 'OP',
|
||||
'options': [
|
||||
['%{BKY_MATH_ROUND_OPERATOR_ROUND}', 'ROUND'],
|
||||
['%{BKY_MATH_ROUND_OPERATOR_ROUNDUP}', 'ROUNDUP'],
|
||||
['%{BKY_MATH_ROUND_OPERATOR_ROUNDDOWN}', 'ROUNDDOWN'],
|
||||
],
|
||||
},
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "NUM",
|
||||
"check": "Number",
|
||||
'type': 'input_value',
|
||||
'name': 'NUM',
|
||||
'check': 'Number',
|
||||
},
|
||||
],
|
||||
"output": "Number",
|
||||
"style": "math_blocks",
|
||||
"helpUrl": "%{BKY_MATH_ROUND_HELPURL}",
|
||||
"tooltip": "%{BKY_MATH_ROUND_TOOLTIP}",
|
||||
'output': 'Number',
|
||||
'style': 'math_blocks',
|
||||
'helpUrl': '%{BKY_MATH_ROUND_HELPURL}',
|
||||
'tooltip': '%{BKY_MATH_ROUND_TOOLTIP}',
|
||||
},
|
||||
|
||||
// Block for evaluating a list of numbers to return sum, average, min, max,
|
||||
// etc. Some functions also work on text (min, max, mode, median).
|
||||
{
|
||||
"type": "math_on_list",
|
||||
"message0": "%1 %2",
|
||||
"args0": [
|
||||
'type': 'math_on_list',
|
||||
'message0': '%1 %2',
|
||||
'args0': [
|
||||
{
|
||||
"type": "field_dropdown",
|
||||
"name": "OP",
|
||||
"options": [
|
||||
["%{BKY_MATH_ONLIST_OPERATOR_SUM}", "SUM"],
|
||||
["%{BKY_MATH_ONLIST_OPERATOR_MIN}", "MIN"],
|
||||
["%{BKY_MATH_ONLIST_OPERATOR_MAX}", "MAX"],
|
||||
["%{BKY_MATH_ONLIST_OPERATOR_AVERAGE}", "AVERAGE"],
|
||||
["%{BKY_MATH_ONLIST_OPERATOR_MEDIAN}", "MEDIAN"],
|
||||
["%{BKY_MATH_ONLIST_OPERATOR_MODE}", "MODE"],
|
||||
["%{BKY_MATH_ONLIST_OPERATOR_STD_DEV}", "STD_DEV"],
|
||||
["%{BKY_MATH_ONLIST_OPERATOR_RANDOM}", "RANDOM"],
|
||||
'type': 'field_dropdown',
|
||||
'name': 'OP',
|
||||
'options': [
|
||||
['%{BKY_MATH_ONLIST_OPERATOR_SUM}', 'SUM'],
|
||||
['%{BKY_MATH_ONLIST_OPERATOR_MIN}', 'MIN'],
|
||||
['%{BKY_MATH_ONLIST_OPERATOR_MAX}', 'MAX'],
|
||||
['%{BKY_MATH_ONLIST_OPERATOR_AVERAGE}', 'AVERAGE'],
|
||||
['%{BKY_MATH_ONLIST_OPERATOR_MEDIAN}', 'MEDIAN'],
|
||||
['%{BKY_MATH_ONLIST_OPERATOR_MODE}', 'MODE'],
|
||||
['%{BKY_MATH_ONLIST_OPERATOR_STD_DEV}', 'STD_DEV'],
|
||||
['%{BKY_MATH_ONLIST_OPERATOR_RANDOM}', 'RANDOM'],
|
||||
],
|
||||
},
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "LIST",
|
||||
"check": "Array",
|
||||
'type': 'input_value',
|
||||
'name': 'LIST',
|
||||
'check': 'Array',
|
||||
},
|
||||
],
|
||||
"output": "Number",
|
||||
"style": "math_blocks",
|
||||
"helpUrl": "%{BKY_MATH_ONLIST_HELPURL}",
|
||||
"mutator": "math_modes_of_list_mutator",
|
||||
"extensions": ["math_op_tooltip"],
|
||||
'output': 'Number',
|
||||
'style': 'math_blocks',
|
||||
'helpUrl': '%{BKY_MATH_ONLIST_HELPURL}',
|
||||
'mutator': 'math_modes_of_list_mutator',
|
||||
'extensions': ['math_op_tooltip'],
|
||||
},
|
||||
|
||||
// Block for remainder of a division.
|
||||
{
|
||||
"type": "math_modulo",
|
||||
"message0": "%{BKY_MATH_MODULO_TITLE}",
|
||||
"args0": [
|
||||
'type': 'math_modulo',
|
||||
'message0': '%{BKY_MATH_MODULO_TITLE}',
|
||||
'args0': [
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "DIVIDEND",
|
||||
"check": "Number",
|
||||
'type': 'input_value',
|
||||
'name': 'DIVIDEND',
|
||||
'check': 'Number',
|
||||
},
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "DIVISOR",
|
||||
"check": "Number",
|
||||
'type': 'input_value',
|
||||
'name': 'DIVISOR',
|
||||
'check': 'Number',
|
||||
},
|
||||
],
|
||||
"inputsInline": true,
|
||||
"output": "Number",
|
||||
"style": "math_blocks",
|
||||
"tooltip": "%{BKY_MATH_MODULO_TOOLTIP}",
|
||||
"helpUrl": "%{BKY_MATH_MODULO_HELPURL}",
|
||||
'inputsInline': true,
|
||||
'output': 'Number',
|
||||
'style': 'math_blocks',
|
||||
'tooltip': '%{BKY_MATH_MODULO_TOOLTIP}',
|
||||
'helpUrl': '%{BKY_MATH_MODULO_HELPURL}',
|
||||
},
|
||||
|
||||
// Block for constraining a number between two limits.
|
||||
{
|
||||
"type": "math_constrain",
|
||||
"message0": "%{BKY_MATH_CONSTRAIN_TITLE}",
|
||||
"args0": [
|
||||
'type': 'math_constrain',
|
||||
'message0': '%{BKY_MATH_CONSTRAIN_TITLE}',
|
||||
'args0': [
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "VALUE",
|
||||
"check": "Number",
|
||||
'type': 'input_value',
|
||||
'name': 'VALUE',
|
||||
'check': 'Number',
|
||||
},
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "LOW",
|
||||
"check": "Number",
|
||||
'type': 'input_value',
|
||||
'name': 'LOW',
|
||||
'check': 'Number',
|
||||
},
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "HIGH",
|
||||
"check": "Number",
|
||||
'type': 'input_value',
|
||||
'name': 'HIGH',
|
||||
'check': 'Number',
|
||||
},
|
||||
],
|
||||
"inputsInline": true,
|
||||
"output": "Number",
|
||||
"style": "math_blocks",
|
||||
"tooltip": "%{BKY_MATH_CONSTRAIN_TOOLTIP}",
|
||||
"helpUrl": "%{BKY_MATH_CONSTRAIN_HELPURL}",
|
||||
'inputsInline': true,
|
||||
'output': 'Number',
|
||||
'style': 'math_blocks',
|
||||
'tooltip': '%{BKY_MATH_CONSTRAIN_TOOLTIP}',
|
||||
'helpUrl': '%{BKY_MATH_CONSTRAIN_HELPURL}',
|
||||
},
|
||||
|
||||
// Block for random integer between [X] and [Y].
|
||||
{
|
||||
"type": "math_random_int",
|
||||
"message0": "%{BKY_MATH_RANDOM_INT_TITLE}",
|
||||
"args0": [
|
||||
'type': 'math_random_int',
|
||||
'message0': '%{BKY_MATH_RANDOM_INT_TITLE}',
|
||||
'args0': [
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "FROM",
|
||||
"check": "Number",
|
||||
'type': 'input_value',
|
||||
'name': 'FROM',
|
||||
'check': 'Number',
|
||||
},
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "TO",
|
||||
"check": "Number",
|
||||
'type': 'input_value',
|
||||
'name': 'TO',
|
||||
'check': 'Number',
|
||||
},
|
||||
],
|
||||
"inputsInline": true,
|
||||
"output": "Number",
|
||||
"style": "math_blocks",
|
||||
"tooltip": "%{BKY_MATH_RANDOM_INT_TOOLTIP}",
|
||||
"helpUrl": "%{BKY_MATH_RANDOM_INT_HELPURL}",
|
||||
'inputsInline': true,
|
||||
'output': 'Number',
|
||||
'style': 'math_blocks',
|
||||
'tooltip': '%{BKY_MATH_RANDOM_INT_TOOLTIP}',
|
||||
'helpUrl': '%{BKY_MATH_RANDOM_INT_HELPURL}',
|
||||
},
|
||||
|
||||
// Block for random integer between [X] and [Y].
|
||||
{
|
||||
"type": "math_random_float",
|
||||
"message0": "%{BKY_MATH_RANDOM_FLOAT_TITLE_RANDOM}",
|
||||
"output": "Number",
|
||||
"style": "math_blocks",
|
||||
"tooltip": "%{BKY_MATH_RANDOM_FLOAT_TOOLTIP}",
|
||||
"helpUrl": "%{BKY_MATH_RANDOM_FLOAT_HELPURL}",
|
||||
'type': 'math_random_float',
|
||||
'message0': '%{BKY_MATH_RANDOM_FLOAT_TITLE_RANDOM}',
|
||||
'output': 'Number',
|
||||
'style': 'math_blocks',
|
||||
'tooltip': '%{BKY_MATH_RANDOM_FLOAT_TOOLTIP}',
|
||||
'helpUrl': '%{BKY_MATH_RANDOM_FLOAT_HELPURL}',
|
||||
},
|
||||
|
||||
// Block for calculating atan2 of [X] and [Y].
|
||||
{
|
||||
"type": "math_atan2",
|
||||
"message0": "%{BKY_MATH_ATAN2_TITLE}",
|
||||
"args0": [
|
||||
'type': 'math_atan2',
|
||||
'message0': '%{BKY_MATH_ATAN2_TITLE}',
|
||||
'args0': [
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "X",
|
||||
"check": "Number",
|
||||
'type': 'input_value',
|
||||
'name': 'X',
|
||||
'check': 'Number',
|
||||
},
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "Y",
|
||||
"check": "Number",
|
||||
'type': 'input_value',
|
||||
'name': 'Y',
|
||||
'check': 'Number',
|
||||
},
|
||||
],
|
||||
"inputsInline": true,
|
||||
"output": "Number",
|
||||
"style": "math_blocks",
|
||||
"tooltip": "%{BKY_MATH_ATAN2_TOOLTIP}",
|
||||
"helpUrl": "%{BKY_MATH_ATAN2_HELPURL}",
|
||||
'inputsInline': true,
|
||||
'output': 'Number',
|
||||
'style': 'math_blocks',
|
||||
'tooltip': '%{BKY_MATH_ATAN2_TOOLTIP}',
|
||||
'helpUrl': '%{BKY_MATH_ATAN2_HELPURL}',
|
||||
},
|
||||
]);
|
||||
|
||||
/**
|
||||
* Mapping of math block OP value to tooltip message for blocks
|
||||
* math_arithmetic, math_simple, math_trig, and math_on_lists.
|
||||
* @see {Blockly.Extensions#buildTooltipForDropdown}
|
||||
* @see {Extensions#buildTooltipForDropdown}
|
||||
* @package
|
||||
* @readonly
|
||||
*/
|
||||
Blockly.Constants.Math.TOOLTIPS_BY_OP = {
|
||||
const TOOLTIPS_BY_OP = {
|
||||
// math_arithmetic
|
||||
'ADD': '%{BKY_MATH_ARITHMETIC_TOOLTIP_ADD}',
|
||||
'MINUS': '%{BKY_MATH_ARITHMETIC_TOOLTIP_MINUS}',
|
||||
@@ -425,27 +428,27 @@ Blockly.Constants.Math.TOOLTIPS_BY_OP = {
|
||||
'RANDOM': '%{BKY_MATH_ONLIST_TOOLTIP_RANDOM}',
|
||||
};
|
||||
|
||||
Blockly.Extensions.register('math_op_tooltip',
|
||||
Blockly.Extensions.buildTooltipForDropdown(
|
||||
'OP', Blockly.Constants.Math.TOOLTIPS_BY_OP));
|
||||
Extensions.register(
|
||||
'math_op_tooltip',
|
||||
Extensions.buildTooltipForDropdown('OP', TOOLTIPS_BY_OP));
|
||||
|
||||
|
||||
/**
|
||||
* Mixin for mutator functions in the 'math_is_divisibleby_mutator'
|
||||
* extension.
|
||||
* @mixin
|
||||
* @augments Blockly.Block
|
||||
* @augments Block
|
||||
* @package
|
||||
*/
|
||||
Blockly.Constants.Math.IS_DIVISIBLEBY_MUTATOR_MIXIN = {
|
||||
const IS_DIVISIBLEBY_MUTATOR_MIXIN = {
|
||||
/**
|
||||
* Create XML to represent whether the 'divisorInput' should be present.
|
||||
* Backwards compatible serialization implementation.
|
||||
* @return {!Element} XML storage element.
|
||||
* @this {Blockly.Block}
|
||||
* @this {Block}
|
||||
*/
|
||||
mutationToDom: function() {
|
||||
const container = Blockly.utils.xml.createElement('mutation');
|
||||
const container = xmlUtils.createElement('mutation');
|
||||
const divisorInput = (this.getFieldValue('PROPERTY') === 'DIVISIBLE_BY');
|
||||
container.setAttribute('divisor_input', divisorInput);
|
||||
return container;
|
||||
@@ -454,7 +457,7 @@ Blockly.Constants.Math.IS_DIVISIBLEBY_MUTATOR_MIXIN = {
|
||||
* Parse XML to restore the 'divisorInput'.
|
||||
* Backwards compatible serialization implementation.
|
||||
* @param {!Element} xmlElement XML storage element.
|
||||
* @this {Blockly.Block}
|
||||
* @this {Block}
|
||||
*/
|
||||
domToMutation: function(xmlElement) {
|
||||
const divisorInput = (xmlElement.getAttribute('divisor_input') === 'true');
|
||||
@@ -470,15 +473,14 @@ Blockly.Constants.Math.IS_DIVISIBLEBY_MUTATOR_MIXIN = {
|
||||
* Modify this block to have (or not have) an input for 'is divisible by'.
|
||||
* @param {boolean} divisorInput True if this block has a divisor input.
|
||||
* @private
|
||||
* @this {Blockly.Block}
|
||||
* @this {Block}
|
||||
*/
|
||||
updateShape_: function(divisorInput) {
|
||||
// Add or remove a Value Input.
|
||||
const inputExists = this.getInput('DIVISOR');
|
||||
if (divisorInput) {
|
||||
if (!inputExists) {
|
||||
this.appendValueInput('DIVISOR')
|
||||
.setCheck('Number');
|
||||
this.appendValueInput('DIVISOR').setCheck('Number');
|
||||
}
|
||||
} else if (inputExists) {
|
||||
this.removeInput('DIVISOR');
|
||||
@@ -490,45 +492,45 @@ Blockly.Constants.Math.IS_DIVISIBLEBY_MUTATOR_MIXIN = {
|
||||
* 'math_is_divisibleby_mutator' extension to the 'math_property' block that
|
||||
* can update the block shape (add/remove divisor input) based on whether
|
||||
* property is "divisible by".
|
||||
* @this {Blockly.Block}
|
||||
* @this {Block}
|
||||
* @package
|
||||
*/
|
||||
Blockly.Constants.Math.IS_DIVISIBLE_MUTATOR_EXTENSION = function() {
|
||||
this.getField('PROPERTY').setValidator(
|
||||
/**
|
||||
* @this {Blockly.FieldDropdown}
|
||||
* @param {*} option The selected dropdown option.
|
||||
*/
|
||||
function(option) {
|
||||
const divisorInput = (option === 'DIVISIBLE_BY');
|
||||
this.getSourceBlock().updateShape_(divisorInput);
|
||||
}
|
||||
);
|
||||
const IS_DIVISIBLE_MUTATOR_EXTENSION = function() {
|
||||
this.getField('PROPERTY')
|
||||
.setValidator(
|
||||
/**
|
||||
* @this {FieldDropdown}
|
||||
* @param {*} option The selected dropdown option.
|
||||
*/
|
||||
function(option) {
|
||||
const divisorInput = (option === 'DIVISIBLE_BY');
|
||||
this.getSourceBlock().updateShape_(divisorInput);
|
||||
});
|
||||
};
|
||||
|
||||
Blockly.Extensions.registerMutator('math_is_divisibleby_mutator',
|
||||
Blockly.Constants.Math.IS_DIVISIBLEBY_MUTATOR_MIXIN,
|
||||
Blockly.Constants.Math.IS_DIVISIBLE_MUTATOR_EXTENSION);
|
||||
Extensions.registerMutator(
|
||||
'math_is_divisibleby_mutator', IS_DIVISIBLEBY_MUTATOR_MIXIN,
|
||||
IS_DIVISIBLE_MUTATOR_EXTENSION);
|
||||
|
||||
// Update the tooltip of 'math_change' block to reference the variable.
|
||||
Blockly.Extensions.register('math_change_tooltip',
|
||||
Blockly.Extensions.buildTooltipWithFieldText(
|
||||
'%{BKY_MATH_CHANGE_TOOLTIP}', 'VAR'));
|
||||
Extensions.register(
|
||||
'math_change_tooltip',
|
||||
Extensions.buildTooltipWithFieldText('%{BKY_MATH_CHANGE_TOOLTIP}', 'VAR'));
|
||||
|
||||
/**
|
||||
* Mixin with mutator methods to support alternate output based if the
|
||||
* 'math_on_list' block uses the 'MODE' operation.
|
||||
* @mixin
|
||||
* @augments Blockly.Block
|
||||
* @augments Block
|
||||
* @package
|
||||
* @readonly
|
||||
*/
|
||||
Blockly.Constants.Math.LIST_MODES_MUTATOR_MIXIN = {
|
||||
const LIST_MODES_MUTATOR_MIXIN = {
|
||||
/**
|
||||
* Modify this block to have the correct output type.
|
||||
* @param {string} newOp Either 'MODE' or some op than returns a number.
|
||||
* @private
|
||||
* @this {Blockly.Block}
|
||||
* @this {Block}
|
||||
*/
|
||||
updateType_: function(newOp) {
|
||||
if (newOp === 'MODE') {
|
||||
@@ -541,10 +543,10 @@ Blockly.Constants.Math.LIST_MODES_MUTATOR_MIXIN = {
|
||||
* Create XML to represent the output type.
|
||||
* Backwards compatible serialization implementation.
|
||||
* @return {!Element} XML storage element.
|
||||
* @this {Blockly.Block}
|
||||
* @this {Block}
|
||||
*/
|
||||
mutationToDom: function() {
|
||||
const container = Blockly.utils.xml.createElement('mutation');
|
||||
const container = xmlUtils.createElement('mutation');
|
||||
container.setAttribute('op', this.getFieldValue('OP'));
|
||||
return container;
|
||||
},
|
||||
@@ -552,7 +554,7 @@ Blockly.Constants.Math.LIST_MODES_MUTATOR_MIXIN = {
|
||||
* Parse XML to restore the output type.
|
||||
* Backwards compatible serialization implementation.
|
||||
* @param {!Element} xmlElement XML storage element.
|
||||
* @this {Blockly.Block}
|
||||
* @this {Block}
|
||||
*/
|
||||
domToMutation: function(xmlElement) {
|
||||
this.updateType_(xmlElement.getAttribute('op'));
|
||||
@@ -567,15 +569,15 @@ Blockly.Constants.Math.LIST_MODES_MUTATOR_MIXIN = {
|
||||
/**
|
||||
* Extension to 'math_on_list' blocks that allows support of
|
||||
* modes operation (outputs a list of numbers).
|
||||
* @this {Blockly.Block}
|
||||
* @this {Block}
|
||||
* @package
|
||||
*/
|
||||
Blockly.Constants.Math.LIST_MODES_MUTATOR_EXTENSION = function() {
|
||||
const LIST_MODES_MUTATOR_EXTENSION = function() {
|
||||
this.getField('OP').setValidator(function(newOp) {
|
||||
this.updateType_(newOp);
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
Blockly.Extensions.registerMutator('math_modes_of_list_mutator',
|
||||
Blockly.Constants.Math.LIST_MODES_MUTATOR_MIXIN,
|
||||
Blockly.Constants.Math.LIST_MODES_MUTATOR_EXTENSION);
|
||||
Extensions.registerMutator(
|
||||
'math_modes_of_list_mutator', LIST_MODES_MUTATOR_MIXIN,
|
||||
LIST_MODES_MUTATOR_EXTENSION);
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
"./core/renderers/zelos/constants.js",
|
||||
"./core/renderers/zelos/path_object.js",
|
||||
"./core/field_image.js",
|
||||
"./core/field_textinput.js",
|
||||
"./core/renderers/zelos/marker_svg.js",
|
||||
"./core/renderers/zelos/renderer.js",
|
||||
"./core/renderers/zelos/measurables/row_elements.js",
|
||||
@@ -48,7 +47,6 @@
|
||||
"./core/renderers/zelos/zelos.js",
|
||||
"./core/toolbox/collapsible_category.js",
|
||||
"./core/field_angle.js",
|
||||
"./core/field_checkbox.js",
|
||||
"./core/field_colour.js",
|
||||
"./core/field_label_serializable.js",
|
||||
"./core/field_multilineinput.js",
|
||||
@@ -64,6 +62,8 @@
|
||||
"./core/field_variable.js",
|
||||
"./core/field_number.js",
|
||||
"./core/field_dropdown.js",
|
||||
"./core/field_checkbox.js",
|
||||
"./core/field_textinput.js",
|
||||
"./core/events/workspace_events.js",
|
||||
"./core/events/events_toolbox_item_select.js",
|
||||
"./core/events/events_ui.js",
|
||||
|
||||
@@ -3,7 +3,7 @@ goog.addDependency('../../blocks/colour.js', ['Blockly.blocks.colour'], ['Blockl
|
||||
goog.addDependency('../../blocks/lists.js', ['Blockly.blocks.lists'], ['Blockly.ConnectionType', 'Blockly.FieldDropdown', 'Blockly.Input', 'Blockly.Msg', 'Blockly.Mutator', 'Blockly.blocks', 'Blockly.common', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../blocks/logic.js', ['Blockly.blocks.logic'], ['Blockly.Events', 'Blockly.Extensions', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.Msg', 'Blockly.Mutator', 'Blockly.common', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../blocks/loops.js', ['Blockly.blocks.loops'], ['Blockly.ContextMenu', 'Blockly.Events', 'Blockly.Extensions', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable', 'Blockly.Msg', 'Blockly.Variables', 'Blockly.Warning', 'Blockly.common', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../blocks/math.js', ['Blockly.Constants.Math', 'Blockly.blocks.math'], ['Blockly', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable'], {'lang': 'es6'});
|
||||
goog.addDependency('../../blocks/math.js', ['Blockly.blocks.math'], ['Blockly.Extensions', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable', 'Blockly.common', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../blocks/procedures.js', ['Blockly.blocks.procedures'], ['Blockly.Comment', 'Blockly.ContextMenu', 'Blockly.Events', 'Blockly.FieldCheckbox', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.Input', 'Blockly.Msg', 'Blockly.Mutator', 'Blockly.Names', 'Blockly.Procedures', 'Blockly.Variables', 'Blockly.Warning', 'Blockly.Xml', 'Blockly.blocks', 'Blockly.internalConstants', 'Blockly.utils.xml'], {'lang': 'es9', 'module': 'goog'});
|
||||
goog.addDependency('../../blocks/text.js', ['Blockly.Constants.Text', 'Blockly.blocks.texts'], ['Blockly', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldMultilineInput', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.Mutator'], {'lang': 'es6'});
|
||||
goog.addDependency('../../blocks/variables.js', ['Blockly.Constants.Variables', 'Blockly.blocks.variables'], ['Blockly', 'Blockly.FieldLabel', 'Blockly.FieldVariable'], {'lang': 'es6'});
|
||||
|
||||
Reference in New Issue
Block a user