|
6 | 6 | import { nodeRegistry, type NodeInstance } from '$lib/nodes'; |
7 | 7 | import { eventRegistry, type EventInstance } from '$lib/events'; |
8 | 8 | import { NODE_TYPES } from '$lib/constants/nodeTypes'; |
| 9 | +import { blockImportPaths } from '$lib/nodes/generated/blocks'; |
9 | 10 |
|
10 | 11 | /** |
11 | 12 | * Extract Python identifiers from a string (parameter values) |
@@ -134,10 +135,21 @@ export function generateBlockCodeHeader(node: NodeInstance, codeContext: string) |
134 | 135 | const blockClasses = new Set<string>(); |
135 | 136 | collectSubsystemBlockClasses(node, blockClasses); |
136 | 137 | if (blockClasses.size > 0) { |
137 | | - lines.push(`from pathsim.blocks import ${[...blockClasses].sort().join(', ')}`); |
| 138 | + // Group block classes by import path |
| 139 | + const importGroups = new Map<string, string[]>(); |
| 140 | + for (const cls of [...blockClasses].sort()) { |
| 141 | + const importPath = blockImportPaths[cls] || 'pathsim.blocks'; |
| 142 | + const group = importGroups.get(importPath) || []; |
| 143 | + group.push(cls); |
| 144 | + importGroups.set(importPath, group); |
| 145 | + } |
| 146 | + for (const [importPath, classes] of importGroups) { |
| 147 | + lines.push(`from ${importPath} import ${classes.join(', ')}`); |
| 148 | + } |
138 | 149 | } |
139 | 150 | } else { |
140 | | - lines.push(`from pathsim.blocks import ${typeDef.blockClass}`); |
| 151 | + const importPath = blockImportPaths[typeDef.blockClass] || 'pathsim.blocks'; |
| 152 | + lines.push(`from ${importPath} import ${typeDef.blockClass}`); |
141 | 153 | } |
142 | 154 |
|
143 | 155 | // Extract referenced code context |
|
0 commit comments