MCPcopy Index your code
hub / github.com/codecombat/codecombat / prepareBlockIntelligence

Function prepareBlockIntelligence

app/lib/code-to-blocks.js:700–774  ·  view source on GitHub ↗
({ toolbox, blocklyState, workspace })

Source from the content-addressed store, hash-verified

698}
699
700function prepareBlockIntelligence ({ toolbox, blocklyState, workspace }) {
701 const plan = []
702
703 // console.log('prepareBlockIntelligence', arguments[0])
704 // window.ws = workspace
705 const blocks = findAllBlocks(toolbox.fullContents)
706 const rewritesStepsAsDropdowns = !_.find(blocks, { type: 'Hero_dist' })
707
708 for (const block of blocks) {
709 const zeblock = Blockly.Blocks[block.type]
710 if (!zeblock) {
711 console.error(`Could not find block definition for block of type ${block.type}`, block)
712 continue
713 }
714 // console.log('Consider', block, 'z', zeblock)
715 workspace.clear()
716 const defn = {
717 type: block.type,
718 }
719 defn.setupInfo = zeblock.setupInfo || 'NO SETUP INFO'
720 if (zeblock.setupInfo) {
721 if (zeblock.setupInfo.args0) {
722 defn.inputs = {}
723 defn.output = zeblock.setupInfo.output === null
724
725 for (const entry of zeblock.setupInfo.args0) {
726 // console.log(entry)
727 if (entry.type === 'field_image') {
728 // Don't add an input; it's just decoration
729 } else if (['to'].includes(entry.name) && entry.type === 'field_dropdown') {
730 // Don't add an input.
731 } else if (['steps', 'squares'].includes(entry.name) && entry.type === 'field_dropdown' && rewritesStepsAsDropdowns) {
732 // Don't add an input.
733 } else if (entry.check === 'Number') {
734 defn.inputs[entry.name] = {
735 block: {
736 type: 'math_number',
737 fields: {
738 NUM: 0,
739 },
740 },
741 }
742 } else {
743 defn.inputs[entry.name] = {
744 block: {
745 type: 'text',
746 fields: {
747 TEXT: '$ARGUMENT$' + entry.name,
748 },
749 },
750 }
751 }
752 }
753 }
754 }
755
756 try {
757 Blockly.serialization.blocks.append(defn, workspace)

Callers 1

addBlocklyMethod · 0.85

Calls 3

findAllBlocksFunction · 0.85
doParseFunction · 0.85
errorMethod · 0.45

Tested by

no test coverage detected