Skip to content
Closed
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ WARNING! This is not ready for use and is under heavy development of basic featu
2. Mechanisms aren't limited to only Robot or Mechanism class
3. No way to specify whether an opmode is auto or teleop
4. Since we changed the "Workspace" terminology to "Project", existing Workspaces are no longer supported. They can be deleted via the browser's Developer Tools - Application tab.
5. When a method definition block's name or parameters are changed, the call blocks don't update automatically.
4 changes: 1 addition & 3 deletions src/editor/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class Editor {
this.blocklyWorkspace = blocklyWorkspace;
this.generatorContext = generatorContext;
this.storage = storage;
this.methodsCategory = new MethodsCategory(blocklyWorkspace);
this.methodsCategory = new MethodsCategory(blocklyWorkspace, generatorContext);
}

private onChangeWhileLoading(event: Blockly.Events.Abstract) {
Expand Down Expand Up @@ -112,7 +112,6 @@ export class Editor {
public async loadModuleBlocks(currentModule: commonStorage.Module | null) {
this.generatorContext.setModule(currentModule);
this.currentModule = currentModule;
this.methodsCategory.setCurrentModule(currentModule);
if (currentModule) {
this.modulePath = currentModule.modulePath;
this.projectPath = commonStorage.makeProjectPath(currentModule.projectName);
Expand Down Expand Up @@ -226,5 +225,4 @@ export class Editor {
throw e;
}
}

}
16 changes: 8 additions & 8 deletions src/toolbox/methods_category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import * as Blockly from 'blockly/core';

import { GeneratorContext } from './generator_context';
import * as commonStorage from '../storage/common_storage';
import { MRC_CATEGORY_STYLE_METHODS } from '../themes/styles'
import { mechanism_class_blocks } from './mechanism_class_methods';
Expand All @@ -38,16 +39,13 @@ export const category = {
};

export class MethodsCategory {
private currentModule: commonStorage.Module | null = null;
private generatorContext: GeneratorContext;

constructor(blocklyWorkspace: Blockly.WorkspaceSvg) {
constructor(blocklyWorkspace: Blockly.WorkspaceSvg, generatorContext: GeneratorContext) {
this.generatorContext = generatorContext;
blocklyWorkspace.registerToolboxCategoryCallback(CUSTOM_CATEGORY_METHODS, this.methodsFlyout.bind(this));
}

public setCurrentModule(currentModule: commonStorage.Module | null) {
this.currentModule = currentModule;
}

public methodsFlyout(workspace: Blockly.WorkspaceSvg): ToolboxInfo {
const toolboxInfo = {
contents: [
Expand Down Expand Up @@ -110,6 +108,8 @@ export class MethodsCategory {
// mrc_call_python_function block.
workspace.getBlocksByType('mrc_class_method_def', false).forEach((classMethodDefBlock) => {
if (classMethodDefBlock.mrcCanBeCalledWithinClass) {
const nameFieldValue = classMethodDefBlock.getFieldValue('NAME');
const classMethodName = this.generatorContext.getClassMethodName(nameFieldValue);
const callPythonFunctionBlock = {
kind: 'block',
type: 'mrc_call_python_function',
Expand All @@ -118,10 +118,10 @@ export class MethodsCategory {
functionKind: 'instance_within',
returnType: classMethodDefBlock.mrcReturnType,
args: [],
actualFunctionName: classMethodDefBlock.mrcPythonMethodName,
actualFunctionName: classMethodName,
},
fields: {
FUNC: classMethodDefBlock.getFieldValue('NAME'),
FUNC: nameFieldValue,
},
};
classMethodDefBlock.mrcParameters.forEach((param) => {
Expand Down