@@ -29,9 +29,8 @@ import * as Blockly from 'blockly/core';
2929import * as toolboxItems from './items' ;
3030import * as commonStorage from '../storage/common_storage' ;
3131import { getAllPossibleMechanisms } from './blocks_mechanisms' ;
32- import { getAllPossibleComponents } from './blocks_components' ;
33- import * as SmartMotor from './hardware_components/smart_motor' ;
34- import * as TouchSensor from './hardware_components/touch_sensor' ;
32+ import { getAllPossibleComponents , getBlocks } from './blocks_components' ;
33+ import * as MechanismComponentHolder from '../blocks/mrc_mechanism_component_holder' ;
3534
3635export function getHardwareCategory ( currentModule : commonStorage . Module ) {
3736 if ( currentModule . moduleType === commonStorage . MODULE_TYPE_OPMODE ) {
@@ -243,22 +242,46 @@ function getRobotMethodsBlocks(currentModule: commonStorage.Module) {
243242
244243function getComponentsBlocks ( currentModule : commonStorage . Module ) {
245244 const contents = [ ] ;
245+
246+ // Add the "+ Component" category
246247 contents . push ( {
247248 kind : 'category' ,
248249 name : '+ Component' ,
249250 contents : getAllPossibleComponents ( true )
250251 } ) ;
251- contents . push ( {
252- kind : 'category' ,
253- name : 'my_motor' ,
254- contents : SmartMotor . getBlocks ( 'my_motor' )
255- } ,
256- {
257- kind : 'category' ,
258- name : 'my_touch_sensor' ,
259- contents : TouchSensor . getBlocks ( 'my_touch_sensor' )
260- } ,
261- ) ;
252+
253+ // Get components from the current workspace
254+ const workspace = Blockly . getMainWorkspace ( ) ;
255+ if ( workspace ) {
256+ const holderBlocks = workspace . getBlocksByType ( MechanismComponentHolder . BLOCK_NAME ) ;
257+
258+ holderBlocks . forEach ( holderBlock => {
259+ // Get component blocks from the COMPONENTS input
260+ const componentsInput = holderBlock . getInput ( 'COMPONENTS' ) ;
261+ if ( componentsInput && componentsInput . connection ) {
262+ let componentBlock = componentsInput . connection . targetBlock ( ) ;
263+
264+ // Walk through all connected component blocks
265+ while ( componentBlock ) {
266+ if ( componentBlock . type === 'mrc_component' ) {
267+ const componentName = componentBlock . getFieldValue ( 'NAME' ) ;
268+ const componentType = componentBlock . getFieldValue ( 'TYPE' ) ;
269+
270+ if ( componentName && componentType ) {
271+ // Get the blocks for this specific component
272+ contents . push ( {
273+ kind : 'category' ,
274+ name : componentName ,
275+ contents : getBlocks ( componentType , componentName ) ,
276+ } ) ;
277+ }
278+ }
279+ // Move to the next block in the chain
280+ componentBlock = componentBlock . getNextBlock ( ) ;
281+ }
282+ }
283+ } ) ;
284+ }
262285 return {
263286 kind : 'category' ,
264287 name : 'Components' ,
0 commit comments