[Refactor] Replace deprecated getConnectionPos (#776)

Uses `getInputPos` or `getOutputPos` where appropriate.
This commit is contained in:
filtered
2025-03-14 09:19:28 +11:00
committed by GitHub
parent 36f197b34e
commit 034692120e
5 changed files with 17 additions and 20 deletions

View File

@@ -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

View File

@@ -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,

View File

@@ -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

View File

@@ -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)
}
}

View File

@@ -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)
}
}