From 034692120e9321b939e7c5af2194f60a569ebf28 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Fri, 14 Mar 2025 09:19:28 +1100 Subject: [PATCH] [Refactor] Replace deprecated getConnectionPos (#776) Uses `getInputPos` or `getOutputPos` where appropriate. --- src/LGraphCanvas.ts | 14 ++++++-------- src/LGraphNode.ts | 15 +++++++-------- src/canvas/MovingRenderLink.ts | 4 ++-- src/canvas/ToInputRenderLink.ts | 2 +- src/canvas/ToOutputRenderLink.ts | 2 +- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index 4a828d427..1a1a58f60 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -2197,7 +2197,7 @@ export class LGraphCanvas implements ConnectionColorContext { // Outputs if (outputs) { for (const [i, output] of outputs.entries()) { - const link_pos = node.getConnectionPos(false, i) + const link_pos = node.getOutputPos(i) if (isInRectangle(x, y, link_pos[0] - 15, link_pos[1] - 10, 30, 20)) { // Drag multiple output links if (e.shiftKey && output.links?.length) { @@ -2237,7 +2237,7 @@ export class LGraphCanvas implements ConnectionColorContext { // Inputs if (inputs) { for (const [i, input] of inputs.entries()) { - const link_pos = node.getConnectionPos(true, i) + const link_pos = node.getInputPos(i) if (isInRectangle(x, y, link_pos[0] - 15, link_pos[1] - 10, 30, 20)) { pointer.onDoubleClick = () => node.onInputDblClick?.(i, e) pointer.onClick = () => node.onInputClick?.(i, e) @@ -2393,7 +2393,7 @@ export class LGraphCanvas implements ConnectionColorContext { // search for outputs if (outputs) { for (const [i, output] of outputs.entries()) { - const link_pos = node.getConnectionPos(false, i) + const link_pos = node.getOutputPos(i) if (isInRectangle(e.canvasX, e.canvasY, link_pos[0] - 15, link_pos[1] - 10, 30, 20)) { mClikSlot = output mClikSlot_index = i @@ -2406,7 +2406,7 @@ export class LGraphCanvas implements ConnectionColorContext { // search for inputs if (inputs) { for (const [i, input] of inputs.entries()) { - const link_pos = node.getConnectionPos(true, i) + const link_pos = node.getInputPos(i) if (isInRectangle(e.canvasX, e.canvasY, link_pos[0] - 15, link_pos[1] - 10, 30, 20)) { mClikSlot = input mClikSlot_index = i @@ -2625,8 +2625,7 @@ export class LGraphCanvas implements ConnectionColorContext { const result = node.findInputByType(firstLink.fromSlot.type) if (result) { highlightInput = result.slot - node.getConnectionPos(true, result.index, pos) - highlightPos = pos + highlightPos = node.getInputPos(result.index) } } } else if ( @@ -2643,8 +2642,7 @@ export class LGraphCanvas implements ConnectionColorContext { if (inputId === -1 && outputId === -1) { const result = node.findOutputByType(firstLink.fromSlot.type) if (result) { - node.getConnectionPos(false, result.index, pos) - highlightPos = pos + highlightPos = node.getOutputPos(result.index) } } else { // check if I have a slot below de mouse diff --git a/src/LGraphNode.ts b/src/LGraphNode.ts index 10a66c30e..4f3d0f64f 100644 --- a/src/LGraphNode.ts +++ b/src/LGraphNode.ts @@ -1858,23 +1858,22 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { */ getSlotInPosition(x: number, y: number): IFoundSlot | null { // search for inputs - const link_pos = new Float32Array(2) const { inputs, outputs } = this if (inputs) { for (const [i, input] of inputs.entries()) { - this.getConnectionPos(true, i, link_pos) - if (isInRectangle(x, y, link_pos[0] - 10, link_pos[1] - 5, 20, 10)) { - return { input, slot: i, link_pos } + const pos = this.getInputPos(i) + if (isInRectangle(x, y, pos[0] - 10, pos[1] - 5, 20, 10)) { + return { input, slot: i, link_pos: pos } } } } if (outputs) { for (const [i, output] of outputs.entries()) { - this.getConnectionPos(false, i, link_pos) - if (isInRectangle(x, y, link_pos[0] - 10, link_pos[1] - 5, 20, 10)) { - return { output, slot: i, link_pos } + const pos = this.getOutputPos(i) + if (isInRectangle(x, y, pos[0] - 10, pos[1] - 5, 20, 10)) { + return { output, slot: i, link_pos: pos } } } } @@ -3377,7 +3376,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { }): void { const { slotIndex } = options const isInput = isINodeInputSlot(slot) - const pos = this.getConnectionPos(isInput, slotIndex) + const pos = isInput ? this.getInputPos(slotIndex) : this.getOutputPos(slotIndex) slot._layoutElement = new LayoutElement({ value: slot, diff --git a/src/canvas/MovingRenderLink.ts b/src/canvas/MovingRenderLink.ts index 4cb52bb5a..ee4a36cce 100644 --- a/src/canvas/MovingRenderLink.ts +++ b/src/canvas/MovingRenderLink.ts @@ -62,7 +62,7 @@ export class MovingRenderLink implements RenderLink { this.outputNode = outputNode this.outputSlot = outputSlot this.outputIndex = outputIndex - this.outputPos = outputNode.getConnectionPos(false, outputIndex) + this.outputPos = outputNode.getOutputPos(outputIndex) // Store input info const inputNode = network.getNodeById(inputNodeId) ?? undefined @@ -75,7 +75,7 @@ export class MovingRenderLink implements RenderLink { this.inputNode = inputNode this.inputSlot = inputSlot this.inputIndex = inputIndex - this.inputPos = inputNode.getConnectionPos(true, inputIndex) + this.inputPos = inputNode.getInputPos(inputIndex) // RenderLink props this.node = this.toType === "input" ? outputNode : inputNode diff --git a/src/canvas/ToInputRenderLink.ts b/src/canvas/ToInputRenderLink.ts index 5c04591e6..9c921dd78 100644 --- a/src/canvas/ToInputRenderLink.ts +++ b/src/canvas/ToInputRenderLink.ts @@ -27,6 +27,6 @@ export class ToInputRenderLink implements RenderLink { this.fromSlotIndex = outputIndex this.fromPos = fromReroute ? fromReroute.pos - : this.node.getConnectionPos(false, outputIndex) + : this.node.getOutputPos(outputIndex) } } diff --git a/src/canvas/ToOutputRenderLink.ts b/src/canvas/ToOutputRenderLink.ts index 669b443af..1bd3d2796 100644 --- a/src/canvas/ToOutputRenderLink.ts +++ b/src/canvas/ToOutputRenderLink.ts @@ -27,6 +27,6 @@ export class ToOutputRenderLink implements RenderLink { this.fromSlotIndex = inputIndex this.fromPos = fromReroute ? fromReroute.pos - : this.node.getConnectionPos(true, inputIndex) + : this.node.getInputPos(inputIndex) } }