Skip to content

Commit

Permalink
On/off colors added as block params for grids
Browse files Browse the repository at this point in the history
  • Loading branch information
srietkerk committed Aug 10, 2023
1 parent 6307b6c commit 3267ad0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions localtypings/pxtarget.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,8 @@ declare namespace ts.pxtc {
iconURL?: string;
imageLiteral?: number;
gridLiteral?: number;
gridLiteralOnColor?: string;
gridLiteralOffColor?: string;
imageLiteralColumns?: number; // optional number of columns
imageLiteralRows?: number; // optional number of rows
imageLiteralScale?: number; // button sizing between 0.6 and 2, default is 1
Expand Down
4 changes: 3 additions & 1 deletion pxtblocks/blocklyloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,10 @@ namespace pxt.blocks {
const columns = (fn.attributes.imageLiteralColumns || 5) * gridTemplateString;
const rows = fn.attributes.imageLiteralRows || 5;
const scale = fn.attributes.imageLiteralScale;
const onColor = fn.attributes.gridLiteralOnColor;
const offColor = fn.attributes.gridLiteralOffColor;
let ri = block.appendDummyInput();
ri.appendField(new pxtblockly.FieldMatrix("", { columns, rows, scale }), "LEDS");
ri.appendField(new pxtblockly.FieldMatrix("", { columns, rows, scale, onColor, offColor }), "LEDS");
}

if (fn.attributes.inlineInputMode === "external") {
Expand Down
3 changes: 2 additions & 1 deletion pxtblocks/fields/field_ledmatrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ namespace pxtblockly {
}

private getOpacity(x: number, y: number) {
return this.cellState[x][y] ? '1.0' : '0.2';
const offOpacity = this.offColor ? '1.0': '0.2';
return this.cellState[x][y] ? '1.0' : offOpacity;
}

private updateCell(x: number, y: number) {
Expand Down

0 comments on commit 3267ad0

Please sign in to comment.