Fix primitive node connected slot types
This commit is contained in:
@@ -272,7 +272,7 @@ function convertPrimitiveNode(vanillaWorkflow: ComfyVanillaWorkflow, node: Seria
|
|||||||
const widgetLayout = layoutState.addWidget(group, comfyWidgetNode)
|
const widgetLayout = layoutState.addWidget(group, comfyWidgetNode)
|
||||||
widgetLayout.attrs.title = mainOutput.name;
|
widgetLayout.attrs.title = mainOutput.name;
|
||||||
|
|
||||||
// Rewrite links to point to the new widget node
|
// Follow the existing links on the original node and do some cleanup
|
||||||
const newLinkOutputSlot = serWidgetNode.outputs.findIndex(o => o.name === comfyWidgetNode.outputSlotName)
|
const newLinkOutputSlot = serWidgetNode.outputs.findIndex(o => o.name === comfyWidgetNode.outputSlotName)
|
||||||
if (newLinkOutputSlot !== -1) {
|
if (newLinkOutputSlot !== -1) {
|
||||||
const newLinkOutput = serWidgetNode.outputs[newLinkOutputSlot];
|
const newLinkOutput = serWidgetNode.outputs[newLinkOutputSlot];
|
||||||
@@ -280,24 +280,31 @@ function convertPrimitiveNode(vanillaWorkflow: ComfyVanillaWorkflow, node: Seria
|
|||||||
for (const linkID of mainOutput.links) {
|
for (const linkID of mainOutput.links) {
|
||||||
const link = vanillaWorkflow.links.find(l => l[0] === linkID)
|
const link = vanillaWorkflow.links.find(l => l[0] === linkID)
|
||||||
if (link) {
|
if (link) {
|
||||||
|
// Rewrite links to point to the new widget node
|
||||||
link[1] = serWidgetNode.id; // origin node ID
|
link[1] = serWidgetNode.id; // origin node ID
|
||||||
link[2] = newLinkOutputSlot; // origin node slot
|
link[2] = newLinkOutputSlot; // origin node slot
|
||||||
newLinkOutput.links ||= []
|
newLinkOutput.links ||= []
|
||||||
newLinkOutput.links.push(linkID)
|
newLinkOutput.links.push(linkID)
|
||||||
|
|
||||||
// Change the title of the widget to the name of the first input connected to
|
// Look up the node the link was connected to.
|
||||||
if (foundTitle == null) {
|
|
||||||
const targetNode = vanillaWorkflow.nodes.find(n => n.id === link[3]) // target node ID
|
const targetNode = vanillaWorkflow.nodes.find(n => n.id === link[3]) // target node ID
|
||||||
if (targetNode != null) {
|
const foundInput = targetNode != null ? targetNode.inputs[link[4]] : null // target node slot
|
||||||
const foundInput = targetNode.inputs[link[4]] // target node slot
|
|
||||||
if (foundInput != null && foundInput.name) {
|
// Make sure that the input type for the connected inputs is correct.
|
||||||
|
// ComfyUI seems to set them to the input def type instead of the litegraph type.
|
||||||
|
// For example a "number" input gets changed to type "INT" or "FLOAT"
|
||||||
|
link[5] = widgetInputType // link data type
|
||||||
|
if (foundInput != null) {
|
||||||
|
foundInput.type = widgetInputType;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Change the title of the widget to the name of the first input connected to
|
||||||
|
if (foundTitle == null && foundInput != null && foundInput.name) {
|
||||||
foundTitle = foundInput.name;
|
foundTitle = foundInput.name;
|
||||||
widgetLayout.attrs.title = foundTitle;
|
widgetLayout.attrs.title = foundTitle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
// Remove links on the old node so they won't be double-removed when it's pruned
|
// Remove links on the old node so they won't be double-removed when it's pruned
|
||||||
mainOutput.links = []
|
mainOutput.links = []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,11 @@ export default class convertVanillaWorkflowTests extends UnitTest {
|
|||||||
const kSampler = convWorkflow.graph.findNodesByType("KSampler")[0];
|
const kSampler = convWorkflow.graph.findNodesByType("KSampler")[0];
|
||||||
expect(links[0].origin_id).toEqual(widget.node.id);
|
expect(links[0].origin_id).toEqual(widget.node.id);
|
||||||
expect(links[0].target_id).toEqual(kSampler.id);
|
expect(links[0].target_id).toEqual(kSampler.id);
|
||||||
|
|
||||||
expect(widget.node.outputs[0].type).toEqual("number");
|
expect(widget.node.outputs[0].type).toEqual("number");
|
||||||
|
|
||||||
|
const targetNode = widget.node.getOutputNodes(0)[0]
|
||||||
|
expect(targetNode.inputs[links[0].target_slot].type).toEqual("number")
|
||||||
expect(links[0].type).toEqual("number");
|
expect(links[0].type).toEqual("number");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user