(pos: Point, slot: INodeInputSlot | INodeOutputSlot, afterRerouteId?: RerouteId)
| 2700 | } |
| 2701 | |
| 2702 | connectFloatingReroute(pos: Point, slot: INodeInputSlot | INodeOutputSlot, afterRerouteId?: RerouteId): Reroute { |
| 2703 | const { graph, id } = this |
| 2704 | if (!graph) throw new NullGraphError() |
| 2705 | |
| 2706 | // Assertion: It's either there or it isn't. |
| 2707 | const inputIndex = this.inputs.indexOf(slot as INodeInputSlot) |
| 2708 | const outputIndex = this.outputs.indexOf(slot as INodeOutputSlot) |
| 2709 | if (inputIndex === -1 && outputIndex === -1) throw new Error("Invalid slot") |
| 2710 | |
| 2711 | const slotType = outputIndex === -1 ? "input" : "output" |
| 2712 | |
| 2713 | const reroute = graph.setReroute({ |
| 2714 | pos, |
| 2715 | parentId: afterRerouteId, |
| 2716 | linkIds: [], |
| 2717 | floating: { slotType }, |
| 2718 | }) |
| 2719 | |
| 2720 | const parentReroute = graph.getReroute(afterRerouteId) |
| 2721 | const fromLastFloatingReroute = parentReroute?.floating?.slotType === "output" |
| 2722 | |
| 2723 | // Adding from an ouput, or a floating reroute that is NOT the tip of an existing floating chain |
| 2724 | if (afterRerouteId == null || !fromLastFloatingReroute) { |
| 2725 | const link = new LLink( |
| 2726 | -1, |
| 2727 | slot.type, |
| 2728 | outputIndex === -1 ? -1 : id, |
| 2729 | outputIndex, |
| 2730 | inputIndex === -1 ? -1 : id, |
| 2731 | inputIndex, |
| 2732 | ) |
| 2733 | link.parentId = reroute.id |
| 2734 | graph.addFloatingLink(link) |
| 2735 | return reroute |
| 2736 | } |
| 2737 | |
| 2738 | // Adding a new floating reroute from the tip of a floating chain. |
| 2739 | if (!parentReroute) throw new Error("[connectFloatingReroute] Parent reroute not found") |
| 2740 | |
| 2741 | const link = parentReroute.getFloatingLinks("output")?.[0] |
| 2742 | if (!link) throw new Error("[connectFloatingReroute] Floating link not found") |
| 2743 | |
| 2744 | reroute.floatingLinkIds.add(link.id) |
| 2745 | link.parentId = reroute.id |
| 2746 | delete parentReroute.floating |
| 2747 | return reroute |
| 2748 | } |
| 2749 | |
| 2750 | /** |
| 2751 | * disconnect one output to an specific node |
no test coverage detected