mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-11-19 23:37:08 +08:00
Allow primitives to connect to reroutes with type
- Added a check so that reroute nodes won't connect widget inputs with the same type but different configs (e.g. seed and steps). - The widget property of widget inputs are distributed among every reroute node in the reroute chain, allowing primitives to connect.
This commit is contained in:
parent
f87ec10a97
commit
c226b2615a
@ -21,8 +21,21 @@ app.registerExtension({
|
|||||||
|
|
||||||
// Prevent multiple connections to different types when we have no input
|
// Prevent multiple connections to different types when we have no input
|
||||||
if (connected && type === LiteGraph.OUTPUT) {
|
if (connected && type === LiteGraph.OUTPUT) {
|
||||||
// Ignore wildcard nodes as these will be updated to real types
|
const callback = function (l) {
|
||||||
const types = new Set(this.outputs[0].links.map((l) => app.graph.links[l].type).filter((t) => t !== "*"));
|
// Map the link to a type, including the widget config if it exists
|
||||||
|
const link = app.graph.links[l];
|
||||||
|
const input = app.graph.getNodeById(link.target_id).getInputInfo(link.target_slot);
|
||||||
|
return [link.type, input?.widget ? JSON.stringify(input.widget.config) : ""];
|
||||||
|
}
|
||||||
|
const types = new Set(
|
||||||
|
this.outputs[0].links
|
||||||
|
// Map each link to a type
|
||||||
|
.map((l) => callback(l))
|
||||||
|
// Ignore wildcard nodes as these will be updated to real types
|
||||||
|
.filter((t) => t[0] !== "*")
|
||||||
|
// Concatenate the type and widget config into a single string
|
||||||
|
.map((t) => t[0] + t[1])
|
||||||
|
);
|
||||||
if (types.size > 1) {
|
if (types.size > 1) {
|
||||||
const linksToDisconnect = [];
|
const linksToDisconnect = [];
|
||||||
for (let i = 0; i < this.outputs[0].links.length - 1; i++) {
|
for (let i = 0; i < this.outputs[0].links.length - 1; i++) {
|
||||||
@ -75,6 +88,7 @@ app.registerExtension({
|
|||||||
// Find all outputs
|
// Find all outputs
|
||||||
const nodes = [this];
|
const nodes = [this];
|
||||||
let outputType = null;
|
let outputType = null;
|
||||||
|
let outputWidget = null;
|
||||||
while (nodes.length) {
|
while (nodes.length) {
|
||||||
currentNode = nodes.pop();
|
currentNode = nodes.pop();
|
||||||
const outputs = (currentNode.outputs ? currentNode.outputs[0].links : []) || [];
|
const outputs = (currentNode.outputs ? currentNode.outputs[0].links : []) || [];
|
||||||
@ -95,8 +109,9 @@ app.registerExtension({
|
|||||||
} else {
|
} else {
|
||||||
// We've found an output
|
// We've found an output
|
||||||
const nodeOutType = node.inputs && node.inputs[link?.target_slot] && node.inputs[link.target_slot].type ? node.inputs[link.target_slot].type : null;
|
const nodeOutType = node.inputs && node.inputs[link?.target_slot] && node.inputs[link.target_slot].type ? node.inputs[link.target_slot].type : null;
|
||||||
if (inputType && nodeOutType !== inputType) {
|
outputWidget = node.inputs[link.target_slot]?.widget ?? null;
|
||||||
// The output doesnt match our input so disconnect it
|
if (inputType && nodeOutType !== inputType && inputType !== "*") {
|
||||||
|
// The output doesnt match our input and is not a wildcard so disconnect it
|
||||||
node.disconnectInput(link.target_slot);
|
node.disconnectInput(link.target_slot);
|
||||||
} else {
|
} else {
|
||||||
outputType = nodeOutType;
|
outputType = nodeOutType;
|
||||||
@ -108,7 +123,7 @@ app.registerExtension({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const displayType = inputType || outputType || "*";
|
const displayType = (inputType === "*" && outputType) || inputType || outputType || "*";
|
||||||
const color = LGraphCanvas.link_type_colors[displayType];
|
const color = LGraphCanvas.link_type_colors[displayType];
|
||||||
|
|
||||||
// Update the types of each node
|
// Update the types of each node
|
||||||
@ -118,6 +133,12 @@ app.registerExtension({
|
|||||||
node.outputs[0].type = inputType || "*";
|
node.outputs[0].type = inputType || "*";
|
||||||
node.__outputType = displayType;
|
node.__outputType = displayType;
|
||||||
node.outputs[0].name = node.properties.showOutputText ? displayType : "";
|
node.outputs[0].name = node.properties.showOutputText ? displayType : "";
|
||||||
|
if (outputWidget) {
|
||||||
|
// Inherit the widget from the connected input
|
||||||
|
node.inputs[0].widget = outputWidget;
|
||||||
|
} else {
|
||||||
|
delete node.inputs[0].widget;
|
||||||
|
}
|
||||||
node.size = node.computeSize();
|
node.size = node.computeSize();
|
||||||
node.applyOrientation();
|
node.applyOrientation();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user