Skip to content

Commit d387b9e

Browse files
authored
fix: update pixel with new values (#2373)
1 parent ab5b31c commit d387b9e

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

plugins/field-bitmap/src/field-bitmap.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)