Skip to content

Commit

Permalink
feat: add docking type assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
KermanX committed Nov 10, 2023
1 parent 8860d40 commit c07d92a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/block-data/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default {
output("value", "string"),
event("onInput", t.string),
method("clear", []),
plugin("validator", "validator"),
plugin("validator", "input-plugin"),
),

appbar: component(
Expand Down
2 changes: 1 addition & 1 deletion packages/northstar/src/blocks/component/updatePlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export function updatePlugins(block: ComponentBlock) {
const { plugins } = info;

for (const plugin of plugins) {
block.dockableDirections.push(plugin.direction);
block.dockableDirections.push([plugin.direction, plugin.dataType]);
}
}
4 changes: 3 additions & 1 deletion packages/northstar/src/blocks/special/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export class StateBlock extends FuncBlockBase {
placeholder = "initial value";
outputLabel = "current";

dockableDirections: Direction[] = [Direction.LEFT];
dockableDirections: [Direction, string][] = [
[Direction.LEFT, "state-plugin"],
];

get slots(): string[] {
return [];
Expand Down
4 changes: 2 additions & 2 deletions packages/northstar/src/blocks/special/stateSetter.r.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export class StateSetterBlock extends RectBlock {
removable = true;
duplicateable = true;

dockingDirections: Direction[] = [Direction.LEFT];
dockableDirections: Direction[] = [Direction.LEFT];
dockingDirections: [Direction, string][] = [[Direction.LEFT, "state-plugin"]];
dockableDirections: [Direction, string][] = [[Direction.LEFT, "state-plugin"]];

get onsetSocket() {
return this.getSocketByName("set") as MultiInSocket;
Expand Down
6 changes: 4 additions & 2 deletions packages/northstar/src/blocks/special/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ export class ValidatorBlock extends FuncBlockBase {

errorMessages: string = "Invalid input";

dockingDirections = [Direction.LEFT];
dockableDirections = [Direction.LEFT];
dockingDirections: [Direction, string][] = [[Direction.LEFT, "input-plugin"]];
dockableDirections: [Direction, string][] = [
[Direction.LEFT, "input-plugin"],
];

get slots(): string[] {
return [];
Expand Down
16 changes: 9 additions & 7 deletions packages/visual-flow/src/model/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ export abstract class Block extends ModelBase {
*/
attached = false;

dockableDirections: Direction[] = [];
dockingDirections: Direction[] = [];
dockableDirections: [Direction, string][] = [];
dockingDirections: [Direction, string][] = [];
dockedToBlock: Block | null = null;
dockedByBlocks: [Direction, Block][] = [];

Expand Down Expand Up @@ -322,10 +322,12 @@ export abstract class Block extends ModelBase {
if (this === block || this.predicting) return null;
let minDockingDistanceSquare = MIN_DOCKING_DISTANCE_SQUARE;
let dockingInfo: [Direction, Point] | null = null;
for (const direction of this.dockableDirections) {
for (const [direction, type] of this.dockableDirections) {
if (
block.dockingDirections.includes(direction) &&
!this.dockedByBlocks.some(([d, _b]) => d === direction)
block.dockingDirections.some(
(d) => d[0] == direction && d[1] == type,
) &&
this.dockedByBlocks.every(([d, _b]) => d !== direction)
) {
const p1 = this.getDockedBenchmarkBoardPos(direction);
const p2 = block.getDockingBenchmarkBoardPos(direction);
Expand Down Expand Up @@ -465,8 +467,8 @@ export interface BlockRecord {
id: number;
boardX: number;
boardY: number;
dockableDirections: Direction[];
dockingDirection: Direction[];
dockableDirections: [Direction, string][];
dockingDirection: [Direction, string][];
dockedToBlock: number | null;
dockedByBlocks: [Direction, number][];
sockets: [string, number][];
Expand Down

0 comments on commit c07d92a

Please sign in to comment.