diff --git a/src/blocks/mrc_component.ts b/src/blocks/mrc_component.ts index cd24f4cc..492f8eae 100644 --- a/src/blocks/mrc_component.ts +++ b/src/blocks/mrc_component.ts @@ -30,6 +30,8 @@ import * as ToolboxItems from '../toolbox/items'; import * as CommonStorage from '../storage/common_storage'; import { createPortShadow } from './mrc_port'; import { createNumberShadowValue } from './utils/value'; +import { ClassData, FunctionData } from './utils/python_json_types'; + export const BLOCK_NAME = 'mrc_component'; export const OUTPUT_NAME = 'mrc_component'; @@ -177,6 +179,7 @@ export function getAllPossibleComponents(hideParams: boolean): ToolboxItems.Cont const contents: ToolboxItems.ContentsType[] = []; // Iterate through all the components subclasses and add definition blocks. const componentTypes = getSubclassNames('component.Component'); + componentTypes.forEach(componentType => { const classData = getClassData(componentType); if (!classData) { @@ -212,7 +215,7 @@ function createComponentBlock( const inputs: {[key: string]: any} = {}; for (let i = 0; i < staticFunctionData.args.length; i++) { const argData = staticFunctionData.args[i]; - extraState.params.push({ + extraState.params!.push({ 'name': argData.name, 'type': argData.type, }); @@ -233,14 +236,16 @@ function createComponentBlock( function getPortTypeForArgument(argName: string): string | null { const argNameLower = argName.toLowerCase(); const moduleData = getModuleData('component'); - for (const enumData of moduleData.enums) { - if (enumData.enumClassName === 'component.PortType') { - for (const value of enumData.enumValues) { - if (argNameLower === value.toLowerCase()) { - return value; - } - } - break; + if (moduleData) { + for (const enumData of moduleData.enums) { + if (enumData.enumClassName === 'component.PortType') { + for (const value of enumData.enumValues) { + if (argNameLower === value.toLowerCase()) { + return value; + } + } + break; + } } } diff --git a/src/blocks/mrc_get_parameter.ts b/src/blocks/mrc_get_parameter.ts index 2a50b327..a345117f 100644 --- a/src/blocks/mrc_get_parameter.ts +++ b/src/blocks/mrc_get_parameter.ts @@ -27,7 +27,7 @@ import {ExtendedPythonGenerator} from '../editor/extended_python_generator'; import {createFieldNonEditableText} from '../fields/FieldNonEditableText'; import {MRC_STYLE_VARIABLES} from '../themes/styles'; import {BLOCK_NAME as MRC_CLASS_METHOD_DEF, ClassMethodDefBlock} from './mrc_class_method_def'; -import {BLOCK_NAME as MRC_EVENT_HANDLER, EventHandlerBlock} from './mrc_event_handler'; +import {BLOCK_NAME as MRC_EVENT_HANDLER } from './mrc_event_handler'; import * as ChangeFramework from './utils/change_framework'; diff --git a/src/blocks/mrc_port.ts b/src/blocks/mrc_port.ts index 49421d9a..69b748b7 100644 --- a/src/blocks/mrc_port.ts +++ b/src/blocks/mrc_port.ts @@ -65,7 +65,7 @@ export const pythonFromBlock = function ( return [code, Order.ATOMIC]; } -export function createPortShadow(portType: string, portNum: int) { +export function createPortShadow(portType: string, portNum: Number) { return { shadow: { type: 'mrc_port', diff --git a/src/blocks/utils/python.ts b/src/blocks/utils/python.ts index 720f6982..30fd8957 100644 --- a/src/blocks/utils/python.ts +++ b/src/blocks/utils/python.ts @@ -19,7 +19,7 @@ * @author lizlooney@google.com (Liz Looney) */ -import { ClassData, PythonData, organizeVarDataByType, VariableGettersAndSetters } from './python_json_types'; +import { ClassData, PythonData, ModuleData, organizeVarDataByType, VariableGettersAndSetters } from './python_json_types'; import { robotPyData } from './robotpy_data'; import { externalSamplesData } from './external_samples_data'; @@ -157,7 +157,7 @@ export function getAlias(type: string): string | null { // Returns the list of subclass names for the given type. // For example, if type is 'wpilib.drive.RobotDriveBase', this function will // return ['wpilib.drive.DifferentialDrive', 'wpilib.drive.MecanumDrive']. -export function getSubclassNames(type: string): string[] | null { +export function getSubclassNames(type: string): string[] { for (const pythonData of allPythonData) { for (const className in pythonData.subclasses) { if (type === className) { @@ -165,7 +165,7 @@ export function getSubclassNames(type: string): string[] | null { } } } - return null; + return []; } // Returns the array of allowed types for the given string. diff --git a/src/editor/editor.ts b/src/editor/editor.ts index 7781210d..176b9a72 100644 --- a/src/editor/editor.ts +++ b/src/editor/editor.ts @@ -26,17 +26,17 @@ import { GeneratorContext } from './generator_context'; import * as commonStorage from '../storage/common_storage'; import * as mechanismComponentHolder from '../blocks/mrc_mechanism_component_holder'; //import { testAllBlocksInToolbox } from '../toolbox/toolbox_tests'; -import { MethodsCategory} from '../toolbox/methods_category'; -import { EventsCategory} from '../toolbox/event_category'; +import { MethodsCategory } from '../toolbox/methods_category'; +import { EventsCategory } from '../toolbox/event_category'; import { getToolboxJSON } from '../toolbox/toolbox'; const EMPTY_TOOLBOX: Blockly.utils.toolbox.ToolboxDefinition = { - kind: 'categoryToolbox', - contents: [], + kind: 'categoryToolbox', + contents: [], }; export class Editor { - private static workspaceIdToEditor: {[key: string]: Editor} = {}; + private static workspaceIdToEditor: { [key: string]: Editor } = {}; private blocklyWorkspace: Blockly.WorkspaceSvg; private generatorContext: GeneratorContext; @@ -136,14 +136,14 @@ export class Editor { if (currentModule) { // Fetch the content for the current module and the robot. // TODO: Also fetch the content for the mechanisms? - const promises: {[key: string]: Promise} = {}; // key is module path, value is promise of module content. + const promises: { [key: string]: Promise } = {}; // key is module path, value is promise of module content. promises[this.modulePath] = this.storage.fetchModuleContent(this.modulePath); if (this.robotPath !== this.modulePath) { // Also fetch the robot module content. It contains components, etc, that can be used. promises[this.robotPath] = this.storage.fetchModuleContent(this.robotPath) } - const moduleContents: {[key: string]: string} = {}; // key is module path, value is module content + const moduleContents: { [key: string]: string } = {}; // key is module path, value is module content await Promise.all( Object.entries(promises).map(async ([modulePath, promise]) => { moduleContents[modulePath] = await promise; @@ -173,7 +173,7 @@ export class Editor { if (toolbox != this.toolbox) { this.toolbox = toolbox; this.blocklyWorkspace.updateToolbox(toolbox); - // testAllBlocksInToolbox(toolbox); + // testAllBlocksInToolbox(toolbox); } } @@ -220,23 +220,24 @@ export class Editor { throw new Error('getModuleContent: this.currentModule is null.'); } const pythonCode = extendedPythonGenerator.mrcWorkspaceToCode( - this.blocklyWorkspace, this.generatorContext); + this.blocklyWorkspace, this.generatorContext); const exportedBlocks = JSON.stringify(this.generatorContext.getExportedBlocks()); const blocksContent = JSON.stringify( - Blockly.serialization.workspaces.save(this.blocklyWorkspace)); + Blockly.serialization.workspaces.save(this.blocklyWorkspace)); const componentsContent = JSON.stringify(this.getComponents()); return commonStorage.makeModuleContent( - this.currentModule, pythonCode, blocksContent, exportedBlocks, componentsContent); + this.currentModule, pythonCode, blocksContent, exportedBlocks, componentsContent); } private getComponents(): commonStorage.Component[] { const components: commonStorage.Component[] = []; if (this.currentModule?.moduleType === commonStorage.MODULE_TYPE_ROBOT || - this.currentModule?.moduleType === commonStorage.MODULE_TYPE_MECHANISM) { + this.currentModule?.moduleType === commonStorage.MODULE_TYPE_MECHANISM) { // Get the holder block and ask it for the components. const holderBlocks = this.blocklyWorkspace.getBlocksByType(mechanismComponentHolder.BLOCK_NAME); holderBlocks.forEach(holderBlock => { - const componentsFromHolder: commonStorage.Component[] = holderBlock.getComponents(); + const componentsFromHolder: commonStorage.Component[] = + (holderBlock as mechanismComponentHolder.MechanismComponentHolderBlock).getComponents(); componentsFromHolder.forEach(component => { components.push(component); }); diff --git a/src/reactComponents/Tabs.tsx b/src/reactComponents/Tabs.tsx index 368c6082..f64e0378 100644 --- a/src/reactComponents/Tabs.tsx +++ b/src/reactComponents/Tabs.tsx @@ -23,9 +23,6 @@ import * as Antd from 'antd'; import * as commonStorage from '../storage/common_storage'; import * as I18Next from 'react-i18next'; import { - RobotOutlined, - CodeOutlined, - BlockOutlined, CloseOutlined, DeleteOutlined, CopyOutlined, diff --git a/src/reactComponents/ThemeModal.tsx b/src/reactComponents/ThemeModal.tsx index bc20eb8e..f93823a4 100644 --- a/src/reactComponents/ThemeModal.tsx +++ b/src/reactComponents/ThemeModal.tsx @@ -89,7 +89,6 @@ const ThemeModal: React.FC = ({ setSelectedTheme(currentTheme); onClose(); }; - const { token } = Antd.theme.useToken(); return ( { const componentsFromHolder: commonStorage.Component[] = - (holderBlock as mechanismComponentHolder.MechanismComponentHolderBlock).getComponents(); + (holderBlock as MechanismComponentHolder.MechanismComponentHolderBlock).getComponents(); componentsFromHolder.forEach(component => { // Get the blocks for this specific component contents.push({