Skip to content

Commit 5da4f22

Browse files
committed
Added canBeCalledWithinClass and canBeCalledOutsideClass to the mrc_class_method_def extraState.
Added mrcCanBeCalledWithinClass and mrcCanBeCalledOutsideClass to the mrc_class_method_def block. Removed Mechanism category from the toolbox. Replaced Methods category with a dynamic category with the method blocks appropriate for the current module.
1 parent bf988cd commit 5da4f22

12 files changed

+364
-55
lines changed

src/blocks/mrc_class_method_def.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export type Parameter = {
4545
type ClassMethodDefBlock = Blockly.Block & ClassMethodDefMixin & Blockly.BlockSvg;
4646
interface ClassMethodDefMixin extends ClassMethodDefMixinType {
4747
mrcCanChangeSignature: boolean,
48+
mrcCanBeCalledWithinClass: boolean,
49+
mrcCanBeCalledOutsideClass: boolean,
4850
mrcReturnType: string,
4951
mrcParameters: Parameter[],
5052
mrcPythonMethodName: string,
@@ -57,6 +59,14 @@ type ClassMethodDefExtraState = {
5759
* Can change name and parameters and return type
5860
*/
5961
canChangeSignature: boolean,
62+
/**
63+
* Can be called from within the class.
64+
*/
65+
canBeCalledWithinClass: boolean,
66+
/**
67+
* Can be called from outside the class.
68+
*/
69+
canBeCalledOutsideClass: boolean,
6070
/**
6171
* The return type of the function.
6272
* Use 'None' for no return value.
@@ -95,6 +105,8 @@ const CLASS_METHOD_DEF = {
95105
this: ClassMethodDefBlock): ClassMethodDefExtraState {
96106
const extraState: ClassMethodDefExtraState = {
97107
canChangeSignature: this.mrcCanChangeSignature,
108+
canBeCalledWithinClass: this.mrcCanBeCalledWithinClass,
109+
canBeCalledOutsideClass: this.mrcCanBeCalledOutsideClass,
98110
returnType: this.mrcReturnType,
99111
params: [],
100112
};
@@ -118,6 +130,8 @@ const CLASS_METHOD_DEF = {
118130
extraState: ClassMethodDefExtraState
119131
): void {
120132
this.mrcCanChangeSignature = extraState.canChangeSignature;
133+
this.mrcCanBeCalledWithinClass = extraState.canBeCalledWithinClass;
134+
this.mrcCanBeCalledOutsideClass = extraState.canBeCalledOutsideClass;
121135
this.mrcPythonMethodName = extraState.pythonMethodName ? extraState.pythonMethodName : '';
122136
this.mrcReturnType = extraState.returnType;
123137
this.mrcParameters = [];

src/editor/editor.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import * as Blockly from 'blockly/core';
2424
import { extendedPythonGenerator } from './extended_python_generator';
2525
import * as commonStorage from '../storage/common_storage';
2626
import { getToolboxJSON } from '../toolbox/toolbox';
27+
import { MethodsCategory} from '../toolbox/methods_category';
2728

2829

2930
const EMPTY_TOOLBOX: Blockly.utils.toolbox.ToolboxDefinition = {
@@ -34,6 +35,7 @@ const EMPTY_TOOLBOX: Blockly.utils.toolbox.ToolboxDefinition = {
3435
export class Editor {
3536
private blocklyWorkspace: Blockly.WorkspaceSvg;
3637
private storage: commonStorage.Storage;
38+
private methodsCategory: MethodsCategory;
3739
private currentModule: commonStorage.Module | null = null;
3840
private modulePath: string = '';
3941
private projectPath: string = '';
@@ -45,6 +47,7 @@ export class Editor {
4547
constructor(blocklyWorkspace: Blockly.WorkspaceSvg, storage: commonStorage.Storage) {
4648
this.blocklyWorkspace = blocklyWorkspace;
4749
this.storage = storage;
50+
this.methodsCategory = new MethodsCategory(blocklyWorkspace);
4851
}
4952

5053
private onChangeWhileLoading(event: Blockly.Events.Abstract) {
@@ -105,6 +108,7 @@ export class Editor {
105108

106109
public async loadModuleBlocks(currentModule: commonStorage.Module | null) {
107110
this.currentModule = currentModule;
111+
this.methodsCategory.setCurrentModule(currentModule);
108112
if (currentModule) {
109113
this.modulePath = currentModule.modulePath;
110114
this.projectPath = commonStorage.makeProjectPath(currentModule.projectName);
@@ -219,4 +223,5 @@ export class Editor {
219223
throw e;
220224
}
221225
}
226+
222227
}

src/modules/mechanism_start.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"deletable": false,
1111
"extraState": {
1212
"canChangeSignature": false,
13+
"canBeCalledWithinClass": false,
14+
"canBeCalledOutsideClass": false,
1315
"returnType": "None",
1416
"params": [],
1517
"pythonMethodName": "__init__"
@@ -26,6 +28,8 @@
2628
"deletable": false,
2729
"extraState": {
2830
"canChangeSignature": false,
31+
"canBeCalledWithinClass": false,
32+
"canBeCalledOutsideClass": false,
2933
"returnType": "None",
3034
"params": []
3135
},
@@ -35,4 +39,4 @@
3539
}
3640
]
3741
}
38-
}
42+
}

src/modules/opmode_start.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"deletable": false,
1111
"extraState": {
1212
"canChangeSignature": false,
13+
"canBeCalledWithinClass": false,
14+
"canBeCalledOutsideClass": false,
1315
"returnType": "None",
1416
"params": [],
1517
"pythonMethodName": "__init__"
@@ -26,6 +28,8 @@
2628
"deletable": false,
2729
"extraState": {
2830
"canChangeSignature": false,
31+
"canBeCalledWithinClass": false,
32+
"canBeCalledOutsideClass": false,
2933
"returnType": "None",
3034
"params": []
3135
},
@@ -35,4 +39,4 @@
3539
}
3640
]
3741
}
38-
}
42+
}

src/modules/robot_start.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"deletable": false,
1111
"extraState": {
1212
"canChangeSignature": false,
13+
"canBeCalledWithinClass": false,
14+
"canBeCalledOutsideClass": false,
1315
"returnType": "None",
1416
"params": [],
1517
"pythonMethodName": "__init__"
@@ -20,4 +22,4 @@
2022
}
2123
]
2224
}
23-
}
25+
}

src/themes/styles.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,21 @@ export const MRC_STYLE_ENUM = 'mrc_style_enum';
2626
export const MRC_STYLE_VARIABLES = 'mrc_style_variables';
2727
export const MRC_STYLE_COMMENTS = 'mrc_style_comments';
2828
export const MRC_STYLE_MISC = 'mrc_style_misc';
29-
export const MRC_STYLE_CLASS_BLOCKS = 'mrc_style_class_blocks'
29+
export const MRC_STYLE_CLASS_BLOCKS = 'mrc_style_class_blocks';
30+
export const MRC_CATEGORY_STYLE_METHODS = 'mrc_category_style_methods';
3031

3132
export const add_mrc_styles = function(theme : Blockly.Theme) : Blockly.Theme {
3233
theme.setBlockStyle(MRC_STYLE_FUNCTIONS,{
3334
colourPrimary: "#805ba5",
3435
colourSecondary: "#e6deed",
3536
colourTertiary: "#664984",
36-
hat: ""
37+
hat: ""
3738
});
3839
theme.setBlockStyle(MRC_STYLE_ENUM,{
3940
colourPrimary: "#5ba5a5",
4041
colourSecondary: "#deeded",
4142
colourTertiary: "#498484",
42-
hat: ""
43+
hat: ""
4344
});
4445
theme.setBlockStyle(MRC_STYLE_VARIABLES, {
4546
colourPrimary: "#5ba55b",
@@ -53,13 +54,17 @@ export const add_mrc_styles = function(theme : Blockly.Theme) : Blockly.Theme {
5354
colourTertiary:"#CDB6E9",
5455
hat:""
5556
});
56-
theme.setBlockStyle(MRC_STYLE_COMMENTS,{
57+
theme.setCategoryStyle(MRC_CATEGORY_STYLE_METHODS, {
58+
colour: '#4A148C',
59+
});
60+
61+
theme.setBlockStyle(MRC_STYLE_COMMENTS, {
5762
colourPrimary: "#5b5ba5",
5863
colourSecondary: "#dedeed",
5964
colourTertiary: "#494984",
6065
hat:""
6166
});
62-
theme.setBlockStyle(MRC_STYLE_MISC,{
67+
theme.setBlockStyle(MRC_STYLE_MISC, {
6368
colourPrimary: "#5b5ba5",
6469
colourSecondary: "#dedeed",
6570
colourTertiary: "#494984",
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google 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] (Liz Looney)
20+
*/
21+
22+
import * as toolboxItems from '../toolbox/items';
23+
24+
25+
/**
26+
* The blocks that define the methods for the Mechanism class.
27+
*
28+
* These blocks will be added (if appropriate) to the Methods category in the
29+
* toolbox.
30+
*/
31+
export const mechanism_class_blocks: toolboxItems.Block[] = [
32+
{
33+
kind: 'block',
34+
type: 'mrc_class_method_def',
35+
fields: {
36+
'NAME': 'update',
37+
},
38+
extraState: {
39+
canChangeSignature: false,
40+
canBeCalledWithinClass: false,
41+
canBeCalledOutsideClass: false,
42+
canDelete: false,
43+
returnType: 'None',
44+
params: [],
45+
},
46+
},
47+
];

0 commit comments

Comments
 (0)