Skip to content

Commit

Permalink
feat: allow to rotate do block
Browse files Browse the repository at this point in the history
  • Loading branch information
KermanX committed Nov 10, 2023
1 parent 0ccb449 commit ca0512b
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions packages/northstar/src/blocks/special/do.r.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import {
PATH_OUT_TRIANGLE,
RectBlock,
SingleOutSocket,
Socket,
UseSocket,
blockCtors,
} from "@quasi-dev/visual-flow";
import { Context } from "refina";
import { PropsData } from "../../utils/props";
import { multiInSocketToOutput, singleOutSocketToOutput } from "../../utils/toOutpus";

const WIDTH = 70;
const HEIGHT = 30;

export class DoBlock extends RectBlock {
cloneTo(target: this): this {
super.cloneTo(target);
Expand All @@ -24,8 +26,8 @@ export class DoBlock extends RectBlock {

type = "state-setter";

boardWidth = 70;
boardHeight = 30;
boardWidth = WIDTH;
boardHeight = HEIGHT;

removable = true;
duplicateable = true;
Expand All @@ -38,21 +40,22 @@ export class DoBlock extends RectBlock {
}

socketNum: number = 2;
rotate: boolean = false;

socketUpdater(useSocket: UseSocket): void {
useSocket("when", MultiInSocket, {
hideLabel: true,
type: "E",
path: PATH_IN_TRIANGLE,
direction: Direction.TOP,
direction: this.rotate ? Direction.LEFT : Direction.TOP,
});

for (let i = 0; i < this.socketNum; i++) {
useSocket(`then-${i}`, SingleOutSocket, {
hideLabel: true,
type: "E",
path: PATH_OUT_TRIANGLE,
direction: Direction.BOTTOM,
direction: this.rotate ? Direction.RIGHT : Direction.BOTTOM,
});
}
}
Expand All @@ -70,6 +73,23 @@ export class DoBlock extends RectBlock {
this.socketNum = isNaN(length) ? 0 : length;
},
},
{
name: "rotate",
type: "switch",
getVal: () => {
return this.rotate;
},
setVal: val => {
this.rotate = val;
if (val) {
this.boardWidth = HEIGHT;
this.boardHeight = WIDTH;
} else {
this.boardWidth = WIDTH;
this.boardHeight = HEIGHT;
}
},
},
];
}

Expand Down

0 comments on commit ca0512b

Please sign in to comment.