Skip to content

Commit

Permalink
feat: led 사이즈 변경 대응
Browse files Browse the repository at this point in the history
  • Loading branch information
Tnks2U committed Dec 18, 2024
1 parent 6d9b717 commit bdf8c4c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/playground/blocks/hardwareLite/block_microbit2_lite.js
Original file line number Diff line number Diff line change
Expand Up @@ -1487,6 +1487,13 @@ const EVENT_INTERVAL = 150;
params: [
{
type: 'Led2',
value: [
[0, 0, 0, 0, 0],
[0, 9, 0, 9, 0],
[0, 0, 0, 0, 0],
[9, 0, 0, 0, 9],
[0, 9, 9, 9, 0],
],
},
{
type: 'Indicator',
Expand Down
9 changes: 6 additions & 3 deletions src/playground/field/led2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { LedPicker } from '@entrylabs/tool';
/*
*
*/
const DEFAULT_LED_SIZE = 5;

Entry.FieldLed2 = class FieldLed2 extends Entry.Field {
constructor(content, blockView, index) {
super(content, blockView, index);
Expand Down Expand Up @@ -35,6 +37,7 @@ Entry.FieldLed2 = class FieldLed2 extends Entry.Field {
[0, 9, 9, 9, 0],
]
);
this.ledSize = this.getValue().length || DEFAULT_LED_SIZE;
/*
*/
Expand All @@ -46,8 +49,8 @@ Entry.FieldLed2 = class FieldLed2 extends Entry.Field {

renderLed() {
const ledStatus = this.getValue();
const ledDist = 3;
const ledOffset = 0.5;
const ledDist = 3 * (DEFAULT_LED_SIZE / this.ledSize);
const ledOffset = 0.5 * (DEFAULT_LED_SIZE / this.ledSize);
const currentStatus = ledStatus.params || ledStatus;
currentStatus.map((leds, x_pos) => {
return leds.map((led, y_pos) => {
Expand Down Expand Up @@ -107,7 +110,7 @@ Entry.FieldLed2 = class FieldLed2 extends Entry.Field {
fill: '#008380',
});

this._rect = [[], [], [], [], []];
this._rect = Array.from({ length: this.ledSize }, () => []);
this.renderLed();
this._arrow = this.svgGroup.elem('path', {
d: `M 30.79 -1.182
Expand Down

0 comments on commit bdf8c4c

Please sign in to comment.