@@ -246,25 +246,26 @@ export class Editor {
246246 const blocks = Blockly . serialization . workspaces . save ( this . blocklyWorkspace ) ;
247247 const mechanisms : storageModuleContent . MechanismInRobot [ ] = this . getMechanismsFromWorkspace ( ) ;
248248 const components : storageModuleContent . Component [ ] = this . getComponentsFromWorkspace ( ) ;
249+ const privateComponents : storageModuleContent . Component [ ] = this . getPrivateComponentsFromWorkspace ( ) ;
249250 const events : storageModuleContent . Event [ ] = this . getEventsFromWorkspace ( ) ;
250251 const methods : storageModuleContent . Method [ ] = (
251252 this . currentModule ?. moduleType === storageModule . ModuleType . ROBOT ||
252253 this . currentModule ?. moduleType === storageModule . ModuleType . MECHANISM )
253254 ? this . getMethodsForOutsideFromWorkspace ( )
254255 : [ ] ;
255256 return storageModuleContent . makeModuleContentText (
256- this . currentModule , blocks , mechanisms , components , events , methods ) ;
257+ this . currentModule , blocks , mechanisms , components , privateComponents , events , methods ) ;
257258 }
258259
259- public getMechanismsFromWorkspace ( ) : storageModuleContent . MechanismInRobot [ ] {
260+ private getMechanismsFromWorkspace ( ) : storageModuleContent . MechanismInRobot [ ] {
260261 const mechanisms : storageModuleContent . MechanismInRobot [ ] = [ ] ;
261262 if ( this . currentModule ?. moduleType === storageModule . ModuleType . ROBOT ) {
262263 mechanismComponentHolder . getMechanisms ( this . blocklyWorkspace , mechanisms ) ;
263264 }
264265 return mechanisms ;
265266 }
266267
267- public getComponentsFromWorkspace ( ) : storageModuleContent . Component [ ] {
268+ private getComponentsFromWorkspace ( ) : storageModuleContent . Component [ ] {
268269 const components : storageModuleContent . Component [ ] = [ ] ;
269270 if ( this . currentModule ?. moduleType === storageModule . ModuleType . ROBOT ||
270271 this . currentModule ?. moduleType === storageModule . ModuleType . MECHANISM ) {
@@ -273,6 +274,14 @@ export class Editor {
273274 return components ;
274275 }
275276
277+ private getPrivateComponentsFromWorkspace ( ) : storageModuleContent . Component [ ] {
278+ const components : storageModuleContent . Component [ ] = [ ] ;
279+ if ( this . currentModule ?. moduleType === storageModule . ModuleType . MECHANISM ) {
280+ mechanismComponentHolder . getPrivateComponents ( this . blocklyWorkspace , components ) ;
281+ }
282+ return components ;
283+ }
284+
276285 public getAllComponentsFromWorkspace ( ) : storageModuleContent . Component [ ] {
277286 const components : storageModuleContent . Component [ ] = [ ] ;
278287 if ( this . currentModule ?. moduleType === storageModule . ModuleType . ROBOT ||
@@ -288,7 +297,7 @@ export class Editor {
288297 return methods ;
289298 }
290299
291- public getMethodsForOutsideFromWorkspace ( ) : storageModuleContent . Method [ ] {
300+ private getMethodsForOutsideFromWorkspace ( ) : storageModuleContent . Method [ ] {
292301 const methods : storageModuleContent . Method [ ] = [ ] ;
293302 classMethodDef . getMethodsForOutside ( this . blocklyWorkspace , methods ) ;
294303 return methods ;
@@ -433,24 +442,12 @@ export class Editor {
433442 return this . getAllComponentsFromWorkspace ( ) ;
434443 }
435444 if ( mechanism . className in this . mechanismClassNameToModuleContent ) {
436- // For saved mechanisms, we need to reconstruct all components from the blocks
437- // since only public components are saved in the module content
438445 const moduleContent = this . mechanismClassNameToModuleContent [ mechanism . className ] ;
439- const blocks = moduleContent . getBlocks ( ) ;
440-
441- // Create a temporary workspace to load the mechanism's blocks
442- const tempWorkspace = new Blockly . Workspace ( ) ;
443- try {
444- Blockly . serialization . workspaces . load ( blocks , tempWorkspace ) ;
445-
446- // Extract all components (public and private) from the temporary workspace
447- const allComponents : storageModuleContent . Component [ ] = [ ] ;
448- mechanismComponentHolder . getAllComponents ( tempWorkspace , allComponents ) ;
449-
450- return allComponents ;
451- } finally {
452- tempWorkspace . dispose ( ) ;
453- }
446+ const allComponents : storageModuleContent . Component [ ] = [
447+ ...moduleContent . getComponents ( ) ,
448+ ...moduleContent . getPrivateComponents ( ) ,
449+ ]
450+ return allComponents ;
454451 }
455452 throw new Error ( 'getAllComponentsFromMechanism: mechanism not found: ' + mechanism . className ) ;
456453 }
0 commit comments