Skip to content

Commit b387280

Browse files
committed
Handle method names that are python reserved words.
Added known issue to readme: renaming a method definition doesn't update call blocks.
1 parent 612a7e3 commit b387280

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ WARNING! This is not ready for use and is under heavy development of basic featu
1616
2. Mechanisms aren't limited to only Robot or Mechanism class
1717
3. No way to specify whether an opmode is auto or teleop
1818
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.
19+
5. When a method definition block's name or parameters are changed, the call blocks don't update automatically.

src/editor/editor.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class Editor {
5050
this.blocklyWorkspace = blocklyWorkspace;
5151
this.generatorContext = generatorContext;
5252
this.storage = storage;
53-
this.methodsCategory = new MethodsCategory(blocklyWorkspace);
53+
this.methodsCategory = new MethodsCategory(blocklyWorkspace, generatorContext);
5454
}
5555

5656
private onChangeWhileLoading(event: Blockly.Events.Abstract) {
@@ -112,7 +112,6 @@ export class Editor {
112112
public async loadModuleBlocks(currentModule: commonStorage.Module | null) {
113113
this.generatorContext.setModule(currentModule);
114114
this.currentModule = currentModule;
115-
this.methodsCategory.setCurrentModule(currentModule);
116115
if (currentModule) {
117116
this.modulePath = currentModule.modulePath;
118117
this.projectPath = commonStorage.makeProjectPath(currentModule.projectName);
@@ -226,5 +225,4 @@ export class Editor {
226225
throw e;
227226
}
228227
}
229-
230228
}

src/toolbox/methods_category.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import * as Blockly from 'blockly/core';
2323

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

4041
export class MethodsCategory {
41-
private currentModule: commonStorage.Module | null = null;
42+
private generatorContext: GeneratorContext;
4243

43-
constructor(blocklyWorkspace: Blockly.WorkspaceSvg) {
44+
constructor(blocklyWorkspace: Blockly.WorkspaceSvg, generatorContext: GeneratorContext) {
45+
this.generatorContext = generatorContext;
4446
blocklyWorkspace.registerToolboxCategoryCallback(CUSTOM_CATEGORY_METHODS, this.methodsFlyout.bind(this));
4547
}
4648

47-
public setCurrentModule(currentModule: commonStorage.Module | null) {
48-
this.currentModule = currentModule;
49-
}
50-
5149
public methodsFlyout(workspace: Blockly.WorkspaceSvg): ToolboxInfo {
5250
const toolboxInfo = {
5351
contents: [
@@ -110,6 +108,8 @@ export class MethodsCategory {
110108
// mrc_call_python_function block.
111109
workspace.getBlocksByType('mrc_class_method_def', false).forEach((classMethodDefBlock) => {
112110
if (classMethodDefBlock.mrcCanBeCalledWithinClass) {
111+
const nameFieldValue = classMethodDefBlock.getFieldValue('NAME');
112+
const classMethodName = this.generatorContext.getClassMethodName(nameFieldValue);
113113
const callPythonFunctionBlock = {
114114
kind: 'block',
115115
type: 'mrc_call_python_function',
@@ -118,10 +118,10 @@ export class MethodsCategory {
118118
functionKind: 'instance_within',
119119
returnType: classMethodDefBlock.mrcReturnType,
120120
args: [],
121-
actualFunctionName: classMethodDefBlock.mrcPythonMethodName,
121+
actualFunctionName: classMethodName,
122122
},
123123
fields: {
124-
FUNC: classMethodDefBlock.getFieldValue('NAME'),
124+
FUNC: nameFieldValue,
125125
},
126126
};
127127
classMethodDefBlock.mrcParameters.forEach((param) => {

0 commit comments

Comments
 (0)