variables.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * @license Licensed under the Apache License, Version 2.0 (the "License"):
  3. * http://www.apache.org/licenses/LICENSE-2.0
  4. */
  5. /**
  6. * @fileoverview Block for the Arduino map functionality.
  7. * The Arduino built in functions syntax can be found at:
  8. * http://arduino.cc/en/Reference/HomePage
  9. *
  10. * TODO: This block can be improved to set the new range properly.
  11. */
  12. 'use strict';
  13. goog.require('Blockly.Blocks');
  14. goog.require('Blockly.Types');
  15. /** Common HSV hue for all blocks in this category. */
  16. Blockly.Blocks.variables.HUE = 20;
  17. Blockly.Blocks['variables_set_type'] = {
  18. /**
  19. * Block for variable casting.
  20. * @this Blockly.Block
  21. */
  22. init: function() {
  23. this.setHelpUrl('http://arduino.cc/en/Reference/HomePage');
  24. // this.setColour(Blockly.Blocks.variables.HUE);
  25. this.appendValueInput('VARIABLE_SETTYPE_INPUT');
  26. this.appendDummyInput()
  27. .appendField(Blockly.Msg.ARD_VAR_AS)
  28. .appendField(new Blockly.FieldDropdown(
  29. Blockly.Types.getValidTypeArray()),
  30. 'VARIABLE_SETTYPE_TYPE');
  31. this.setInputsInline(true);
  32. this.setOutput(true);
  33. this.setTooltip(Blockly.Msg.ARD_VAR_AS_TIP);
  34. this.setColour(30);
  35. },
  36. /**
  37. * Assigns a type to the block based on the selected type to cast.
  38. * @return {!string} Blockly type for this block configuration.
  39. * @this Blockly.Block
  40. */
  41. getBlockType: function() {
  42. var blocklyTypeKey = this.getFieldValue('VARIABLE_SETTYPE_TYPE');
  43. return Blockly.Types[blocklyTypeKey];
  44. }
  45. };