| import {app} from "../../scripts/app.js"; |
|
|
| function setNodeMode(node, mode) { |
| node.mode = mode; |
| node.graph.change(); |
| } |
|
|
| app.registerExtension({ |
| name: "Comfy.GroupOptions", |
| setup() { |
| const orig = LGraphCanvas.prototype.getCanvasMenuOptions; |
| |
| LGraphCanvas.prototype.getCanvasMenuOptions = function () { |
| const options = orig.apply(this, arguments); |
| const group = this.graph.getGroupOnPos(this.graph_mouse[0], this.graph_mouse[1]); |
| if (!group) { |
| return options; |
| } |
|
|
| |
| group.recomputeInsideNodes(); |
| const nodesInGroup = group._nodes; |
|
|
| |
| if (nodesInGroup.length === 0) { |
| return options; |
| } else { |
| |
| options.push(null); |
| } |
|
|
| |
| let allNodesAreSameMode = true; |
| for (let i = 1; i < nodesInGroup.length; i++) { |
| if (nodesInGroup[i].mode !== nodesInGroup[0].mode) { |
| allNodesAreSameMode = false; |
| break; |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| if (allNodesAreSameMode) { |
| const mode = nodesInGroup[0].mode; |
| switch (mode) { |
| case 0: |
| |
| options.push({ |
| content: "Set Group Nodes to Never", |
| callback: () => { |
| for (const node of nodesInGroup) { |
| setNodeMode(node, 2); |
| } |
| } |
| }); |
| options.push({ |
| content: "Bypass Group Nodes", |
| callback: () => { |
| for (const node of nodesInGroup) { |
| setNodeMode(node, 4); |
| } |
| } |
| }); |
| break; |
| case 2: |
| |
| options.push({ |
| content: "Set Group Nodes to Always", |
| callback: () => { |
| for (const node of nodesInGroup) { |
| setNodeMode(node, 0); |
| } |
| } |
| }); |
| options.push({ |
| content: "Bypass Group Nodes", |
| callback: () => { |
| for (const node of nodesInGroup) { |
| setNodeMode(node, 4); |
| } |
| } |
| }); |
| break; |
| case 4: |
| |
| options.push({ |
| content: "Set Group Nodes to Always", |
| callback: () => { |
| for (const node of nodesInGroup) { |
| setNodeMode(node, 0); |
| } |
| } |
| }); |
| options.push({ |
| content: "Set Group Nodes to Never", |
| callback: () => { |
| for (const node of nodesInGroup) { |
| setNodeMode(node, 2); |
| } |
| } |
| }); |
| break; |
| default: |
| |
| options.push({ |
| content: "Set Group Nodes to Always", |
| callback: () => { |
| for (const node of nodesInGroup) { |
| setNodeMode(node, 0); |
| } |
| } |
| }); |
| options.push({ |
| content: "Set Group Nodes to Never", |
| callback: () => { |
| for (const node of nodesInGroup) { |
| setNodeMode(node, 2); |
| } |
| } |
| }); |
| options.push({ |
| content: "Bypass Group Nodes", |
| callback: () => { |
| for (const node of nodesInGroup) { |
| setNodeMode(node, 4); |
| } |
| } |
| }); |
| break; |
| } |
| } else { |
| |
| options.push({ |
| content: "Set Group Nodes to Always", |
| callback: () => { |
| for (const node of nodesInGroup) { |
| setNodeMode(node, 0); |
| } |
| } |
| }); |
| options.push({ |
| content: "Set Group Nodes to Never", |
| callback: () => { |
| for (const node of nodesInGroup) { |
| setNodeMode(node, 2); |
| } |
| } |
| }); |
| options.push({ |
| content: "Bypass Group Nodes", |
| callback: () => { |
| for (const node of nodesInGroup) { |
| setNodeMode(node, 4); |
| } |
| } |
| }); |
| } |
|
|
| return options |
| } |
| } |
| }); |
|
|