-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31d0f00
commit a277580
Showing
3 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
src/blockly10/src/BlocklyReusable/BlocklyNewBlocks/UnaryOperator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// import * as Blockly from "blockly/core"; | ||
import { IBlocksSimple } from "../blocksInterface"; | ||
//imported from | ||
//https://github.com/carloslfu/ =>/javascript/blocks/expressions.j | ||
export class UnaryOperator implements IBlocksSimple { | ||
definitionBlocksSimple(blocks: any, javascriptGenerator: any): void { | ||
blocks[UnaryOperator.nameBlock] = { | ||
init: function() { | ||
var OPERATORS = [ | ||
['++', '++'], | ||
['--', '--'], | ||
]; | ||
this.jsonInit({ | ||
"id": UnaryOperator.nameBlock, | ||
"message0": "set %1 %2", | ||
"args0": [ | ||
{ | ||
"type": "input_value", | ||
"name": "VAR" | ||
}, | ||
{ | ||
"type": "field_dropdown", | ||
"name": "OPERATOR", | ||
"options": OPERATORS | ||
} | ||
], | ||
"colour": 330, | ||
"previousStatement": "Statement", | ||
"nextStatement": "Statement", | ||
"inputsInline": true, | ||
"tooltip": "Assignment expression." | ||
}); | ||
} | ||
}; | ||
|
||
javascriptGenerator[UnaryOperator.nameBlock] = function(block:any) { | ||
var variable = javascriptGenerator.valueToCode(block, 'VAR', | ||
javascriptGenerator.ORDER_ASSIGNMENT); | ||
var operator = block.getFieldValue('OPERATOR'); | ||
var code = variable + ' ' + operator ; | ||
//If has output returns a tuple with the order of precedence | ||
if (block.outputConnection) { | ||
return [code, javascriptGenerator.ORDER_ASSIGNMENT]; | ||
} else { | ||
return code + ';\n'; | ||
} | ||
}; | ||
|
||
} | ||
addWrapper(interpreter: any, globalObject: any) { | ||
|
||
} | ||
fieldXML(): string { | ||
return `<block type="${UnaryOperator.nameBlock}"> | ||
</block>`; | ||
} | ||
category: string='MoreMath'; | ||
public static nameBlock: string = "unaryOperator"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters