Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
24 lines (23 sloc) 4.26 KB
{
"BLOCKPLUGINS": {
"heapEmpty": "var heapEmpty = new ProtoBlock('heapEmpty');heapEmpty.palette = palettes.dict['extras'];blocks.protoBlockDict['heapEmpty'] = heapEmpty;heapEmpty.staticLabels.push(_('heap empty?'));heapEmpty.adjustWidthToLabel();heapEmpty.booleanZeroArgBlock();",
"showHeap": "var showHeap = new ProtoBlock('showHeap');showHeap.palette = palettes.dict['extras'];blocks.protoBlockDict['showHeap'] = showHeap;showHeap.staticLabels.push(_('show heap'));showHeap.adjustWidthToLabel();showHeap.zeroArgBlock();",
"pop": "var popBlk = new ProtoBlock('pop');popBlk.palette = palettes.dict['extras'];blocks.protoBlockDict['pop'] = popBlk;popBlk.staticLabels.push(_('pop'));popBlk.adjustWidthToLabel();popBlk.parameterBlock();",
"emptyHeap": "var emptyHeap = new ProtoBlock('emptyHeap');emptyHeap.palette = palettes.dict['extras'];blocks.protoBlockDict['emptyHeap'] = emptyHeap;emptyHeap.staticLabels.push(_('empty heap'));emptyHeap.adjustWidthToLabel();emptyHeap.zeroArgBlock();",
"saveHeap": "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';",
"loadHeap": "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]];",
"push": "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';"
},
"GLOBALS": "turtleHeaps = {};",
"ARGPLUGINS": {
"heapEmpty": "var block = logo.blocks.blockList[blk];if (turtle in turtleHeaps) { block.value = (turtleHeaps[turtle].length == 0);} else { block.value = true;}",
"pop": "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;}"
},
"FLOWPLUGINS": {
"emptyHeap": "turtleHeaps[turtle] = [];",
"showHeap": "var block = logo.blocks.blockList[blk];logo.textMsg(JSON.stringify(turtleHeaps[turtle]));",
"push": "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);",
"loadHeap": "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.'))};",
"saveHeap": "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]));};"
}
}