@@ -37,12 +37,14 @@ export type ConstructorArg = {
3737
3838type ComponentExtraState = {
3939 importModule ?: string ,
40+ hideParams ?: boolean ,
4041 params ?: ConstructorArg [ ] ,
4142}
4243
4344type ComponentBlock = Blockly . Block & ComponentMixin ;
4445interface ComponentMixin extends ComponentMixinType {
4546 mrcArgs : ConstructorArg [ ] ,
47+ hideParams : boolean ,
4648 mrcImportModule : string ,
4749}
4850type ComponentMixinType = typeof COMPONENT ;
@@ -59,7 +61,6 @@ const COMPONENT = {
5961 . appendField ( createFieldNonEditableText ( '' ) , 'TYPE' ) ;
6062 this . setPreviousStatement ( true , OUTPUT_NAME ) ;
6163 this . setNextStatement ( true , OUTPUT_NAME ) ;
62- // this.setOutput(true, OUTPUT_NAME);
6364 } ,
6465
6566 /**
@@ -74,20 +75,24 @@ const COMPONENT = {
7475 'name' : arg . name ,
7576 'type' : arg . type ,
7677 } ) ;
77- } ) ;
78+ } ) ;
7879 if ( this . mrcImportModule ) {
7980 extraState . importModule = this . mrcImportModule ;
8081 }
82+ if ( this . hideParams ) {
83+ extraState . hideParams = this . hideParams ;
84+ }
8185 return extraState ;
8286 } ,
8387 /**
8488 * Applies the given state to this block.
8589 */
8690 loadExtraState : function ( this : ComponentBlock , extraState : ComponentExtraState ) : void {
8791 this . mrcImportModule = extraState . importModule ? extraState . importModule : '' ;
92+ this . hideParams = extraState . hideParams ? extraState . hideParams : false ;
8893 this . mrcArgs = [ ] ;
8994
90- if ( extraState . params ) {
95+ if ( extraState . params ) {
9196 extraState . params . forEach ( ( arg ) => {
9297 this . mrcArgs . push ( {
9398 'name' : arg . name ,
@@ -101,17 +106,19 @@ const COMPONENT = {
101106 /**
102107 * Update the block to reflect the newly loaded extra state.
103108 */
104- updateBlock_ : function ( this : ComponentBlock ) : void {
109+ updateBlock_ : function ( this : ComponentBlock ) : void {
110+ if ( this . hideParams == false ) {
105111 // Add input sockets for the arguments.
106112 for ( let i = 0 ; i < this . mrcArgs . length ; i ++ ) {
107113 const input = this . appendValueInput ( 'ARG' + i )
108- . setAlign ( Blockly . inputs . Align . RIGHT )
109- . appendField ( this . mrcArgs [ i ] . name ) ;
114+ . setAlign ( Blockly . inputs . Align . RIGHT )
115+ . appendField ( this . mrcArgs [ i ] . name ) ;
110116 if ( this . mrcArgs [ i ] . type ) {
111117 input . setCheck ( getAllowedTypesForSetCheck ( this . mrcArgs [ i ] . type ) ) ;
112118 }
113119 }
114120 }
121+ }
115122}
116123
117124export const setup = function ( ) {
@@ -122,18 +129,26 @@ export const pythonFromBlock = function (
122129 block : ComponentBlock ,
123130 generator : ExtendedPythonGenerator ,
124131) {
125- if ( block . mrcImportModule ) {
132+ if ( block . mrcImportModule ) {
126133 generator . addImport ( block . mrcImportModule ) ;
127134 }
128135 let code = 'self.' + block . getFieldValue ( 'NAME' ) + ' = ' + block . getFieldValue ( 'TYPE' ) + '(' ;
129-
136+
130137 for ( let i = 0 ; i < block . mrcArgs . length ; i ++ ) {
131- const fieldName = 'ARG' + i ;
138+ const fieldName = 'ARG' + i ;
139+ if ( i != 0 ) {
140+ code += ', '
141+ }
142+ if ( block . hideParams ) {
143+ let extension = '' ;
132144 if ( i != 0 ) {
133- code + = ', '
145+ extension = '_' + ( i + 1 ) . toString ( ) ;
134146 }
147+ code += block . mrcArgs [ i ] . name + " = " + block . getFieldValue ( 'NAME' ) + extension ;
148+ } else {
135149 code += block . mrcArgs [ i ] . name + ' = ' + generator . valueToCode ( block , fieldName , Order . NONE ) ;
136- }
150+ }
151+ }
137152 code += ')\n' + "self.hardware.append(self." + block . getFieldValue ( 'NAME' ) + ")\n" ;
138153 return code ;
139154}
0 commit comments