blocks.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * Blockly Demos: Plane Seat Calculator Blocks
  3. *
  4. * Copyright 2013 Google Inc.
  5. * https://developers.google.com/blockly/
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. */
  19. /**
  20. * @fileoverview Blocks for Blockly's Plane Seat Calculator application.
  21. * @author fraser@google.com (Neil Fraser)
  22. */
  23. 'use strict';
  24. Blockly.Blocks['plane_set_seats'] = {
  25. // Block seat variable setter.
  26. init: function() {
  27. this.setHelpUrl(Blockly.Msg.VARIABLES_SET_HELPURL);
  28. this.setColour(330);
  29. this.appendValueInput('VALUE')
  30. .appendField(Plane.getMsg('Plane_setSeats'));
  31. this.setTooltip(Blockly.Msg.VARIABLES_SET_TOOLTIP);
  32. this.setDeletable(false);
  33. }
  34. };
  35. Blockly.JavaScript['plane_set_seats'] = function(block) {
  36. // Generate JavaScript for seat variable setter.
  37. var argument0 = Blockly.JavaScript.valueToCode(block, 'VALUE',
  38. Blockly.JavaScript.ORDER_ASSIGNMENT) || 'NaN';
  39. return argument0 + ';';
  40. };
  41. Blockly.Blocks['plane_get_rows'] = {
  42. // Block for row variable getter.
  43. init: function() {
  44. this.setHelpUrl(Blockly.Msg.VARIABLES_GET_HELPURL);
  45. this.setColour(330);
  46. this.appendDummyInput()
  47. .appendField(Plane.getMsg('Plane_getRows'), 'title');
  48. this.setOutput(true, 'Number');
  49. },
  50. customUpdate: function() {
  51. this.setFieldValue(
  52. Plane.getMsg('Plane_getRows').replace('%1', Plane.rows1st), 'title');
  53. }
  54. };
  55. Blockly.JavaScript['plane_get_rows'] = function(block) {
  56. // Generate JavaScript for row variable getter.
  57. return ['Plane.rows1st', Blockly.JavaScript.ORDER_MEMBER];
  58. };
  59. Blockly.Blocks['plane_get_rows1st'] = {
  60. // Block for first class row variable getter.
  61. init: function() {
  62. this.setHelpUrl(Blockly.Msg.VARIABLES_GET_HELPURL);
  63. this.setColour(330);
  64. this.appendDummyInput()
  65. .appendField(Plane.getMsg('Plane_getRows1'), 'title');
  66. this.setOutput(true, 'Number');
  67. },
  68. customUpdate: function() {
  69. this.setFieldValue(
  70. Plane.getMsg('Plane_getRows1').replace('%1', Plane.rows1st), 'title');
  71. }
  72. };
  73. Blockly.JavaScript['plane_get_rows1st'] = function(block) {
  74. // Generate JavaScript for first class row variable getter.
  75. return ['Plane.rows1st', Blockly.JavaScript.ORDER_MEMBER];
  76. };
  77. Blockly.Blocks['plane_get_rows2nd'] = {
  78. // Block for second class row variable getter.
  79. init: function() {
  80. this.setHelpUrl(Blockly.Msg.VARIABLES_GET_HELPURL);
  81. this.setColour(330);
  82. this.appendDummyInput()
  83. .appendField(Plane.getMsg('Plane_getRows2'), 'title');
  84. this.setOutput(true, 'Number');
  85. },
  86. customUpdate: function() {
  87. this.setFieldValue(
  88. Plane.getMsg('Plane_getRows2').replace('%1', Plane.rows2nd), 'title');
  89. }
  90. };
  91. Blockly.JavaScript['plane_get_rows2nd'] = function(block) {
  92. // Generate JavaScript for second class row variable getter.
  93. return ['Plane.rows2nd', Blockly.JavaScript.ORDER_MEMBER];
  94. };