123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435 |
- 'use strict';
- goog.provide('Blockly.Blocks.utility');
- goog.require('Blockly.Blocks');
- Blockly.Blocks.utility.HUE = 160;
- Blockly.Blocks['raw_table'] = {
-
- init: function() {
- this.setColour(Blockly.Blocks.utility.HUE);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.appendDummyInput()
- .appendField('Tabular Abstraction:');
- this.appendDummyInput()
- .appendField(new Blockly.FieldTable(''), 'TEXT');
- }
- };
- Blockly.Blocks['raw_block'] = {
-
- init: function() {
- this.setColour(Blockly.Blocks.utility.HUE);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.appendDummyInput()
- .appendField('Code Block:');
- this.appendDummyInput()
- .appendField(new Blockly.FieldTextArea(''), 'TEXT');
- }
- };
- Blockly.Blocks['raw_expression'] = {
-
- init: function() {
- this.setColour(Blockly.Blocks.utility.HUE);
- this.appendDummyInput()
- .appendField('Code Expression:');
- this.appendDummyInput()
- .appendField(new Blockly.FieldTextArea(''), 'TEXT');
- this.setOutput(true);
- }
- };
- Blockly.Blocks['raw_empty'] = {
-
- init: function() {
- this.setColour(Blockly.Blocks.utility.HUE);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.appendValueInput('VALUE')
- .appendField('');
- this.setInputsInline(false);
- }
- };
- Blockly.Blocks['text_comment'] = {
-
- init: function() {
- this.setColour(Blockly.Blocks.utility.HUE);
- this.appendDummyInput()
- .appendTitle('Comment:')
- .appendTitle(new Blockly.FieldTextInput(''), 'TEXT');
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setTooltip('This comment will be ignored by Python');
- }
- };
- Blockly.Blocks['type_check'] = {
-
- init: function() {
- this.setColour(Blockly.Blocks.utility.HUE);
- this.appendValueInput('VALUE')
- .appendField(Blockly.Msg.TYPE_CHECK);
- this.setInputsInline(false);
- this.setOutput(true, 'Type');
-
-
- }
- };
- Blockly.Blocks['text_print_multiple'] = {
-
- init: function() {
- this.setColour(Blockly.Blocks.utility.HUE);
- this.itemCount_ = 1;
- this.updateShape_();
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setMutator(new Blockly.Mutator(['text_print_multiple_item']));
- this.setTooltip(Blockly.Msg.TEXT_PRINT_TOOLTIP);
- },
-
- mutationToDom: function(workspace) {
- var container = document.createElement('mutation');
- container.setAttribute('items', this.itemCount_);
- return container;
- },
-
- domToMutation: function(xmlElement) {
- this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
- this.updateShape_();
- },
-
- decompose: function(workspace) {
- var containerBlock = Blockly.Block.obtain(workspace,
- 'text_print_multiple_container');
- containerBlock.initSvg();
- var connection = containerBlock.getInput('STACK').connection;
- for (var x = 0; x < this.itemCount_; x++) {
- var itemBlock = Blockly.Block.obtain(workspace, 'text_print_multiple_item');
- itemBlock.initSvg();
- connection.connect(itemBlock.previousConnection);
- connection = itemBlock.nextConnection;
- }
- return containerBlock;
- },
-
- compose: function(containerBlock) {
- var itemBlock = containerBlock.getInputTargetBlock('STACK');
-
- var connections = [];
- var i = 0;
- while (itemBlock) {
- connections[i] = itemBlock.valueConnection_;
- itemBlock = itemBlock.nextConnection &&
- itemBlock.nextConnection.targetBlock();
- i++;
- }
- this.itemCount_ = i;
- this.updateShape_();
-
- for (var i = 0; i < this.itemCount_; i++) {
- if (connections[i]) {
- this.getInput('PRINT' + i).connection.connect(connections[i]);
- }
- }
- },
-
- saveConnections: function(containerBlock) {
-
- var itemBlock = containerBlock.getInputTargetBlock('STACK');
- var x = 0;
- while (itemBlock) {
- var input = this.getInput('PRINT' + x);
- itemBlock.valueConnection_ = input && input.connection.targetConnection;
- x++;
- itemBlock = itemBlock.nextConnection &&
- itemBlock.nextConnection.targetBlock();
- }
- },
-
- updateShape_: function() {
-
- if (this.getInput('EMPTY')) {
- this.removeInput('EMPTY');
- } else {
- var i = 0;
- while (this.getInput('PRINT' + i)) {
- this.removeInput('PRINT' + i);
- i++;
- }
- }
-
-
- if (this.itemCount_ == 0) {
- this.appendDummyInput('EMPTY')
- .appendField("print");
- } else {
- for (var i = 0; i < this.itemCount_; i++) {
- var input = this.appendValueInput('PRINT' + i);
- if (i == 0) {
- input.appendField("print");
- }
- }
- }
- }
- };
- Blockly.Blocks['text_print_multiple_container'] = {
-
- init: function() {
- this.setColour(Blockly.Blocks.utility.HUE);
- this.appendDummyInput()
- .appendField('print');
- this.appendStatementInput('STACK');
- this.setTooltip('');
- this.contextMenu = false;
- }
- };
- Blockly.Blocks['text_print_multiple_item'] = {
-
- init: function() {
- this.setColour(Blockly.Blocks.utility.HUE);
- this.appendDummyInput()
- .appendField('item');
- this.setInputsInline(true);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setTooltip('');
- this.contextMenu = false;
- }
- };
- Blockly.Blocks['function_call'] = {
-
- init: function() {
- this.setColour(Blockly.Blocks.utility.HUE);
- this.itemCount_ = 1;
- this.hasReturn_ = false;
- this.appendDummyInput()
- .appendField(new Blockly.FieldTextInput("str"), 'NAME');
- this.updateShape_();
- this.setMutator(new Blockly.Mutator(['function_call_item']));
- this.setTooltip("Can be used to call any function");
- },
-
- mutationToDom: function(workspace) {
- var container = document.createElement('mutation');
- container.setAttribute('items', this.itemCount_);
- container.setAttribute('hasReturn', this.hasReturn_ ? "TRUE": "FALSE");
- return container;
- },
-
- domToMutation: function(xmlElement) {
- this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
- this.hasReturn_ = xmlElement.getAttribute('hasReturn') === "TRUE";
- this.updateShape_();
- },
-
- decompose: function(workspace) {
- var containerBlock = Blockly.Block.obtain(workspace,
- 'function_call_container');
- containerBlock.initSvg();
-
- containerBlock.setFieldValue(this.hasStatements_ ? 'TRUE' : 'FALSE',
- 'RETURN');
-
- var connection = containerBlock.getInput('STACK').connection;
- for (var x = 0; x < this.itemCount_; x++) {
- var itemBlock = Blockly.Block.obtain(workspace, 'function_call_item');
- itemBlock.initSvg();
- connection.connect(itemBlock.previousConnection);
- connection = itemBlock.nextConnection;
- }
- return containerBlock;
- },
-
- setReturn: function(returnState) {
- this.unplug(true, true);
- this.setOutput(returnState);
- this.setPreviousStatement(!returnState);
- this.setNextStatement(!returnState);
- if (this.rendered) {
- this.render();
- }
- },
-
- compose: function(containerBlock) {
- var itemBlock = containerBlock.getInputTargetBlock('STACK');
-
- var connections = [];
- var i = 0;
- while (itemBlock) {
- connections[i] = itemBlock.valueConnection_;
- itemBlock = itemBlock.nextConnection &&
- itemBlock.nextConnection.targetBlock();
- i++;
- }
- this.itemCount_ = i;
-
- this.hasReturn_ = containerBlock.getFieldValue("RETURN") === "TRUE";
-
- this.updateShape_();
-
- for (var i = 0; i < this.itemCount_; i++) {
- if (connections[i]) {
- this.getInput('ARGUMENT' + i).connection.connect(connections[i]);
- }
- }
- },
-
- saveConnections: function(containerBlock) {
-
- var itemBlock = containerBlock.getInputTargetBlock('STACK');
- var x = 0;
- while (itemBlock) {
- var input = this.getInput('ARGUMENT' + x);
- itemBlock.valueConnection_ = input && input.connection.targetConnection;
- x++;
- itemBlock = itemBlock.nextConnection &&
- itemBlock.nextConnection.targetBlock();
- }
- },
-
- updateShape_: function() {
-
- if (this.getInput('EMPTY')) {
- this.removeInput('EMPTY');
- } else {
- var i = 0;
- while (this.getInput('ARGUMENT' + i)) {
- this.removeInput('ARGUMENT' + i);
- i++;
- }
- }
-
-
- for (var i = 0; i < this.itemCount_; i++) {
- var input = this.appendValueInput('ARGUMENT' + i);
- }
-
-
- this.setReturn(this.hasReturn_);
- }
- };
- Blockly.Blocks['function_call_container'] = {
-
- init: function() {
- this.setColour(Blockly.Blocks.utility.HUE);
- this.appendDummyInput()
- .appendField('Arguments');
- this.appendStatementInput('STACK');
- this.appendDummyInput()
- .setAlign(Blockly.ALIGN_RIGHT)
- .appendField('has return')
- .appendField(new Blockly.FieldCheckbox('TRUE'),
- 'RETURN');
- this.setTooltip('');
- this.contextMenu = false;
- }
- };
- Blockly.Blocks['function_call_item'] = {
-
- init: function() {
- this.setColour(Blockly.Blocks.utility.HUE);
- this.appendDummyInput()
- .appendField('argument');
- this.setInputsInline(true);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setTooltip('');
- this.contextMenu = false;
- }
- };
|