Skip to content

Commit a277580

Browse files
committed
added unary operator
1 parent 31d0f00 commit a277580

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// import * as Blockly from "blockly/core";
2+
import { IBlocksSimple } from "../blocksInterface";
3+
//imported from
4+
//https://github.com/carloslfu/ =>/javascript/blocks/expressions.j
5+
export class UnaryOperator implements IBlocksSimple {
6+
definitionBlocksSimple(blocks: any, javascriptGenerator: any): void {
7+
blocks[UnaryOperator.nameBlock] = {
8+
init: function() {
9+
var OPERATORS = [
10+
['++', '++'],
11+
['--', '--'],
12+
];
13+
this.jsonInit({
14+
"id": UnaryOperator.nameBlock,
15+
"message0": "set %1 %2",
16+
"args0": [
17+
{
18+
"type": "input_value",
19+
"name": "VAR"
20+
},
21+
{
22+
"type": "field_dropdown",
23+
"name": "OPERATOR",
24+
"options": OPERATORS
25+
}
26+
],
27+
"colour": 330,
28+
"previousStatement": "Statement",
29+
"nextStatement": "Statement",
30+
"inputsInline": true,
31+
"tooltip": "Assignment expression."
32+
});
33+
}
34+
};
35+
36+
javascriptGenerator[UnaryOperator.nameBlock] = function(block:any) {
37+
var variable = javascriptGenerator.valueToCode(block, 'VAR',
38+
javascriptGenerator.ORDER_ASSIGNMENT);
39+
var operator = block.getFieldValue('OPERATOR');
40+
var code = variable + ' ' + operator ;
41+
//If has output returns a tuple with the order of precedence
42+
if (block.outputConnection) {
43+
return [code, javascriptGenerator.ORDER_ASSIGNMENT];
44+
} else {
45+
return code + ';\n';
46+
}
47+
};
48+
49+
}
50+
addWrapper(interpreter: any, globalObject: any) {
51+
52+
}
53+
fieldXML(): string {
54+
return `<block type="${UnaryOperator.nameBlock}">
55+
</block>`;
56+
}
57+
category: string='MoreMath';
58+
public static nameBlock: string = "unaryOperator";
59+
}

src/blockly10/src/BlocklyReusable/BlocklyNewBlocks/moreOperators.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@ export class MoreOperators implements IBlocksSimple {
7171
return `<block type="${MoreOperators.nameBlock}">
7272
</block>`;
7373
}
74-
category: string='other';
74+
category: string='MoreMath';
7575
public static nameBlock: string = "js_assignment_expression";
7676
}

src/blockly10/src/BlocklyReusable/allNewBlocks.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { SwitchBlock } from "./BlocklyNewBlocks/switch";
2525
import { SpecialCharBlock } from "./BlocklyNewBlocks/specialChar";
2626
import { MoreOperators } from "./BlocklyNewBlocks/moreOperators";
2727
import { comment } from "./BlocklyNewBlocks/meta/comment";
28+
import { UnaryOperator } from "./BlocklyNewBlocks/UnaryOperator";
2829

2930
export default class AllNewBlocks
3031
{
@@ -71,7 +72,8 @@ export default class AllNewBlocks
7172
new SwitchBlock(),
7273
new SpecialCharBlock(),
7374
new MoreOperators(),
74-
new comment()
75+
new comment(),
76+
new UnaryOperator()
7577
];
7678
return this.nb;
7779
}

0 commit comments

Comments
 (0)