Skip to content

Commit 6ee74ea

Browse files
authored
Combine categories (#130)
* Prepare fake toolbox items to be done for real * Use copilot to match Google coding standards for Typescript * remove components category * remove samples * remove unneeded imports * remove dead break * Changed TYPE to use constant TYPE_NAME
1 parent 100f43a commit 6ee74ea

16 files changed

+1033
-1205
lines changed

src/editor/editor.ts

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,11 @@ import * as Blockly from 'blockly/core';
2424
import { extendedPythonGenerator } from './extended_python_generator';
2525
import { GeneratorContext } from './generator_context';
2626
import * as commonStorage from '../storage/common_storage';
27-
import * as toolboxOpmode from '../toolbox/toolbox_opmode';
28-
import * as toolboxMechanism from '../toolbox/toolbox_mechanism';
29-
import * as toolboxRobot from '../toolbox/toolbox_robot';
3027

3128
//import { testAllBlocksInToolbox } from '../toolbox/toolbox_tests';
3229
import { MethodsCategory} from '../toolbox/methods_category';
3330
import { EventsCategory} from '../toolbox/event_category';
34-
import { ComponentsCategory } from '../toolbox/components_category';
35-
31+
import { getToolboxJSON } from '../toolbox/toolbox';
3632

3733
const EMPTY_TOOLBOX: Blockly.utils.toolbox.ToolboxDefinition = {
3834
kind: 'categoryToolbox',
@@ -47,7 +43,6 @@ export class Editor {
4743
private storage: commonStorage.Storage;
4844
private methodsCategory: MethodsCategory;
4945
private eventsCategory: EventsCategory;
50-
private componentsCategory: ComponentsCategory;
5146
private currentModule: commonStorage.Module | null = null;
5247
private modulePath: string = '';
5348
private projectPath: string = '';
@@ -63,7 +58,6 @@ export class Editor {
6358
this.storage = storage;
6459
this.methodsCategory = new MethodsCategory(blocklyWorkspace);
6560
this.eventsCategory = new EventsCategory(blocklyWorkspace);
66-
this.componentsCategory = new ComponentsCategory(blocklyWorkspace);
6761
}
6862

6963
private onChangeWhileLoading(event: Blockly.Events.Abstract) {
@@ -127,7 +121,6 @@ export class Editor {
127121
this.currentModule = currentModule;
128122
this.methodsCategory.setCurrentModule(currentModule);
129123
this.eventsCategory.setCurrentModule(currentModule);
130-
this.componentsCategory.setCurrentModule(currentModule);
131124

132125
if (currentModule) {
133126
this.modulePath = currentModule.modulePath;
@@ -201,23 +194,9 @@ export class Editor {
201194
}, 50);
202195
return;
203196
}
204-
switch(this.currentModule.moduleType){
205-
case commonStorage.MODULE_TYPE_PROJECT:
206-
this.setToolbox(toolboxRobot.getToolboxJSON(shownPythonToolboxCategories));
207-
break;
208-
case commonStorage.MODULE_TYPE_MECHANISM:
209-
this.setToolbox(toolboxMechanism.getToolboxJSON(shownPythonToolboxCategories));
210-
break;
211-
case commonStorage.MODULE_TYPE_OPMODE:
212-
/*
213-
* TODO: When editing an opmode, we'll need to have blocks for all the methods that a robot has.
214-
* Not sure what this will be replaced with, but it will need something.
215-
* const robotBlocks = commonStorage.extractExportedBlocks(
216-
* this.currentModule.projectName, this.projectContent);
217-
*/
218-
this.setToolbox(toolboxOpmode.getToolboxJSON(shownPythonToolboxCategories));
219-
break;
220-
}
197+
this.setToolbox(
198+
getToolboxJSON(
199+
shownPythonToolboxCategories, this.currentModule));
221200
}
222201
}
223202

src/toolbox/add_hardware_component_category.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/toolbox/blocks_components.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Porpoiseful LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/**
19+
* @author [email protected] (Alan Smith)
20+
*/
21+
import * as ToolboxItems from './items';
22+
import * as ColorSensor from './hardware_components/color_sensor';
23+
import * as SmartMotor from './hardware_components/smart_motor';
24+
import * as TouchSensor from './hardware_components/touch_sensor';
25+
import * as Servo from './hardware_components/servo';
26+
27+
export function getAllPossibleComponents(hideParams : boolean): ToolboxItems.ContentsType[] {
28+
return [
29+
SmartMotor.getDefinitionBlock(hideParams),
30+
TouchSensor.getDefinitionBlock(hideParams),
31+
ColorSensor.getDefinitionBlock(hideParams),
32+
Servo.getDefinitionBlock(hideParams),
33+
];
34+
}

src/toolbox/blocks_mechanisms.ts

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Porpoiseful LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/**
19+
* @author [email protected] (Alan Smith)
20+
*/
21+
import * as ToolboxItems from './items';
22+
23+
/**
24+
* TODO: This is all fake right now, it will be generated dynamically
25+
* based on reading things from mechanisms.
26+
*/
27+
28+
export function getAllPossibleMechanisms(): ToolboxItems.ContentsType[] {
29+
return [
30+
31+
{
32+
kind: 'block',
33+
type: 'mrc_mechanism',
34+
fields: {
35+
NAME: 'claw',
36+
TYPE: 'Claw'
37+
},
38+
extraState: {
39+
importModule: 'claw',
40+
params: [{ name: 'gripper_port', type: 'int' },
41+
{ name: 'piece_sensor_port', type: 'int' },
42+
]
43+
},
44+
inputs: {
45+
ARG0: {
46+
shadow: {
47+
type: 'mrc_port',
48+
fields: {
49+
TYPE: 'SmartMotor',
50+
PORT_NUM: 1
51+
},
52+
},
53+
},
54+
ARG1: {
55+
shadow: {
56+
type: 'mrc_port',
57+
fields: {
58+
TYPE: 'SmartIO',
59+
PORT_NUM: 1
60+
},
61+
},
62+
},
63+
}
64+
},
65+
{
66+
kind: 'block',
67+
type: 'mrc_mechanism',
68+
fields: {
69+
NAME: 'drive',
70+
TYPE: 'DriveMecanum'
71+
},
72+
extraState: {
73+
importModule: 'DriveMecanum',
74+
params: [{ name: 'front_left_drive_port', type: 'int' },
75+
{ name: 'front_right_drive_port', type: 'int' },
76+
{ name: 'back_left_drive_port', type: 'int' },
77+
{ name: 'back_right_drive_port', type: 'int' },
78+
]
79+
},
80+
inputs: {
81+
ARG0: {
82+
shadow: {
83+
type: 'mrc_port',
84+
fields: {
85+
TYPE: 'SmartMotor',
86+
PORT_NUM: 1
87+
},
88+
},
89+
},
90+
ARG1: {
91+
shadow: {
92+
type: 'mrc_port',
93+
fields: {
94+
TYPE: 'SmartMotor',
95+
PORT_NUM: 2
96+
},
97+
},
98+
},
99+
ARG2: {
100+
shadow: {
101+
type: 'mrc_port',
102+
fields: {
103+
TYPE: 'SmartMotor',
104+
PORT_NUM: 3
105+
},
106+
},
107+
},
108+
ARG3: {
109+
shadow: {
110+
type: 'mrc_port',
111+
fields: {
112+
TYPE: 'SmartMotor',
113+
PORT_NUM: 4
114+
},
115+
},
116+
},
117+
}
118+
},
119+
];
120+
}
121+

0 commit comments

Comments
 (0)