forked from microsoft/pxt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroundingOperations.ts
More file actions
45 lines (39 loc) · 1.51 KB
/
roundingOperations.ts
File metadata and controls
45 lines (39 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
namespace pxt.blocks {
const allOperations = pxt.blocks.ROUNDING_FUNCTIONS;
export function initMathRoundBlock() {
const mathRoundId = "math_js_round";
const mathRoundDef = pxt.blocks.getBlockDefinition(mathRoundId);
Blockly.Blocks[mathRoundId] = {
init: function () {
const b = this as Blockly.Block;
b.setPreviousStatement(false);
b.setNextStatement(false);
b.setOutput(true, "Number");
b.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
b.setInputsInline(true);
const ddi = b.appendDummyInput("round_dropdown")
ddi.appendField(
new Blockly.FieldDropdown(allOperations.map(op => [mathRoundDef.block[op], op]),
(op: string) => onOperatorSelect(b, op)),
"OP");
addArgInput(b);
}
};
installHelpResources(
mathRoundId,
mathRoundDef.name,
function (block: Blockly.Block) {
return (mathRoundDef.tooltip as Map<string>)[block.getFieldValue("OP")];
},
mathRoundDef.url,
pxt.toolbox.getNamespaceColor(mathRoundDef.category)
);
function onOperatorSelect(b: Blockly.Block, op: string) {
// No-op
}
function addArgInput(b: Blockly.Block) {
const i = b.appendValueInput("ARG0");
i.setCheck("Number");
}
}
}