Skip to content

Commit d7cbbb3

Browse files
committed
Added comment in getRobotMechanismsCategory specifying that it needs to call
getAllComponentsFromMechanism so it can create the port parameters. Simplified getComponentsCategory to call getAllComponentsFromWorkspace for both robot and mechanism modules and added comments explaining why.
1 parent 19f1003 commit d7cbbb3

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/toolbox/hardware_category.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ function getRobotMechanismsCategory(editor: Editor): toolboxItems.Category {
7878
if (mechanisms.length) {
7979
const mechanismBlocks: toolboxItems.Block[] = [];
8080
mechanisms.forEach(mechanism => {
81+
// Here we need all the components (regular and private) from the mechanism because we need
82+
// to create port parameters for all the components.
8183
const components = editor.getAllComponentsFromMechanism(mechanism);
8284
mechanismBlocks.push(createMechanismBlock(mechanism, components));
8385
});
@@ -110,11 +112,13 @@ function getRobotMechanismsCategory(editor: Editor): toolboxItems.Category {
110112
contents: mechanismMethodBlocks,
111113
});
112114

113-
// Get the public components from the mechanism and add the blocks for calling the component functions.
115+
// Get the public components from the mechanism and add the blocks for calling the
116+
// component functions.
114117
const componentsFromMechanism = editor.getComponentsFromMechanism(mechanism);
115118
if (componentsFromMechanism.length > 0) {
116119
const componentBlocks: toolboxItems.ContentsType[] = [];
117120
componentsFromMechanism.forEach(component => {
121+
// Get the blocks for this specific component.
118122
componentBlocks.push({
119123
kind: 'category',
120124
name: component.name,
@@ -202,12 +206,13 @@ function getComponentsCategory(
202206
contents: getAllPossibleComponents(moduleType),
203207
});
204208

205-
// Get components from the current workspace.
206-
const componentsToShow = moduleType === storageModule.ModuleType.MECHANISM
207-
? editor.getAllComponentsFromWorkspace() // Show all components (including private) when editing mechanisms
208-
: editor.getComponentsFromWorkspace(); // Show only regular components when editing robots
209-
210-
componentsToShow.forEach(component => {
209+
// Get all (regular and private) components from the current workspace.
210+
// For a robot module, we can only have regular components. For a mechanism module, we can have
211+
// regular and/or private components. Rather than checking what the current module type is, it's
212+
// simpler to just call getAllComponentsFromWorkspace for both robot and mechanism modules. Since
213+
// robot modules don't have private components, getAllComponentsFromWorkspace is equivalent to
214+
// getComponentsFromWorkspace for a robot module.
215+
editor.getAllComponentsFromWorkspace().forEach(component => {
211216
// Get the blocks for this specific component
212217
contents.push({
213218
kind: 'category',

0 commit comments

Comments
 (0)