Skip to content

Commit fa2aee1

Browse files
committed
Moved types and functions related to module content from common_storage.ts to module_content.ts.
1 parent 1ae530b commit fa2aee1

12 files changed

+285
-262
lines changed

src/blocks/mrc_call_python_function.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ import { createFieldDropdown } from '../fields/FieldDropdown';
3333
import { createFieldNonEditableText } from '../fields/FieldNonEditableText';
3434
import { MRC_STYLE_FUNCTIONS } from '../themes/styles'
3535
import * as toolboxItems from '../toolbox/items';
36-
import * as commonStorage from '../storage/common_storage';
3736
import * as storageModule from '../storage/module';
37+
import * as storageModuleContent from '../storage/module_content';
3838

3939

4040
// A block to call a python function.
@@ -497,11 +497,11 @@ const CALL_PYTHON_FUNCTION = {
497497
},
498498
mutateMethodCaller: function(
499499
this: CallPythonFunctionBlock,
500-
methodOrEvent: commonStorage.Method | commonStorage.Event
500+
methodOrEvent: storageModuleContent.Method | storageModuleContent.Event
501501
): void {
502502
// mutateMethodCaller is called when the method or event definition block in the same module is modified.
503503
if (this.mrcFunctionKind == FunctionKind.EVENT) {
504-
const event = methodOrEvent as commonStorage.Event;
504+
const event = methodOrEvent as storageModuleContent.Event;
505505
this.mrcArgs = [];
506506
event.args.forEach((arg) => {
507507
this.mrcArgs.push({
@@ -510,7 +510,7 @@ const CALL_PYTHON_FUNCTION = {
510510
});
511511
});
512512
} else if (this.mrcFunctionKind == FunctionKind.INSTANCE_WITHIN) {
513-
const method = methodOrEvent as commonStorage.Method;
513+
const method = methodOrEvent as storageModuleContent.Method;
514514
this.mrcReturnType = method.returnType;
515515
this.mrcArgs = [];
516516
// We don't include the arg for the self argument because we don't need a socket for it.
@@ -523,9 +523,9 @@ const CALL_PYTHON_FUNCTION = {
523523
}
524524
this.updateBlock_();
525525
},
526-
getComponentsFromRobot: function(this: CallPythonFunctionBlock): commonStorage.Component[] {
526+
getComponentsFromRobot: function(this: CallPythonFunctionBlock): storageModuleContent.Component[] {
527527
// Get the list of components whose type matches this.mrcComponentClassName.
528-
const components: commonStorage.Component[] = [];
528+
const components: storageModuleContent.Component[] = [];
529529
const editor = Editor.getEditorForBlocklyWorkspace(this.workspace);
530530
if (editor) {
531531
editor.getComponentsFromRobot().forEach(component => {
@@ -551,7 +551,7 @@ const CALL_PYTHON_FUNCTION = {
551551
// visible warning on it.
552552
if (this.mrcFunctionKind === FunctionKind.INSTANCE_COMPONENT) {
553553
let foundComponent = false;
554-
const componentsInScope: commonStorage.Component[] = [];
554+
const componentsInScope: storageModuleContent.Component[] = [];
555555
componentsInScope.push(...this.getComponentsFromRobot());
556556
if (editor.getCurrentModuleType() === storageModule.MODULE_TYPE_MECHANISM) {
557557
componentsInScope.push(...editor.getComponentsFromWorkspace());
@@ -662,7 +662,7 @@ const CALL_PYTHON_FUNCTION = {
662662

663663
let foundMechanismMethod = false;
664664
const mechanism = editor.getMechanism(mechanismInRobot);
665-
const mechanismMethods: commonStorage.Method[] = mechanism
665+
const mechanismMethods: storageModuleContent.Method[] = mechanism
666666
? editor.getMethodsFromMechanism(mechanism) : [];
667667
for (const mechanismMethod of mechanismMethods) {
668668
if (mechanismMethod.blockId === this.mrcOtherBlockId) {
@@ -883,7 +883,7 @@ export function renameMethodCallers(workspace: Blockly.Workspace, otherBlockId:
883883
}
884884

885885
export function mutateMethodCallers(
886-
workspace: Blockly.Workspace, otherBlockId: string, methodOrEvent: commonStorage.Method | commonStorage.Event) {
886+
workspace: Blockly.Workspace, otherBlockId: string, methodOrEvent: storageModuleContent.Method | storageModuleContent.Event) {
887887
const oldRecordUndo = Blockly.Events.getRecordUndo();
888888

889889
getMethodCallers(workspace, otherBlockId).forEach(block => {
@@ -1071,14 +1071,14 @@ function createInstanceMethodBlock(
10711071
}
10721072

10731073
export function addInstanceWithinBlocks(
1074-
methods: commonStorage.Method[],
1074+
methods: storageModuleContent.Method[],
10751075
contents: toolboxItems.ContentsType[]) {
10761076
methods.forEach(method => {
10771077
contents.push(createInstanceWithinBlock(method));
10781078
});
10791079
}
10801080

1081-
function createInstanceWithinBlock(method: commonStorage.Method): toolboxItems.Block {
1081+
function createInstanceWithinBlock(method: storageModuleContent.Method): toolboxItems.Block {
10821082
const extraState: CallPythonFunctionExtraState = {
10831083
functionKind: FunctionKind.INSTANCE_WITHIN,
10841084
returnType: method.returnType,
@@ -1089,7 +1089,7 @@ function createInstanceWithinBlock(method: commonStorage.Method): toolboxItems.B
10891089
const fields: {[key: string]: any} = {};
10901090
fields[FIELD_FUNCTION_NAME] = method.visibleName;
10911091
const inputs: {[key: string]: any} = {};
1092-
// Convert method.args from commonStorage.MethodArg[] to ArgData[].
1092+
// Convert method.args from storageModuleContent.MethodArg[] to ArgData[].
10931093
const args: ArgData[] = [];
10941094
// We don't include the arg for the self argument because we don't need a socket for it.
10951095
for (let i = 1; i < method.args.length; i++) {
@@ -1104,7 +1104,7 @@ function createInstanceWithinBlock(method: commonStorage.Method): toolboxItems.B
11041104
}
11051105

11061106
export function getInstanceComponentBlocks(
1107-
component: commonStorage.Component): toolboxItems.ContentsType[] {
1107+
component: storageModuleContent.Component): toolboxItems.ContentsType[] {
11081108
const contents: toolboxItems.ContentsType[] = [];
11091109

11101110
const classData = getClassData(component.className);
@@ -1132,7 +1132,7 @@ export function getInstanceComponentBlocks(
11321132
}
11331133

11341134
function createInstanceComponentBlock(
1135-
component: commonStorage.Component, functionData: FunctionData): toolboxItems.Block {
1135+
component: storageModuleContent.Component, functionData: FunctionData): toolboxItems.Block {
11361136
const extraState: CallPythonFunctionExtraState = {
11371137
functionKind: FunctionKind.INSTANCE_COMPONENT,
11381138
returnType: functionData.returnType,
@@ -1156,14 +1156,14 @@ function createInstanceComponentBlock(
11561156
}
11571157

11581158
export function addInstanceRobotBlocks(
1159-
methods: commonStorage.Method[],
1159+
methods: storageModuleContent.Method[],
11601160
contents: toolboxItems.ContentsType[]) {
11611161
methods.forEach(method => {
11621162
contents.push(createInstanceRobotBlock(method));
11631163
});
11641164
}
11651165

1166-
function createInstanceRobotBlock(method: commonStorage.Method): toolboxItems.Block {
1166+
function createInstanceRobotBlock(method: storageModuleContent.Method): toolboxItems.Block {
11671167
const extraState: CallPythonFunctionExtraState = {
11681168
functionKind: FunctionKind.INSTANCE_ROBOT,
11691169
returnType: method.returnType,
@@ -1174,7 +1174,7 @@ function createInstanceRobotBlock(method: commonStorage.Method): toolboxItems.Bl
11741174
const fields: {[key: string]: any} = {};
11751175
fields[FIELD_FUNCTION_NAME] = method.visibleName;
11761176
const inputs: {[key: string]: any} = {};
1177-
// Convert method.args from commonStorage.MethodArg[] to ArgData[].
1177+
// Convert method.args from storageModuleContent.MethodArg[] to ArgData[].
11781178
const args: ArgData[] = [];
11791179
// We don't include the arg for the self argument because we don't need a socket for it.
11801180
for (let i = 1; i < method.args.length; i++) {
@@ -1189,17 +1189,17 @@ function createInstanceRobotBlock(method: commonStorage.Method): toolboxItems.Bl
11891189
}
11901190

11911191
export function addInstanceMechanismBlocks(
1192-
mechanismInRobot: commonStorage.MechanismInRobot,
1193-
methods: commonStorage.Method[],
1192+
mechanismInRobot: storageModuleContent.MechanismInRobot,
1193+
methods: storageModuleContent.Method[],
11941194
contents: toolboxItems.ContentsType[]) {
11951195
methods.forEach(method => {
11961196
contents.push(createInstanceMechanismBlock(mechanismInRobot, method));
11971197
});
11981198
}
11991199

12001200
function createInstanceMechanismBlock(
1201-
mechanismInRobot: commonStorage.MechanismInRobot,
1202-
method: commonStorage.Method): toolboxItems.Block {
1201+
mechanismInRobot: storageModuleContent.MechanismInRobot,
1202+
method: storageModuleContent.Method): toolboxItems.Block {
12031203
const extraState: CallPythonFunctionExtraState = {
12041204
functionKind: FunctionKind.INSTANCE_MECHANISM,
12051205
returnType: method.returnType,
@@ -1213,7 +1213,7 @@ function createInstanceMechanismBlock(
12131213
fields[FIELD_MECHANISM_NAME] = mechanismInRobot.name;
12141214
fields[FIELD_FUNCTION_NAME] = method.visibleName;
12151215
const inputs: {[key: string]: any} = {};
1216-
// Convert method.args from commonStorage.MethodArg[] to ArgData[].
1216+
// Convert method.args from storageModuleContent.MethodArg[] to ArgData[].
12171217
const args: ArgData[] = [];
12181218
// For INSTANCE_MECHANISM functions, the 0 argument is 'self', but
12191219
// self is represented by the FIELD_MECHANISM_NAME field.
@@ -1230,14 +1230,14 @@ function createInstanceMechanismBlock(
12301230
}
12311231

12321232
export function addFireEventBlocks(
1233-
events: commonStorage.Event[],
1233+
events: storageModuleContent.Event[],
12341234
contents: toolboxItems.ContentsType[]) {
12351235
events.forEach(event => {
12361236
contents.push(createFireEventBlock(event));
12371237
});
12381238
}
12391239

1240-
function createFireEventBlock(event: commonStorage.Event): toolboxItems.Block {
1240+
function createFireEventBlock(event: storageModuleContent.Event): toolboxItems.Block {
12411241
const extraState: CallPythonFunctionExtraState = {
12421242
functionKind: FunctionKind.EVENT,
12431243
returnType: RETURN_TYPE_NONE,
@@ -1247,7 +1247,7 @@ function createFireEventBlock(event: commonStorage.Event): toolboxItems.Block {
12471247
const fields: {[key: string]: any} = {};
12481248
fields[FIELD_EVENT_NAME] = event.name;
12491249
const inputs: {[key: string]: any} = {};
1250-
// Convert event.args from commonStorage.MethodArg[] to ArgData[].
1250+
// Convert event.args from storageModuleContent.MethodArg[] to ArgData[].
12511251
const args: ArgData[] = [];
12521252
event.args.forEach(methodArg => {
12531253
args.push({

src/blocks/mrc_class_method_def.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import { createFieldNonEditableText } from '../fields/FieldNonEditableText'
2525
import { createFieldFlydown } from '../fields/field_flydown';
2626
import { Order } from 'blockly/python';
2727
import { ExtendedPythonGenerator } from '../editor/extended_python_generator';
28-
import * as commonStorage from '../storage/common_storage';
2928
import * as storageModule from '../storage/module';
29+
import * as storageModuleContent from '../storage/module_content';
3030
import { renameMethodCallers, mutateMethodCallers } from './mrc_call_python_function'
3131
import * as toolboxItems from '../toolbox/items';
3232
import { getClassData } from './utils/python';
@@ -267,8 +267,8 @@ const CLASS_METHOD_DEF = {
267267
}
268268
return legalName;
269269
},
270-
getMethod: function (this: ClassMethodDefBlock): commonStorage.Method | null {
271-
const method: commonStorage.Method = {
270+
getMethod: function (this: ClassMethodDefBlock): storageModuleContent.Method | null {
271+
const method: storageModuleContent.Method = {
272272
blockId: this.id,
273273
visibleName: this.getFieldValue(FIELD_METHOD_NAME),
274274
pythonName: this.mrcFuncName ? this.mrcFuncName : '',
@@ -289,13 +289,13 @@ const CLASS_METHOD_DEF = {
289289
});
290290
return method;
291291
},
292-
getMethodForWithin: function (this: ClassMethodDefBlock): commonStorage.Method | null {
292+
getMethodForWithin: function (this: ClassMethodDefBlock): storageModuleContent.Method | null {
293293
if (this.mrcCanBeCalledWithinClass) {
294294
return this.getMethod();
295295
}
296296
return null;
297297
},
298-
getMethodForOutside: function (this: ClassMethodDefBlock): commonStorage.Method | null {
298+
getMethodForOutside: function (this: ClassMethodDefBlock): storageModuleContent.Method | null {
299299
if (this.mrcCanBeCalledOutsideClass) {
300300
return this.getMethod();
301301
}
@@ -453,7 +453,7 @@ export const pythonFromBlock = function (
453453
code = generator.scrub_(block, code);
454454
generator.addClassMethodDefinition(funcName, code);
455455

456-
// Save the name of the function we just generated so we can use it to create the commonStorage.Method.
456+
// Save the name of the function we just generated so we can use it to create the storageModuleContent.Method.
457457
// in the getMethod function.
458458
block.mrcFuncName = funcName;
459459

@@ -519,7 +519,7 @@ function createClassMethodDefBlock(
519519

520520
export function getMethodsForWithin(
521521
workspace: Blockly.Workspace,
522-
methods: commonStorage.Method[]): void {
522+
methods: storageModuleContent.Method[]): void {
523523
workspace.getBlocksByType(BLOCK_NAME).forEach(block => {
524524
const method = (block as ClassMethodDefBlock).getMethodForWithin();
525525
if (method) {
@@ -530,7 +530,7 @@ export function getMethodsForWithin(
530530

531531
export function getMethodsForOutside(
532532
workspace: Blockly.Workspace,
533-
methods: commonStorage.Method[]): void {
533+
methods: storageModuleContent.Method[]): void {
534534
workspace.getBlocksByType(BLOCK_NAME).forEach(block => {
535535
const method = (block as ClassMethodDefBlock).getMethodForOutside();
536536
if (method) {

src/blocks/mrc_component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import { Editor } from '../editor/editor';
2828
import { ExtendedPythonGenerator } from '../editor/extended_python_generator';
2929
import { getAllowedTypesForSetCheck, getClassData, getModuleData, getSubclassNames } from './utils/python';
3030
import * as toolboxItems from '../toolbox/items';
31-
import * as commonStorage from '../storage/common_storage';
3231
import * as storageModule from '../storage/module';
32+
import * as storageModuleContent from '../storage/module_content';
3333
import * as storageNames from '../storage/names';
3434
import { createPortShadow } from './mrc_port';
3535
import { createNumberShadowValue } from './utils/value';
@@ -150,7 +150,7 @@ const COMPONENT = {
150150
}
151151
return legalName;
152152
},
153-
getComponent: function (this: ComponentBlock): commonStorage.Component | null {
153+
getComponent: function (this: ComponentBlock): storageModuleContent.Component | null {
154154
const componentName = this.getFieldValue(FIELD_NAME);
155155
const componentType = this.getFieldValue(FIELD_TYPE);
156156
const ports: {[port: string]: string} = {};

src/blocks/mrc_event.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { MUTATOR_BLOCK_NAME, PARAM_CONTAINER_BLOCK_NAME, MethodMutatorArgBlock }
2727
import * as ChangeFramework from './utils/change_framework';
2828
import { BLOCK_NAME as MRC_MECHANISM_COMPONENT_HOLDER } from './mrc_mechanism_component_holder';
2929
import * as toolboxItems from '../toolbox/items';
30-
import * as commonStorage from '../storage/common_storage';
30+
import * as storageModuleContent from '../storage/module_content';
3131
import { renameMethodCallers, mutateMethodCallers } from './mrc_call_python_function'
3232

3333
export const BLOCK_NAME = 'mrc_event';
@@ -210,8 +210,8 @@ const EVENT = {
210210
blockBlock.getIcon(Blockly.icons.IconType.WARNING)!.setBubbleVisible(true);
211211
}
212212
},
213-
getEvent: function (this: EventBlock): commonStorage.Event {
214-
const event: commonStorage.Event = {
213+
getEvent: function (this: EventBlock): storageModuleContent.Event {
214+
const event: storageModuleContent.Event = {
215215
blockId: this.id,
216216
name: this.getFieldValue(FIELD_EVENT_NAME),
217217
args: [],

src/blocks/mrc_event_handler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { createFieldFlydown } from '../fields/field_flydown';
2929
import { createFieldNonEditableText } from '../fields/FieldNonEditableText';
3030
import { MRC_STYLE_EVENT_HANDLER } from '../themes/styles';
3131
import * as toolboxItems from '../toolbox/items';
32-
import * as commonStorage from '../storage/common_storage';
32+
import * as storageModuleContent from '../storage/module_content';
3333

3434
export const BLOCK_NAME = 'mrc_event_handler';
3535

@@ -290,15 +290,15 @@ export function pythonFromBlock(
290290
// Functions used for creating blocks for the toolbox.
291291

292292
export function addRobotEventHandlerBlocks(
293-
events: commonStorage.Event[],
293+
events: storageModuleContent.Event[],
294294
contents: toolboxItems.ContentsType[]) {
295295
events.forEach(event => {
296296
contents.push(createRobotEventHandlerBlock(event));
297297
});
298298
}
299299

300300
function createRobotEventHandlerBlock(
301-
event: commonStorage.Event): toolboxItems.Block {
301+
event: storageModuleContent.Event): toolboxItems.Block {
302302
const extraState: EventHandlerExtraState = {
303303
// TODO(lizlooney): ask Alan what pathOfSender is for.
304304
pathOfSender: '',

src/blocks/mrc_mechanism.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import { Editor } from '../editor/editor';
2828
import { ExtendedPythonGenerator } from '../editor/extended_python_generator';
2929
import { getAllowedTypesForSetCheck } from './utils/python';
3030
import * as toolboxItems from '../toolbox/items';
31-
import * as commonStorage from '../storage/common_storage';
3231
import * as storageModule from '../storage/module';
32+
import * as storageModuleContent from '../storage/module_content';
3333
import * as storageNames from '../storage/names';
3434
import * as value from './utils/value';
3535
import { renameMethodCallers } from './mrc_call_python_function'
@@ -153,7 +153,7 @@ const MECHANISM = {
153153
}
154154
return legalName;
155155
},
156-
getMechanism: function (this: MechanismBlock): commonStorage.MechanismInRobot | null {
156+
getMechanism: function (this: MechanismBlock): storageModuleContent.MechanismInRobot | null {
157157
const mechanismName = this.getFieldValue(FIELD_NAME);
158158
const mechanismType = this.mrcImportModule + '.' + this.getFieldValue(FIELD_TYPE);
159159
return {
@@ -174,7 +174,7 @@ const MECHANISM = {
174174
// Then here, we'd look for the mechanism with the marching UUID, and we'd update the
175175
// FIELD_TYPE value if the mechanism's class name had changed.
176176
let foundMechanism: storageModule.Mechanism | null = null;
177-
const components: commonStorage.Component[] = []
177+
const components: storageModuleContent.Component[] = []
178178
for (const mechanism of editor.getMechanisms()) {
179179
if (mechanism.className === this.getFieldValue(FIELD_TYPE)) {
180180
foundMechanism = mechanism;
@@ -247,7 +247,7 @@ export const pythonFromBlock = function (
247247
}
248248

249249
export function createMechanismBlock(
250-
mechanism: storageModule.Mechanism, components: commonStorage.Component[]): toolboxItems.Block {
250+
mechanism: storageModule.Mechanism, components: storageModuleContent.Component[]): toolboxItems.Block {
251251
const snakeCaseName = storageNames.pascalCaseToSnakeCase(mechanism.className);
252252
const mechanismName = 'my_' + snakeCaseName;
253253
const extraState: MechanismExtraState = {

0 commit comments

Comments
 (0)