Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 4 additions & 25 deletions src/editor/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@ import * as Blockly from 'blockly/core';
import { extendedPythonGenerator } from './extended_python_generator';
import { GeneratorContext } from './generator_context';
import * as commonStorage from '../storage/common_storage';
import * as toolboxOpmode from '../toolbox/toolbox_opmode';
import * as toolboxMechanism from '../toolbox/toolbox_mechanism';
import * as toolboxRobot from '../toolbox/toolbox_robot';

//import { testAllBlocksInToolbox } from '../toolbox/toolbox_tests';
import { MethodsCategory} from '../toolbox/methods_category';
import { EventsCategory} from '../toolbox/event_category';
import { ComponentsCategory } from '../toolbox/components_category';

import { getToolboxJSON } from '../toolbox/toolbox';

const EMPTY_TOOLBOX: Blockly.utils.toolbox.ToolboxDefinition = {
kind: 'categoryToolbox',
Expand All @@ -47,7 +43,6 @@ export class Editor {
private storage: commonStorage.Storage;
private methodsCategory: MethodsCategory;
private eventsCategory: EventsCategory;
private componentsCategory: ComponentsCategory;
private currentModule: commonStorage.Module | null = null;
private modulePath: string = '';
private projectPath: string = '';
Expand All @@ -63,7 +58,6 @@ export class Editor {
this.storage = storage;
this.methodsCategory = new MethodsCategory(blocklyWorkspace);
this.eventsCategory = new EventsCategory(blocklyWorkspace);
this.componentsCategory = new ComponentsCategory(blocklyWorkspace);
}

private onChangeWhileLoading(event: Blockly.Events.Abstract) {
Expand Down Expand Up @@ -127,7 +121,6 @@ export class Editor {
this.currentModule = currentModule;
this.methodsCategory.setCurrentModule(currentModule);
this.eventsCategory.setCurrentModule(currentModule);
this.componentsCategory.setCurrentModule(currentModule);

if (currentModule) {
this.modulePath = currentModule.modulePath;
Expand Down Expand Up @@ -201,23 +194,9 @@ export class Editor {
}, 50);
return;
}
switch(this.currentModule.moduleType){
case commonStorage.MODULE_TYPE_PROJECT:
this.setToolbox(toolboxRobot.getToolboxJSON(shownPythonToolboxCategories));
break;
case commonStorage.MODULE_TYPE_MECHANISM:
this.setToolbox(toolboxMechanism.getToolboxJSON(shownPythonToolboxCategories));
break;
case commonStorage.MODULE_TYPE_OPMODE:
/*
* TODO: When editing an opmode, we'll need to have blocks for all the methods that a robot has.
* Not sure what this will be replaced with, but it will need something.
* const robotBlocks = commonStorage.extractExportedBlocks(
* this.currentModule.projectName, this.projectContent);
*/
this.setToolbox(toolboxOpmode.getToolboxJSON(shownPythonToolboxCategories));
break;
}
this.setToolbox(
getToolboxJSON(
shownPythonToolboxCategories, this.currentModule));
}
}

Expand Down
50 changes: 0 additions & 50 deletions src/toolbox/add_hardware_component_category.ts

This file was deleted.

34 changes: 34 additions & 0 deletions src/toolbox/blocks_components.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @license
* Copyright 2025 Porpoiseful LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @author [email protected] (Alan Smith)
*/
import * as ToolboxItems from './items';
import * as ColorSensor from './hardware_components/color_sensor';
import * as SmartMotor from './hardware_components/smart_motor';
import * as TouchSensor from './hardware_components/touch_sensor';
import * as Servo from './hardware_components/servo';

export function getAllPossibleComponents(hideParams : boolean): ToolboxItems.ContentsType[] {
return [
SmartMotor.getDefinitionBlock(hideParams),
TouchSensor.getDefinitionBlock(hideParams),
ColorSensor.getDefinitionBlock(hideParams),
Servo.getDefinitionBlock(hideParams),
];
}
121 changes: 121 additions & 0 deletions src/toolbox/blocks_mechanisms.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/**
* @license
* Copyright 2025 Porpoiseful LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @author [email protected] (Alan Smith)
*/
import * as ToolboxItems from './items';

/**
* TODO: This is all fake right now, it will be generated dynamically
* based on reading things from mechanisms.
*/

export function getAllPossibleMechanisms(): ToolboxItems.ContentsType[] {
return [

{
kind: 'block',
type: 'mrc_mechanism',
fields: {
NAME: 'claw',
TYPE: 'Claw'
},
extraState: {
importModule: 'claw',
params: [{ name: 'gripper_port', type: 'int' },
{ name: 'piece_sensor_port', type: 'int' },
]
},
inputs: {
ARG0: {
shadow: {
type: 'mrc_port',
fields: {
TYPE: 'SmartMotor',
PORT_NUM: 1
},
},
},
ARG1: {
shadow: {
type: 'mrc_port',
fields: {
TYPE: 'SmartIO',
PORT_NUM: 1
},
},
},
}
},
{
kind: 'block',
type: 'mrc_mechanism',
fields: {
NAME: 'drive',
TYPE: 'DriveMecanum'
},
extraState: {
importModule: 'DriveMecanum',
params: [{ name: 'front_left_drive_port', type: 'int' },
{ name: 'front_right_drive_port', type: 'int' },
{ name: 'back_left_drive_port', type: 'int' },
{ name: 'back_right_drive_port', type: 'int' },
]
},
inputs: {
ARG0: {
shadow: {
type: 'mrc_port',
fields: {
TYPE: 'SmartMotor',
PORT_NUM: 1
},
},
},
ARG1: {
shadow: {
type: 'mrc_port',
fields: {
TYPE: 'SmartMotor',
PORT_NUM: 2
},
},
},
ARG2: {
shadow: {
type: 'mrc_port',
fields: {
TYPE: 'SmartMotor',
PORT_NUM: 3
},
},
},
ARG3: {
shadow: {
type: 'mrc_port',
fields: {
TYPE: 'SmartMotor',
PORT_NUM: 4
},
},
},
}
},
];
}

Loading