Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src_web/comfyui/fast_groups_muter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,12 @@ class FastGroupsToggleRowWidget extends RgthreeBaseWidget<{toggled: boolean}> {
// TODO: This work should probably live in BaseFastGroupsModeChanger instead of the widgets.
if (newValue && this.node.properties?.[PROPERTY_RESTRICTION]?.includes(" one")) {
for (const widget of this.node.widgets) {
if (widget instanceof FastGroupsToggleRowWidget) {
if ("doModeChange" in widget && typeof widget.doModeChange === "function") {
widget.doModeChange(false, true);
}
}
} else if (!newValue && this.node.properties?.[PROPERTY_RESTRICTION] === "always one") {
newValue = this.node.widgets.every((w) => !w.value || w === this);
newValue = this.node.widgets.every((w) => w === this || !("toggled" in w && w.toggled));
}
}
changeModeOfNodes(getGroupNodes(this.group), (newValue ? this.node.modeOn : this.node.modeOff));
Expand Down
73 changes: 73 additions & 0 deletions src_web/comfyui/tests/fast_groups_restriction_tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import {app} from "scripts/app.js";
import {NodeTypesString} from "../constants.js";
import {describe, expect, should} from "../testing/runner.js";

describe("TestFastGroupsRestrictions", async () => {
for (const {nodeType, modeOff} of [
{nodeType: NodeTypesString.FAST_GROUPS_MUTER, modeOff: 2},
{nodeType: NodeTypesString.FAST_GROUPS_BYPASSER, modeOff: 4},
]) {
for (const {restriction, afterEnable, afterDisable} of [
{restriction: "default", afterEnable: [true, true], afterDisable: [true, false]},
{restriction: "max one", afterEnable: [false, true], afterDisable: [false, false]},
{restriction: "always one", afterEnable: [false, true], afterDisable: [false, true]},
]) {
await should(`${nodeType} enforce ${restriction} after widget adoption`, async () => {
app.graph.clear();
const controller = LiteGraph.createNode(nodeType);
if (
!controller ||
!("refreshWidgets" in controller) ||
typeof controller.refreshWidgets !== "function"
) {
throw new Error(`${nodeType} is not registered`);
}
controller.properties.toggleRestriction = restriction;

const nodes = [0, 500].map((x, index) => {
const node = new LGraphNode(`Member ${index}`);
app.graph.add(node);
node.pos = [x + 50, 100];
node.mode = modeOff;
const group = new LGraphGroup(`Group ${index}`);
app.graph.add(group);
group.pos = [x, 0];
group.size = [400, 300];
return node;
});

try {
app.graph.add(controller);
controller.pos = [0, 400];
await new Promise(requestAnimationFrame);
controller.refreshWidgets();
expect(controller.widgets.length).toBe("group toggle count", 2);
const [first, second] = controller.widgets;
if (
!first ||
!second ||
!("toggle" in first) ||
typeof first.toggle !== "function" ||
!("toggle" in second) ||
typeof second.toggle !== "function"
) {
throw new Error("Group toggle widgets were not created");
}
first.toggle();
second.toggle();
expect(JSON.stringify(nodes.map((node) => node.mode))).toBe(
"modes after enabling two groups",
JSON.stringify(afterEnable.map((active) => (active ? 0 : modeOff))),
);
second.toggle();
expect(JSON.stringify(nodes.map((node) => node.mode))).toBe(
"modes after toggling the second group off",
JSON.stringify(afterDisable.map((active) => (active ? 0 : modeOff))),
);
} finally {
app.graph.clear();
}
});
}
}
});
4 changes: 2 additions & 2 deletions web/comfyui/fast_groups_muter.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,13 @@ class FastGroupsToggleRowWidget extends RgthreeBaseWidget {
if (skipOtherNodeCheck !== true) {
if (newValue && ((_b = (_a = this.node.properties) === null || _a === void 0 ? void 0 : _a[PROPERTY_RESTRICTION]) === null || _b === void 0 ? void 0 : _b.includes(" one"))) {
for (const widget of this.node.widgets) {
if (widget instanceof FastGroupsToggleRowWidget) {
if ("doModeChange" in widget && typeof widget.doModeChange === "function") {
widget.doModeChange(false, true);
}
}
}
else if (!newValue && ((_c = this.node.properties) === null || _c === void 0 ? void 0 : _c[PROPERTY_RESTRICTION]) === "always one") {
newValue = this.node.widgets.every((w) => !w.value || w === this);
newValue = this.node.widgets.every((w) => w === this || !("toggled" in w && w.toggled));
}
}
changeModeOfNodes(getGroupNodes(this.group), (newValue ? this.node.modeOn : this.node.modeOff));
Expand Down