| import {app} from "/scripts/app.js"; |
|
|
| app.registerExtension({ |
| name: "ComfyLiterals.OperationNode", |
| nodeCreated(node, app) { |
| if (node['comfyClass'] === 'Operation') { |
| const onAdded = node.onAdded |
| node.onAdded = function (graph) { |
| console.log("OperationNode onAdded") |
| const firstCallbackResp = onAdded ? onAdded.apply(this, arguments) : undefined; |
|
|
| |
| |
| |
| const inputCache = { |
| "A": node.inputs[1], |
| "B": node.inputs[3] |
| } |
|
|
| if (this.widgets_values) { |
| const aType = this.widgets_values[0] |
| const bType = this.widgets_values[1] |
|
|
| |
| const aIdxToDelete = aType === "INT" ? 1 : 0 |
| |
| const bIdxToDelete = bType === "INT" ? 3 : 1 |
|
|
| inputCache["A"] = node.inputs[aIdxToDelete] |
| this.removeInput(aIdxToDelete) |
| inputCache["B"] = node.inputs[bIdxToDelete] |
| this.removeInput(bIdxToDelete) |
| } else { |
| |
| |
| |
| this.removeInput(1) |
| this.removeInput(2) |
| } |
|
|
| |
| this.widgets[0].callback = function (v, canvas, node) { |
| addInputAtIndex(node, inputCache["A"], 0) |
| inputCache["A"] = node.inputs[1] |
| node.removeInput(1) |
| } |
| this.widgets[1].callback = function (v, canvas, node) { |
| addInputAtIndex(node, inputCache["B"], 2) |
| inputCache["B"] = node.inputs[1] |
| node.removeInput(1) |
| } |
| } |
| } |
| } |
| }) |
|
|
| |
| |
| |
| |
| |
| |
| |
| function addInputAtIndex(node, input, index) { |
| if (!node.inputs) { |
| node.inputs = []; |
| } |
|
|
| if (index > node.inputs.length) { |
| console.warn("LiteGraph: Warning adding port index: " + index + " of node " + node.id + ", it doesnt have so many inputs"); |
| node.inputs.push(input); |
| } else { |
| node.inputs.splice(index, 0, input); |
| } |
| if (node.onInputAdded) { |
| node.onInputAdded(input); |
| } |
| node.setSize(node.computeSize()); |
| LiteGraph.registerNodeAndSlotType(node, input.type || 0); |
|
|
| node.setDirtyCanvas(true, true); |
| return input; |
| } |
|
|