not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
2.0 KiB

  1. // Copyright (c) 2017 Walter Bender
  2. //
  3. // This program is free software; you can redistribute it and/or
  4. // modify it under the terms of the The GNU Affero General Public
  5. // License as published by the Free Software Foundation; either
  6. // version 3 of the License, or (at your option) any later version.
  7. //
  8. // You should have received a copy of the GNU Affero General Public
  9. // License along with this library; if not, write to the Free Software
  10. // Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA
  11. // Macro expansions
  12. function blockIsMacro (blkname) {
  13. const BUILTINMACROS = ['setturtlename', 'fill', 'hollowline', 'status', 'xturtle', 'yturtle'];
  14. return BUILTINMACROS.indexOf(blkname) > -1;
  15. };
  16. function getMacroExpansion (blkname, x, y) {
  17. // Some blocks are expanded on load.
  18. const FILLOBJ = [[0, 'fill', x, y, [null, null, 1]], [1, 'hidden', 0, 0, [0, null]]];
  19. const HOLLOWOBJ = [[0, 'hollowline', x, y, [null, null, 1]], [1, 'hidden', 0, 0, [0, null]]];
  20. const SETTURTLENAMEOBJ = [[0, 'setturtlename', x, y, [null, 1, 2, null]], [1, 'turtlename', 0, 0, [0]], [2, ['text', {'value': 'Mozart'}], 0, 0, [0]]];
  21. const STATUSOBJ = [[0, 'status', x, y, [null, 1, null]], [1, 'print', 0, 0, [0, 2, 3]], [2, 'x', 0, 0, [1]], [3, 'print', 0, 0, [1, 4, 5]], [4, 'y', 0, 0, [3]], [5, 'print', 0, 0, [3, 6, null]], [6, 'heading', 0, 0, [5]]];
  22. const XTURTLEOBJ = [[0, 'xturtle', x, y, [null, 1, null]], [1, 'turtlename', 0, 0, [0]]];
  23. const YTURTLEOBJ = [[0, 'yturtle', x, y, [null, 1, null]], [1, 'turtlename', 0, 0, [0]]];
  24. const BUILTINMACROS = {
  25. 'fill': FILLOBJ,
  26. 'hollowline': HOLLOWOBJ,
  27. 'setturtlename': SETTURTLENAMEOBJ,
  28. 'status': STATUSOBJ,
  29. 'xturtle': XTURTLEOBJ,
  30. 'yturtle': YTURTLEOBJ,
  31. };
  32. if (['namedbox', 'nameddo', 'namedcalc', 'namedarg', 'nameddoArg'].indexOf(blkname) === -1 && blkname in BUILTINMACROS) {
  33. return BUILTINMACROS[blkname];
  34. } else {
  35. return null;
  36. }
  37. };