Skip to content

Commit 504948e

Browse files
committed
Ran format on new files
1 parent b84f6fd commit 504948e

File tree

2 files changed

+69
-69
lines changed

2 files changed

+69
-69
lines changed

src/blocks/mrc_jump_to_step.ts

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
*/
2222
import * as Blockly from 'blockly';
2323

24-
import {ExtendedPythonGenerator} from '../editor/extended_python_generator';
25-
import {createFieldNonEditableText} from '../fields/FieldNonEditableText';
26-
import {MRC_STYLE_VARIABLES} from '../themes/styles';
27-
import {BLOCK_NAME as MRC_STEPS, StepsBlock} from './mrc_steps'
24+
import { ExtendedPythonGenerator } from '../editor/extended_python_generator';
25+
import { createFieldNonEditableText } from '../fields/FieldNonEditableText';
26+
import { MRC_STYLE_VARIABLES } from '../themes/styles';
27+
import { BLOCK_NAME as MRC_STEPS, StepsBlock } from './mrc_steps'
2828

2929
export const BLOCK_NAME = 'mrc_jump_to_step';
3030

@@ -45,60 +45,60 @@ const JUMP_TO_STEP_BLOCK = {
4545
/**
4646
* Block initialization.
4747
*/
48-
init: function(this: JumpToStepBlock): void {
48+
init: function (this: JumpToStepBlock): void {
4949
this.appendDummyInput()
50-
.appendField('Jump to')
51-
.appendField(createFieldNonEditableText(''), FIELD_STEP_NAME);
50+
.appendField('Jump to')
51+
.appendField(createFieldNonEditableText(''), FIELD_STEP_NAME);
5252
this.setPreviousStatement(true, null);
5353
this.setInputsInline(true);
5454
this.setStyle(MRC_STYLE_VARIABLES);
55-
this.setTooltip('Jump to the specified step.');
55+
this.setTooltip('Jump to the specified step.');
56+
},
57+
/**
58+
* mrcOnMove is called when an EventBlock is moved.
59+
*/
60+
mrcOnMove: function (this: JumpToStepBlock, _reason: string[]): void {
61+
this.checkBlockPlacement();
62+
},
63+
mrcOnAncestorMove: function (this: JumpToStepBlock): void {
64+
this.checkBlockPlacement();
65+
},
66+
checkBlockPlacement: function (this: JumpToStepBlock): void {
67+
const legalStepNames: string[] = [];
68+
69+
const rootBlock: Blockly.Block | null = this.getRootBlock();
70+
if (rootBlock.type === MRC_STEPS) {
71+
// This block is within a class method definition.
72+
const stepsBlock = rootBlock as StepsBlock;
73+
// Add the method's parameter names to legalStepNames.
74+
legalStepNames.push(...stepsBlock.mrcGetStepNames());
75+
}
76+
77+
if (legalStepNames.includes(this.getFieldValue(FIELD_STEP_NAME))) {
78+
// If this blocks's parameter name is in legalParameterNames, it's good.
79+
this.setWarningText(null, WARNING_ID_NOT_IN_STEP);
80+
this.mrcHasWarning = false;
81+
} else {
82+
// Otherwise, add a warning to this block.
83+
if (!this.mrcHasWarning) {
84+
this.setWarningText(Blockly.Msg.JUMP_CAN_ONLY_GO_IN_THEIR_STEPS_BLOCK, WARNING_ID_NOT_IN_STEP);
85+
this.getIcon(Blockly.icons.IconType.WARNING)!.setBubbleVisible(true);
86+
this.mrcHasWarning = true;
87+
}
88+
}
5689
},
57-
/**
58-
* mrcOnMove is called when an EventBlock is moved.
59-
*/
60-
mrcOnMove: function(this: JumpToStepBlock, _reason: string[]): void {
61-
this.checkBlockPlacement();
62-
},
63-
mrcOnAncestorMove: function(this: JumpToStepBlock): void {
64-
this.checkBlockPlacement();
65-
},
66-
checkBlockPlacement: function(this: JumpToStepBlock): void {
67-
const legalStepNames: string[] = [];
68-
69-
const rootBlock: Blockly.Block | null = this.getRootBlock();
70-
if (rootBlock.type === MRC_STEPS) {
71-
// This block is within a class method definition.
72-
const stepsBlock = rootBlock as StepsBlock;
73-
// Add the method's parameter names to legalStepNames.
74-
legalStepNames.push(...stepsBlock.mrcGetStepNames());
75-
}
76-
77-
if (legalStepNames.includes(this.getFieldValue(FIELD_STEP_NAME))) {
78-
// If this blocks's parameter name is in legalParameterNames, it's good.
79-
this.setWarningText(null, WARNING_ID_NOT_IN_STEP);
80-
this.mrcHasWarning = false;
81-
} else {
82-
// Otherwise, add a warning to this block.
83-
if (!this.mrcHasWarning) {
84-
this.setWarningText(Blockly.Msg.JUMP_CAN_ONLY_GO_IN_THEIR_STEPS_BLOCK, WARNING_ID_NOT_IN_STEP);
85-
this.getIcon(Blockly.icons.IconType.WARNING)!.setBubbleVisible(true);
86-
this.mrcHasWarning = true;
87-
}
88-
}
89-
},
9090
};
9191

92-
export const setup = function() {
92+
export const setup = function () {
9393
Blockly.Blocks[BLOCK_NAME] = JUMP_TO_STEP_BLOCK;
9494
};
9595

96-
export const pythonFromBlock = function(
97-
block: JumpToStepBlock,
98-
_generator: ExtendedPythonGenerator,
96+
export const pythonFromBlock = function (
97+
block: JumpToStepBlock,
98+
_generator: ExtendedPythonGenerator,
9999
) {
100100
let code = 'self.current_step_index = self.mrc_step_name_to_index["' +
101-
block.getFieldValue(FIELD_STEP_NAME) + '"]\n';
101+
block.getFieldValue(FIELD_STEP_NAME) + '"]\n';
102102
code += 'return\n';
103103

104104
return code;

src/blocks/mrc_steps.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @author [email protected] (Alan Smith)
2121
*/
2222
import * as Blockly from 'blockly';
23-
import {Order} from 'blockly/python';
23+
import { Order } from 'blockly/python';
2424

2525
import { MRC_STYLE_STEPS } from '../themes/styles';
2626
import { ExtendedPythonGenerator } from '../editor/extended_python_generator';
@@ -33,10 +33,10 @@ export const BLOCK_NAME = 'mrc_steps';
3333

3434
/** Extra state for serialising call_python_* blocks. */
3535
type StepsExtraState = {
36-
/**
37-
* The steps
38-
*/
39-
stepNames: string[],
36+
/**
37+
* The steps
38+
*/
39+
stepNames: string[],
4040
};
4141

4242
export type StepsBlock = Blockly.Block & StepsMixin & Blockly.BlockSvg;
@@ -58,7 +58,7 @@ const STEPS = {
5858
this.setMutator(stepContainer.getMutatorIcon(this));
5959
this.updateShape_();
6060
},
61-
saveExtraState: function (this: StepsBlock): StepsExtraState{
61+
saveExtraState: function (this: StepsBlock): StepsExtraState {
6262
return {
6363
stepNames: this.mrcStepNames,
6464
};
@@ -75,7 +75,7 @@ const STEPS = {
7575
}
7676
const stepContainerBlock = containerBlock as stepContainer.StepContainerBlock;
7777
const stepItemBlocks: stepContainer.StepItemBlock[] = stepContainerBlock.getStepItemBlocks();
78-
78+
7979
this.mrcStepNames = [];
8080
stepItemBlocks.forEach((stepItemBlock) => {
8181
this.mrcStepNames.push(stepItemBlock.getName());
@@ -90,19 +90,19 @@ const STEPS = {
9090
});
9191
return stepContainer.createMutatorBlocks(workspace, stepNames);
9292
},
93-
/**
94-
* mrcOnMutatorOpen is called when the mutator on an EventBlock is opened.
95-
*/
96-
mrcOnMutatorOpen: function(this: StepsBlock): void {
93+
/**
94+
* mrcOnMutatorOpen is called when the mutator on an EventBlock is opened.
95+
*/
96+
mrcOnMutatorOpen: function (this: StepsBlock): void {
9797
stepContainer.onMutatorOpen(this);
9898
},
99-
mrcOnChange: function(this: StepsBlock): void {
100-
99+
mrcOnChange: function (this: StepsBlock): void {
100+
101101
},
102-
mrcUpdateStepName: function(this: StepsBlock, step : number, newName: string) : string {
102+
mrcUpdateStepName: function (this: StepsBlock, step: number, newName: string): string {
103103
const otherNames = this.mrcStepNames.filter((_name, index) => index !== step);
104104
let currentName = newName;
105-
105+
106106
// Make name unique if it conflicts
107107
while (otherNames.includes(currentName)) {
108108
// Check if currentName ends with a number
@@ -120,30 +120,30 @@ const STEPS = {
120120
this.mrcStepNames[step] = currentName;
121121
// TODO: Rename any jump blocks that refer to this step
122122

123-
123+
124124
return currentName;
125125
},
126126
updateShape_: function (this: StepsBlock): void {
127127
// some way of knowing what was there before and what is there now
128128
let success = true;
129129
let i = 0;
130-
while (success){
130+
while (success) {
131131
success = this.removeInput('CONDITION_' + i, true);
132132
success = this.removeInput('STEP_' + i, true);
133133
i++;
134134
}
135135
for (let j = 0; j < this.mrcStepNames.length; j++) {
136136
const fieldFlydown = createStepFieldFlydown(this.mrcStepNames[j], true);
137-
137+
138138
fieldFlydown.setValidator(this.mrcUpdateStepName.bind(this, j));
139139
this.appendValueInput('CONDITION_' + j)
140140
.appendField(fieldFlydown)
141141
.setCheck('Boolean')
142-
.appendField(Blockly.Msg.REPEAT_UNTIL);
142+
.appendField(Blockly.Msg.REPEAT_UNTIL);
143143
this.appendStatementInput('STEP_' + j);
144144
}
145145
},
146-
mrcGetStepNames: function(this: StepsBlock): string[] {
146+
mrcGetStepNames: function (this: StepsBlock): string[] {
147147
return this.mrcStepNames;
148148
}
149149
};
@@ -156,7 +156,7 @@ export function isStepsInWorkspace(workspace: Blockly.Workspace): boolean {
156156
const blocks = workspace.getBlocksByType(BLOCK_NAME);
157157
return blocks.length > 0;
158158
};
159-
159+
160160
export const pythonFromBlock = function (
161161
block: StepsBlock,
162162
generator: ExtendedPythonGenerator,
@@ -169,7 +169,7 @@ export const pythonFromBlock = function (
169169
code += generator.INDENT + `self.step_from_name['${stepName}'] = ${index}\n`;
170170
code += generator.INDENT + `self.name_from_step[${index}] = '${stepName}'\n`;
171171
});
172-
172+
173173
code += generator.INDENT + 'self.current_step_index = 0\n';
174174
code += generator.INDENT + 'self.initialized = True\n';
175175

@@ -191,6 +191,6 @@ export const pythonFromBlock = function (
191191
});
192192

193193
generator.addClassMethodDefinition('steps', code);
194-
194+
195195
return ''
196196
}

0 commit comments

Comments
 (0)