File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ export class FieldBitmap extends Blockly.Field<number[][]> {
4242 buttonOptions : Buttons ;
4343 pixelSize : number ;
4444 pixelColours : { empty : string ; filled : string } ;
45+ fieldHeight ?: number ;
4546
4647 /**
4748 * Constructor for the bitmap field.
@@ -73,8 +74,9 @@ export class FieldBitmap extends Blockly.Field<number[][]> {
7374 // Set a default empty value
7475 this . setValue ( this . getEmptyArray ( ) ) ;
7576 }
76- if ( config ?. fieldHeight ) {
77- this . pixelSize = config . fieldHeight / this . imgHeight ;
77+ this . fieldHeight = config ?. fieldHeight ;
78+ if ( this . fieldHeight ) {
79+ this . pixelSize = this . fieldHeight / this . imgHeight ;
7880 } else {
7981 this . pixelSize = DEFAULT_PIXEL_SIZE ;
8082 }
@@ -178,6 +180,12 @@ export class FieldBitmap extends Blockly.Field<number[][]> {
178180 if ( newValue ) {
179181 this . imgHeight = newValue . length ;
180182 this . imgWidth = newValue [ 0 ] ? newValue [ 0 ] . length : 0 ;
183+ // If the field height is static, adjust the pixel size to fit.
184+ if ( this . fieldHeight ) {
185+ this . pixelSize = this . fieldHeight / this . imgHeight ;
186+ } else {
187+ this . pixelSize = DEFAULT_PIXEL_SIZE ;
188+ }
181189 }
182190 }
183191
You can’t perform that action at this time.
0 commit comments