standard_categories.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. /**
  2. * @license
  3. * Blockly Demos: Block Factory
  4. *
  5. * Copyright 2016 Google Inc.
  6. * https://developers.google.com/blockly/
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. /**
  21. * @fileoverview Contains a map of standard Blockly categories used to load
  22. * standard Blockly categories into the user's toolbox. The map is keyed by
  23. * the lower case name of the category, and contains the Category object for
  24. * that particular category. Also has a list of core block types provided
  25. * by Blockly.
  26. *
  27. * @author Emma Dauterman (evd2014)
  28. */
  29. 'use strict';
  30. /**
  31. * Namespace for StandardCategories
  32. */
  33. goog.provide('StandardCategories');
  34. // Map of standard category information necessary to add a standard category
  35. // to the toolbox.
  36. StandardCategories.categoryMap = Object.create(null);
  37. StandardCategories.categoryMap['logic'] =
  38. new ListElement(ListElement.TYPE_CATEGORY, 'Logic');
  39. StandardCategories.categoryMap['logic'].xml =
  40. Blockly.Xml.textToDom(
  41. '<xml>' +
  42. '<block type="controls_if"></block>' +
  43. '<block type="logic_compare"></block>' +
  44. '<block type="logic_operation"></block>' +
  45. '<block type="logic_negate"></block>' +
  46. '<block type="logic_boolean"></block>' +
  47. '<block type="logic_null"></block>' +
  48. '<block type="logic_ternary"></block>' +
  49. '</xml>');
  50. StandardCategories.categoryMap['logic'].color ='#5C81A6';
  51. StandardCategories.categoryMap['loops'] =
  52. new ListElement(ListElement.TYPE_CATEGORY, 'Loops');
  53. StandardCategories.categoryMap['loops'].xml =
  54. Blockly.Xml.textToDom(
  55. '<xml>' +
  56. '<block type="controls_repeat_ext">' +
  57. '<value name="TIMES">' +
  58. '<shadow type="math_number">' +
  59. '<field name="NUM">10</field>' +
  60. '</shadow>' +
  61. '</value>' +
  62. '</block>' +
  63. '<block type="controls_whileUntil"></block>' +
  64. '<block type="controls_for">' +
  65. '<value name="FROM">' +
  66. '<shadow type="math_number">' +
  67. '<field name="NUM">1</field>' +
  68. '</shadow>' +
  69. '</value>' +
  70. '<value name="TO">' +
  71. '<shadow type="math_number">' +
  72. '<field name="NUM">10</field>' +
  73. '</shadow>' +
  74. '</value>' +
  75. '<value name="BY">' +
  76. '<shadow type="math_number">' +
  77. '<field name="NUM">1</field>' +
  78. '</shadow>' +
  79. '</value>' +
  80. '</block>' +
  81. '<block type="controls_forEach"></block>' +
  82. '<block type="controls_flow_statements"></block>' +
  83. '</xml>');
  84. StandardCategories.categoryMap['loops'].color = '#5CA65C';
  85. StandardCategories.categoryMap['math'] =
  86. new ListElement(ListElement.TYPE_CATEGORY, 'Math');
  87. StandardCategories.categoryMap['math'].xml =
  88. Blockly.Xml.textToDom(
  89. '<xml>' +
  90. '<block type="math_number"></block>' +
  91. '<block type="math_arithmetic">' +
  92. '<value name="A">' +
  93. '<shadow type="math_number">' +
  94. '<field name="NUM">1</field>' +
  95. '</shadow>' +
  96. '</value>' +
  97. '<value name="B">' +
  98. '<shadow type="math_number">' +
  99. '<field name="NUM">1</field>' +
  100. '</shadow>' +
  101. '</value>' +
  102. '</block>' +
  103. '<block type="math_single">' +
  104. '<value name="NUM">' +
  105. '<shadow type="math_number">' +
  106. '<field name="NUM">9</field>' +
  107. '</shadow>' +
  108. '</value>' +
  109. '</block>' +
  110. '<block type="math_trig">' +
  111. '<value name="NUM">' +
  112. '<shadow type="math_number">' +
  113. '<field name="NUM">45</field>' +
  114. '</shadow>' +
  115. '</value>' +
  116. '</block>' +
  117. '<block type="math_constant"></block>' +
  118. '<block type="math_number_property">' +
  119. '<value name="NUMBER_TO_CHECK">' +
  120. '<shadow type="math_number">' +
  121. '<field name="NUM">0</field>' +
  122. '</shadow>' +
  123. '</value>' +
  124. '</block>' +
  125. '<block type="math_round">' +
  126. '<value name="NUM">' +
  127. '<shadow type="math_number">' +
  128. '<field name="NUM">3.1</field>' +
  129. '</shadow>' +
  130. '</value>' +
  131. '</block>' +
  132. '<block type="math_on_list"></block>' +
  133. '<block type="math_modulo">' +
  134. '<value name="DIVIDEND">' +
  135. '<shadow type="math_number">' +
  136. '<field name="NUM">64</field>' +
  137. '</shadow>' +
  138. '</value>' +
  139. '<value name="DIVISOR">' +
  140. '<shadow type="math_number">' +
  141. '<field name="NUM">10</field>'+
  142. '</shadow>' +
  143. '</value>' +
  144. '</block>' +
  145. '<block type="math_constrain">' +
  146. '<value name="VALUE">' +
  147. '<shadow type="math_number">' +
  148. '<field name="NUM">50</field>' +
  149. '</shadow>' +
  150. '</value>' +
  151. '<value name="LOW">' +
  152. '<shadow type="math_number">' +
  153. '<field name="NUM">1</field>' +
  154. '</shadow>' +
  155. '</value>' +
  156. '<value name="HIGH">' +
  157. '<shadow type="math_number">' +
  158. '<field name="NUM">100</field>' +
  159. '</shadow>' +
  160. '</value>' +
  161. '</block>' +
  162. '<block type="math_random_int">' +
  163. '<value name="FROM">' +
  164. '<shadow type="math_number">' +
  165. '<field name="NUM">1</field>' +
  166. '</shadow>' +
  167. '</value>' +
  168. '<value name="TO">' +
  169. '<shadow type="math_number">' +
  170. '<field name="NUM">100</field>' +
  171. '</shadow>' +
  172. '</value>' +
  173. '</block>' +
  174. '<block type="math_random_float"></block>' +
  175. '</xml>');
  176. StandardCategories.categoryMap['math'].color = '#5C68A6';
  177. StandardCategories.categoryMap['text'] =
  178. new ListElement(ListElement.TYPE_CATEGORY, 'Text');
  179. StandardCategories.categoryMap['text'].xml =
  180. Blockly.Xml.textToDom(
  181. '<xml>' +
  182. '<block type="text"></block>' +
  183. '<block type="text_join"></block>' +
  184. '<block type="text_append">' +
  185. '<value name="TEXT">' +
  186. '<shadow type="text"></shadow>' +
  187. '</value>' +
  188. '</block>' +
  189. '<block type="text_length">' +
  190. '<value name="VALUE">' +
  191. '<shadow type="text">' +
  192. '<field name="TEXT">abc</field>' +
  193. '</shadow>' +
  194. '</value>' +
  195. '</block>' +
  196. '<block type="text_isEmpty">' +
  197. '<value name="VALUE">' +
  198. '<shadow type="text">' +
  199. '<field name="TEXT"></field>' +
  200. '</shadow>' +
  201. '</value>' +
  202. '</block>' +
  203. '<block type="text_indexOf">' +
  204. '<value name="VALUE">' +
  205. '<block type="variables_get">' +
  206. '<field name="VAR">text</field>' +
  207. '</block>' +
  208. '</value>' +
  209. '<value name="FIND">' +
  210. '<shadow type="text">' +
  211. '<field name="TEXT">abc</field>' +
  212. '</shadow>' +
  213. '</value>' +
  214. '</block>' +
  215. '<block type="text_charAt">' +
  216. '<value name="VALUE">' +
  217. '<block type="variables_get">' +
  218. '<field name="VAR">text</field>' +
  219. '</block>' +
  220. '</value>' +
  221. '</block>' +
  222. '<block type="text_getSubstring">' +
  223. '<value name="STRING">' +
  224. '<block type="variables_get">' +
  225. '<field name="VAR">text</field>' +
  226. '</block>' +
  227. '</value>' +
  228. '</block>' +
  229. '<block type="text_changeCase">' +
  230. '<value name="TEXT">' +
  231. '<shadow type="text">' +
  232. '<field name="TEXT">abc</field>' +
  233. '</shadow>' +
  234. '</value>' +
  235. '</block>' +
  236. '<block type="text_trim">' +
  237. '<value name="TEXT">' +
  238. '<shadow type="text">' +
  239. '<field name="TEXT">abc</field>' +
  240. '</shadow>' +
  241. '</value>' +
  242. '</block>' +
  243. '<block type="text_print">' +
  244. '<value name="TEXT">' +
  245. '<shadow type="text">' +
  246. '<field name="TEXT">abc</field>' +
  247. '</shadow>' +
  248. '</value>' +
  249. '</block>' +
  250. '<block type="text_prompt_ext">' +
  251. '<value name="TEXT">' +
  252. '<shadow type="text">' +
  253. '<field name="TEXT">abc</field>' +
  254. '</shadow>' +
  255. '</value>' +
  256. '</block>' +
  257. '</xml>');
  258. StandardCategories.categoryMap['text'].color = '#5CA68D';
  259. StandardCategories.categoryMap['lists'] =
  260. new ListElement(ListElement.TYPE_CATEGORY, 'Lists');
  261. StandardCategories.categoryMap['lists'].xml =
  262. Blockly.Xml.textToDom(
  263. '<xml>' +
  264. '<block type="lists_create_with">' +
  265. '<mutation items="0"></mutation>' +
  266. '</block>' +
  267. '<block type="lists_create_with"></block>' +
  268. '<block type="lists_repeat">' +
  269. '<value name="NUM">' +
  270. '<shadow type="math_number">' +
  271. '<field name="NUM">5</field>' +
  272. '</shadow>' +
  273. '</value>' +
  274. '</block>' +
  275. '<block type="lists_length"></block>' +
  276. '<block type="lists_isEmpty"></block>' +
  277. '<block type="lists_indexOf">' +
  278. '<value name="VALUE">' +
  279. '<block type="variables_get">' +
  280. '<field name="VAR">list</field>' +
  281. '</block>' +
  282. '</value>' +
  283. '</block>' +
  284. '<block type="lists_getIndex">' +
  285. '<value name="VALUE">' +
  286. '<block type="variables_get">' +
  287. '<field name="VAR">list</field>' +
  288. '</block>' +
  289. '</value>' +
  290. '</block>' +
  291. '<block type="lists_setIndex">' +
  292. '<value name="LIST">' +
  293. '<block type="variables_get">' +
  294. '<field name="VAR">list</field>' +
  295. '</block>' +
  296. '</value>' +
  297. '</block>' +
  298. '<block type="lists_getSublist">' +
  299. '<value name="LIST">' +
  300. '<block type="variables_get">' +
  301. '<field name="VAR">list</field>' +
  302. '</block>' +
  303. '</value>' +
  304. '</block>' +
  305. '<block type="lists_split">' +
  306. '<value name="DELIM">' +
  307. '<shadow type="text">' +
  308. '<field name="TEXT">,</field>' +
  309. '</shadow>' +
  310. '</value>' +
  311. '</block>' +
  312. '<block type="lists_sort"></block>' +
  313. '</xml>');
  314. StandardCategories.categoryMap['lists'].color = '#745CA6';
  315. StandardCategories.categoryMap['colour'] =
  316. new ListElement(ListElement.TYPE_CATEGORY, 'Colour');
  317. StandardCategories.categoryMap['colour'].xml =
  318. Blockly.Xml.textToDom(
  319. '<xml>' +
  320. '<block type="colour_picker"></block>' +
  321. '<block type="colour_random"></block>' +
  322. '<block type="colour_rgb">' +
  323. '<value name="RED">' +
  324. '<shadow type="math_number">' +
  325. '<field name="NUM">100</field>' +
  326. '</shadow>' +
  327. '</value>' +
  328. '<value name="GREEN">' +
  329. '<shadow type="math_number">' +
  330. '<field name="NUM">50</field>' +
  331. '</shadow>' +
  332. '</value>' +
  333. '<value name="BLUE">' +
  334. '<shadow type="math_number">' +
  335. '<field name="NUM">0</field>' +
  336. '</shadow>' +
  337. '</value>' +
  338. '</block>' +
  339. '<block type="colour_blend">' +
  340. '<value name="COLOUR1">' +
  341. '<shadow type="colour_picker">' +
  342. '<field name="COLOUR">#ff0000</field>' +
  343. '</shadow>' +
  344. '</value>' +
  345. '<value name="COLOUR2">' +
  346. '<shadow type="colour_picker">' +
  347. '<field name="COLOUR">#3333ff</field>' +
  348. '</shadow>' +
  349. '</value>' +
  350. '<value name="RATIO">' +
  351. '<shadow type="math_number">' +
  352. '<field name="NUM">0.5</field>' +
  353. '</shadow>' +
  354. '</value>' +
  355. '</block>' +
  356. '</xml>');
  357. StandardCategories.categoryMap['colour'].color = '#A6745C';
  358. StandardCategories.categoryMap['functions'] =
  359. new ListElement(ListElement.TYPE_CATEGORY, 'Functions');
  360. StandardCategories.categoryMap['functions'].color = '#9A5CA6'
  361. StandardCategories.categoryMap['functions'].custom = 'PROCEDURE';
  362. StandardCategories.categoryMap['variables'] =
  363. new ListElement(ListElement.TYPE_CATEGORY, 'Variables');
  364. StandardCategories.categoryMap['variables'].color = '#A65C81';
  365. StandardCategories.categoryMap['variables'].custom = 'VARIABLE';
  366. // All standard block types in provided in Blockly core.
  367. StandardCategories.coreBlockTypes = ["controls_if", "logic_compare",
  368. "logic_operation", "logic_negate", "logic_boolean", "logic_null",
  369. "logic_ternary", "controls_repeat_ext", "controls_whileUntil",
  370. "controls_for", "controls_forEach", "controls_flow_statements",
  371. "math_number", "math_arithmetic", "math_single", "math_trig",
  372. "math_constant", "math_number_property", "math_change", "math_round",
  373. "math_on_list", "math_modulo", "math_constrain", "math_random_int",
  374. "math_random_float", "text", "text_join", "text_append", "text_length",
  375. "text_isEmpty", "text_indexOf", "variables_get", "text_charAt",
  376. "text_getSubstring", "text_changeCase", "text_trim", "text_print",
  377. "text_prompt_ext", "colour_picker", "colour_random", "colour_rgb",
  378. "colour_blend", "lists_create_with", "lists_repeat", "lists_length",
  379. "lists_isEmpty", "lists_indexOf", "lists_getIndex", "lists_setIndex",
  380. "lists_getSublist", "lists_split", "lists_sort", "variables_set",
  381. "procedures_defreturn", "procedures_ifreturn", "procedures_defnoreturn",
  382. "procedures_callreturn"];