File size: 4,564 Bytes
4450790
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { app } from "../../scripts/app.js";
import { addConnectionLayoutSupport } from "./utils.js";
import { wait } from "../../rgthree/common/shared_utils.js";
import { ComfyWidgets } from "../../scripts/widgets.js";
import { BaseCollectorNode } from "./base_node_collector.js";
import { NodeTypesString } from "./constants.js";
class CollectorNode extends BaseCollectorNode {
    constructor(title = CollectorNode.title) {
        super(title);
        this.comfyClass = NodeTypesString.NODE_COLLECTOR;
        this.onConstructed();
    }
    onConstructed() {
        this.addOutput("Output", "*");
        return super.onConstructed();
    }
    configure(info) {
        var _a;
        if ((_a = info.outputs) === null || _a === void 0 ? void 0 : _a.length) {
            info.outputs.length = 1;
        }
        super.configure(info);
    }
}
CollectorNode.type = NodeTypesString.NODE_COLLECTOR;
CollectorNode.title = NodeTypesString.NODE_COLLECTOR;
class CombinerNode extends CollectorNode {
    constructor(title = CombinerNode.title) {
        super(title);
        const note = ComfyWidgets["STRING"](this, "last_seed", ["STRING", { multiline: true }], app).widget;
        note.inputEl.value =
            'The Node Combiner has been renamed to Node Collector. You can right-click and select "Update to Node Collector" to attempt to automatically update.';
        note.inputEl.readOnly = true;
        note.inputEl.style.backgroundColor = "#332222";
        note.inputEl.style.fontWeight = "bold";
        note.inputEl.style.fontStyle = "italic";
        note.inputEl.style.opacity = "0.8";
        this.getExtraMenuOptions = (_, options) => {
            options.splice(options.length - 1, 0, {
                content: "‼️ Update to Node Collector",
                callback: (_value, _options, _event, _parentMenu, _node) => {
                    updateCombinerToCollector(this);
                },
            });
        };
    }
    configure(info) {
        super.configure(info);
        if (this.title != CombinerNode.title && !this.title.startsWith("‼️")) {
            this.title = "‼️ " + this.title;
        }
    }
}
CombinerNode.legacyType = "Node Combiner (rgthree)";
CombinerNode.title = "‼️ Node Combiner [DEPRECATED]";
async function updateCombinerToCollector(node) {
    if (node.type === CombinerNode.legacyType) {
        const newNode = new CollectorNode();
        if (node.title != CombinerNode.title) {
            newNode.title = node.title.replace("‼️ ", "");
        }
        newNode.pos = [...node.pos];
        newNode.size = [...node.size];
        newNode.properties = { ...node.properties };
        const links = [];
        for (const [index, output] of node.outputs.entries()) {
            for (const linkId of output.links || []) {
                const link = app.graph.links[linkId];
                if (!link)
                    continue;
                const targetNode = app.graph.getNodeById(link.target_id);
                links.push({ node: newNode, slot: index, targetNode, targetSlot: link.target_slot });
            }
        }
        for (const [index, input] of node.inputs.entries()) {
            const linkId = input.link;
            if (linkId) {
                const link = app.graph.links[linkId];
                const originNode = app.graph.getNodeById(link.origin_id);
                links.push({
                    node: originNode,
                    slot: link.origin_slot,
                    targetNode: newNode,
                    targetSlot: index,
                });
            }
        }
        app.graph.add(newNode);
        await wait();
        for (const link of links) {
            link.node.connect(link.slot, link.targetNode, link.targetSlot);
        }
        await wait();
        app.graph.remove(node);
    }
}
app.registerExtension({
    name: "rgthree.NodeCollector",
    registerCustomNodes() {
        addConnectionLayoutSupport(CollectorNode, app, [
            ["Left", "Right"],
            ["Right", "Left"],
        ]);
        LiteGraph.registerNodeType(CollectorNode.title, CollectorNode);
        CollectorNode.category = CollectorNode._category;
    },
});
app.registerExtension({
    name: "rgthree.NodeCombiner",
    registerCustomNodes() {
        addConnectionLayoutSupport(CombinerNode, app, [
            ["Left", "Right"],
            ["Right", "Left"],
        ]);
        LiteGraph.registerNodeType(CombinerNode.legacyType, CombinerNode);
        CombinerNode.category = CombinerNode._category;
    },
});