1616 */
1717
1818/**
19- * @fileoverview Create a component with a name of a certain type
19+ * @fileoverview This is a block that allows your code to use a parameter
20+ * that is passed to a method.
2021 * @author [email protected] (Alan Smith) 2122 */
2223import * as Blockly from 'blockly' ;
23- import { Order } from 'blockly/python' ;
24+ import { Order } from 'blockly/python' ;
25+
26+ import { ExtendedPythonGenerator } from '../editor/extended_python_generator' ;
27+ import { createFieldNonEditableText } from '../fields/FieldNonEditableText' ;
28+ import { MRC_STYLE_VARIABLES } from '../themes/styles' ;
29+ import { BLOCK_NAME as MRC_CLASS_METHOD_DEF , ClassMethodDefBlock } from './mrc_class_method_def' ;
30+ import * as ChangeFramework from './utils/change_framework' ;
2431
25- import { MRC_STYLE_VARIABLES } from '../themes/styles'
26- import { createFieldNonEditableText } from '../fields/FieldNonEditableText' ;
27- import { ExtendedPythonGenerator } from '../editor/extended_python_generator' ;
28- import { BLOCK_NAME as MRC_CLASS_METHOD_DEF , ClassMethodDefBlock } from './mrc_class_method_def' ;
29- import * as ChangeFramework from './utils/change_framework'
30- import { truncate } from 'node:fs' ;
3132
3233export const BLOCK_NAME = 'mrc_get_parameter' ;
3334export const OUTPUT_NAME = 'mrc_get_parameter_output' ;
3435
3536
3637type GetParameterBlock = Blockly . Block & Blockly . BlockSvg & GetParameterMixin ;
37- interface GetParameterMixin extends GetParameterMixinType {
38- }
38+
39+ interface GetParameterMixin extends GetParameterMixinType { }
40+
3941type GetParameterMixinType = typeof GET_PARAMETER_BLOCK ;
4042
4143const GET_PARAMETER_BLOCK = {
4244 parameterType : '' , // Later this will be set to the type of the parameter, e.g. 'string', 'number', etc.
4345 /**
44- * Block initialization.
45- */
46- init : function ( this : GetParameterBlock ) : void {
46+ * Block initialization.
47+ */
48+ init : function ( this : GetParameterBlock ) : void {
4749 this . setStyle ( MRC_STYLE_VARIABLES ) ;
4850 this . appendDummyInput ( )
49- . appendField ( 'parameter' )
50- . appendField ( createFieldNonEditableText ( 'parameter' ) , 'PARAMETER_NAME' ) ;
51+ . appendField ( 'parameter' )
52+ . appendField ( createFieldNonEditableText ( 'parameter' ) , 'PARAMETER_NAME' ) ;
5153
5254 this . setOutput ( true , [ OUTPUT_NAME , this . parameterType ] ) ;
5355 ChangeFramework . registerCallback ( BLOCK_NAME , [ Blockly . Events . BLOCK_MOVE ] , this . onBlockChanged ) ;
5456 } ,
55- setNameAndType : function ( this : GetParameterBlock , name : string , type : string ) : void {
57+ setNameAndType : function ( this : GetParameterBlock , name : string , type : string ) : void {
5658 this . setFieldValue ( name , 'PARAMETER_NAME' ) ;
5759 this . parameterType = type ;
5860 this . setOutput ( true , [ OUTPUT_NAME , type ] ) ;
5961 } ,
6062
6163 onBlockChanged ( block : Blockly . BlockSvg , blockEvent : Blockly . Events . BlockBase ) : void {
62- let blockBlock = block as Blockly . Block ;
64+ const blockBlock = block as Blockly . Block ;
6365
6466 if ( blockEvent . type === Blockly . Events . BLOCK_MOVE ) {
65- let parent = ChangeFramework . getParentOfType ( block , MRC_CLASS_METHOD_DEF ) ;
67+ const parent = ChangeFramework . getParentOfType ( block , MRC_CLASS_METHOD_DEF ) ;
6668
6769 if ( parent ) {
6870 // It is a class method definition, so we see if this variable is in it.
69- let classMethodDefBlock = parent as ClassMethodDefBlock ;
70- for ( const parameter of classMethodDefBlock . mrcParameters ) {
71+ const classMethodDefBlock = parent as ClassMethodDefBlock ;
72+ for ( const parameter of classMethodDefBlock . mrcParameters ) {
7173 if ( parameter . name === blockBlock . getFieldValue ( 'PARAMETER_NAME' ) ) {
7274 // If it is, we allow it to stay.
7375 blockBlock . setWarningText ( null ) ;
@@ -77,21 +79,21 @@ const GET_PARAMETER_BLOCK = {
7779 }
7880 // If we end up here it shouldn't be allowed
7981 block . unplug ( true ) ;
80- blockBlock . setWarningText ( " Parameters can only go in their method's block." )
82+ blockBlock . setWarningText ( ' Parameters can only go in their method\ 's block.' ) ;
8183 }
8284 } ,
83- }
85+ } ;
8486
85- export const setup = function ( ) {
87+ export const setup = function ( ) {
8688 Blockly . Blocks [ BLOCK_NAME ] = GET_PARAMETER_BLOCK ;
87- }
89+ } ;
8890
89- export const pythonFromBlock = function (
90- block : GetParameterBlock ,
91- generator : ExtendedPythonGenerator ,
91+ export const pythonFromBlock = function (
92+ block : GetParameterBlock ,
93+ _generator : ExtendedPythonGenerator ,
9294) {
93- //TODO (Alan) : Specify the type here as well
94- let code = block . getFieldValue ( 'PARAMETER_NAME' ) ;
95+ // TODO (Alan) : Specify the type here as well
96+ const code = block . getFieldValue ( 'PARAMETER_NAME' ) ;
9597
9698 return [ code , Order . ATOMIC ] ;
97- }
99+ } ;
0 commit comments