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.

65 lines
9.7 KiB

  1. {
  2. "BLOCKPLUGINS": [
  3. [
  4. "push",
  5. "var pushBlk = new ProtoBlock('push');pushBlk.palette = palettes.dict['extras'];blocks.protoBlockDict['push'] = pushBlk;pushBlk.staticLabels.push(_('push'));pushBlk.adjustWidthToLabel();pushBlk.oneArgBlock();pushBlk.dockTypes[1] = 'anyin';"
  6. ],
  7. [
  8. "pop",
  9. "var popBlk = new ProtoBlock('pop');popBlk.palette = palettes.dict['extras'];blocks.protoBlockDict['pop'] = popBlk;popBlk.staticLabels.push(_('pop'));popBlk.adjustWidthToLabel();popBlk.parameterBlock();"
  10. ],
  11. [
  12. "showHeap",
  13. "var showHeap = new ProtoBlock('showHeap');showHeap.palette = palettes.dict['extras'];blocks.protoBlockDict['showHeap'] = showHeap;showHeap.staticLabels.push(_('show heap'));showHeap.adjustWidthToLabel();showHeap.zeroArgBlock();"
  14. ],
  15. [
  16. "heapEmpty",
  17. "var heapEmpty = new ProtoBlock('heapEmpty');heapEmpty.palette = palettes.dict['extras'];blocks.protoBlockDict['heapEmpty'] = heapEmpty;heapEmpty.staticLabels.push(_('heap empty?'));heapEmpty.adjustWidthToLabel();heapEmpty.booleanZeroArgBlock();"
  18. ],
  19. [
  20. "emptyHeap",
  21. "var emptyHeap = new ProtoBlock('emptyHeap');emptyHeap.palette = palettes.dict['extras'];blocks.protoBlockDict['emptyHeap'] = emptyHeap;emptyHeap.staticLabels.push(_('empty heap'));emptyHeap.adjustWidthToLabel();emptyHeap.zeroArgBlock();"
  22. ],
  23. [
  24. "saveHeap",
  25. "var saveHeap = new ProtoBlock('saveHeap');saveHeap.palette = palettes.dict['extras'];blocks.protoBlockDict['saveHeap'] = saveHeap;saveHeap.staticLabels.push(_('save heap'));saveHeap.adjustWidthToLabel();saveHeap.oneArgBlock();saveHeap.defaults.push('heap.json');saveHeap.dockTypes[1] = 'textin';"
  26. ],
  27. [
  28. "loadHeap",
  29. "var loadHeap = new ProtoBlock('loadHeap');loadHeap.palette = palettes.dict['extras'];blocks.protoBlockDict['loadHeap'] = loadHeap;loadHeap.staticLabels.push(_('load heap'));loadHeap.adjustWidthToLabel();loadHeap.oneArgBlock();loadHeap.dockTypes[1] = 'filein';loadHeap.defaults = [[null, null]];"
  30. ]
  31. ],
  32. "GLOBALS": "turtleHeaps = {};",
  33. "ARGPLUGINS": [
  34. [
  35. "pop",
  36. "var block = logo.blocks.blockList[blk];if (turtle in turtleHeaps && turtleHeaps[turtle].length > 0) { block.value = turtleHeaps[turtle].pop();} else { logo.errorMsg(_('empty heap')); block.value = null;}"
  37. ],
  38. [
  39. "heapEmpty",
  40. "var block = logo.blocks.blockList[blk];if (turtle in turtleHeaps) { block.value = (turtleHeaps[turtle].length == 0);} else { block.value = true;}"
  41. ]
  42. ],
  43. "FLOWPLUGINS": [
  44. [
  45. "showHeap",
  46. "var block = logo.blocks.blockList[blk];logo.textMsg(JSON.stringify(turtleHeaps[turtle]));"
  47. ],
  48. [
  49. "emptyHeap",
  50. "turtleHeaps[turtle] = [];"
  51. ],
  52. [
  53. "push",
  54. "var block = logo.blocks.blockList[blk];var conns = block.connections;var arg = logo.parseArg(logo, turtle, conns[1]);if (!(turtle in turtleHeaps)) { turtleHeaps[turtle] = [];}turtleHeaps[turtle].push(arg);"
  55. ],
  56. [
  57. "saveHeap",
  58. "function downloadFile(filename, mimetype, content) { var download = document.createElement('a'); download.setAttribute('href', 'data:' + mimetype + ';charset=utf-8,' + content); download.setAttribute('download', filename); document.body.appendChild(download); download.click(); document.body.removeChild(download);};var block = logo.blocks.blockList[blk];var conns = block.connections;var arg = logo.parseArg(logo, turtle, conns[1]);if (arg && turtle in turtleHeaps) { downloadFile(arg, 'text/json', JSON.stringify(turtleHeaps[turtle]));};"
  59. ],
  60. [
  61. "loadHeap",
  62. "var block = logo.blocks.blockList[blk];var conns = block.connections;var arg = logo.parseArg(logo, turtle, conns[1]);if (turtle in turtleHeaps) { var oldHeap = turtleHeaps[turtle];} else { var oldHeap = [];}if (blocks.blockList[conns[1]].name == 'loadFile') { if (!arg) { logo.errorMsg(_('You need to select a file.')); } else { if (arg.length != 2) { logo.errorMsg(_('You need to select a file.')); } else { try { turtleHeaps[turtle] = JSON.parse(arg[1]); if (!Array.isArray(turtleHeaps[turtle])) { throw 'is not array'; } } catch (e) { turtleHeaps[turtle] = oldHeap; logo.errorMsg(_('The file you selected does not contain a valid heap.')); } } }}else { logo.errorMsg(_('The loadHeap block needs a loadFile block.'))};"
  63. ]
  64. ]
  65. }