From a8ec2cd9930140006f0f8b9482ec86e8dea1fbf5 Mon Sep 17 00:00:00 2001 From: rgthree Date: Mon, 15 Jan 2024 15:51:42 -0500 Subject: [PATCH] Add an explosed action for fast toggler nodes to flip all toggles. Addresses #98 --- src_web/comfyui/base_node_mode_changer.ts | 3 +++ src_web/comfyui/bypasser.ts | 14 ++++++++------ src_web/comfyui/fast_groups_bypasser.ts | 2 +- src_web/comfyui/fast_groups_muter.ts | 15 ++++++++++++++- src_web/comfyui/muter.ts | 13 ++++++++----- web/comfyui/base_node_mode_changer.js | 3 +++ web/comfyui/bypasser.js | 11 ++++++++--- web/comfyui/fast_groups_bypasser.js | 2 +- web/comfyui/fast_groups_muter.js | 16 ++++++++++++++-- web/comfyui/muter.js | 11 ++++++++--- 10 files changed, 68 insertions(+), 22 deletions(-) diff --git a/src_web/comfyui/base_node_mode_changer.ts b/src_web/comfyui/base_node_mode_changer.ts index 7366d6a..bf37574 100644 --- a/src_web/comfyui/base_node_mode_changer.ts +++ b/src_web/comfyui/base_node_mode_changer.ts @@ -89,6 +89,9 @@ export class BaseNodeModeChanger extends BaseAnyInputConnectedNode { forceWidgetOn(widget: IWidget, skipOtherNodeCheck?: boolean) { (widget as any).doModeChange(true, skipOtherNodeCheck); } + forceWidgetToggle(widget: IWidget, skipOtherNodeCheck?: boolean) { + (widget as any).doModeChange(!widget.value, skipOtherNodeCheck); + } static override setUp(clazz: new(title?: string) => T) { diff --git a/src_web/comfyui/bypasser.ts b/src_web/comfyui/bypasser.ts index 9371c8d..bdf28da 100644 --- a/src_web/comfyui/bypasser.ts +++ b/src_web/comfyui/bypasser.ts @@ -9,8 +9,7 @@ const MODE_BYPASS = 4; const MODE_ALWAYS = 0; class BypasserNode extends BaseNodeModeChanger { - - static override exposedActions = ['Bypass all', 'Enable all']; + static override exposedActions = ["Bypass all", "Enable all", "Toggle all"]; static override type = NodeTypesString.FAST_BYPASSER; static override title = NodeTypesString.FAST_BYPASSER; @@ -21,16 +20,19 @@ class BypasserNode extends BaseNodeModeChanger { super(title); } - override async handleAction(action: string) { - if (action === 'Bypass all') { + if (action === "Bypass all") { for (const widget of this.widgets) { this.forceWidgetOff(widget, true); } - } else if (action === 'Enable all') { + } else if (action === "Enable all") { for (const widget of this.widgets) { this.forceWidgetOn(widget, true); } + } else if (action === "Toggle all") { + for (const widget of this.widgets) { + this.forceWidgetToggle(widget, true); + } } } } @@ -45,4 +47,4 @@ app.registerExtension({ (node as any)._tempWidth = node.size[0]; } } -}); \ No newline at end of file +}); diff --git a/src_web/comfyui/fast_groups_bypasser.ts b/src_web/comfyui/fast_groups_bypasser.ts index a1dcc8d..8c5129b 100644 --- a/src_web/comfyui/fast_groups_bypasser.ts +++ b/src_web/comfyui/fast_groups_bypasser.ts @@ -18,7 +18,7 @@ export class FastGroupsBypasser extends FastGroupsMuter { static override type = NodeTypesString.FAST_GROUPS_BYPASSER; static override title = NodeTypesString.FAST_GROUPS_BYPASSER; - static override exposedActions = ["Bypass all", "Enable all"]; + static override exposedActions = ["Bypass all", "Enable all", "Toggle all"]; protected override helpActions = 'bypass and enable'; diff --git a/src_web/comfyui/fast_groups_muter.ts b/src_web/comfyui/fast_groups_muter.ts index 960fae2..709419b 100644 --- a/src_web/comfyui/fast_groups_muter.ts +++ b/src_web/comfyui/fast_groups_muter.ts @@ -215,7 +215,7 @@ export class FastGroupsMuter extends RgthreeBaseNode { override isVirtualNode = true; - static override exposedActions = ["Mute all", "Enable all"]; + static override exposedActions = ["Mute all", "Enable all", "Toggle all"]; readonly modeOn: number = LiteGraph.ALWAYS; readonly modeOff: number = LiteGraph.NEVER; @@ -559,6 +559,19 @@ export class FastGroupsMuter extends RgthreeBaseNode { for (const [index, widget] of this.widgets.entries()) { (widget as any)?.doModeChange(onlyOne && index > 0 ? false : true, true); } + } else if (action === "Toggle all") { + const onlyOne = this.properties?.[PROPERTY_RESTRICTION].includes(" one"); + let foundOne = false; + for (const [index, widget] of this.widgets.entries()) { + // If you have only one, then we'll stop at the first. + let newValue: boolean = onlyOne && foundOne ? false : !widget.value; + foundOne = foundOne || newValue; + (widget as any)?.doModeChange(newValue, true); + } + // And if you have always one, then we'll flip the last + if (!foundOne && this.properties?.[PROPERTY_RESTRICTION] === "always one") { + (this.widgets[this.widgets.length - 1] as any)?.doModeChange(true, true); + } } } diff --git a/src_web/comfyui/muter.ts b/src_web/comfyui/muter.ts index 3ed3883..cae708e 100644 --- a/src_web/comfyui/muter.ts +++ b/src_web/comfyui/muter.ts @@ -9,8 +9,7 @@ const MODE_MUTE = 2; const MODE_ALWAYS = 0; class MuterNode extends BaseNodeModeChanger { - - static override exposedActions = ['Mute all', 'Enable all']; + static override exposedActions = ["Mute all", "Enable all", "Toggle all"]; static override type = NodeTypesString.FAST_MUTER; static override title = NodeTypesString.FAST_MUTER; @@ -22,14 +21,18 @@ class MuterNode extends BaseNodeModeChanger { } override async handleAction(action: string) { - if (action === 'Mute all') { + if (action === "Mute all") { for (const widget of this.widgets) { this.forceWidgetOff(widget, true); } - } else if (action === 'Enable all') { + } else if (action === "Enable all") { for (const widget of this.widgets) { this.forceWidgetOn(widget, true); } + } else if (action === "Toggle all") { + for (const widget of this.widgets) { + this.forceWidgetToggle(widget, true); + } } } } @@ -44,4 +47,4 @@ app.registerExtension({ (node as any)._tempWidth = node.size[0]; } } -}); \ No newline at end of file +}); diff --git a/web/comfyui/base_node_mode_changer.js b/web/comfyui/base_node_mode_changer.js index 1c4ae47..6756c21 100644 --- a/web/comfyui/base_node_mode_changer.js +++ b/web/comfyui/base_node_mode_changer.js @@ -64,6 +64,9 @@ export class BaseNodeModeChanger extends BaseAnyInputConnectedNode { forceWidgetOn(widget, skipOtherNodeCheck) { widget.doModeChange(true, skipOtherNodeCheck); } + forceWidgetToggle(widget, skipOtherNodeCheck) { + widget.doModeChange(!widget.value, skipOtherNodeCheck); + } static setUp(clazz) { BaseAnyInputConnectedNode.setUp(clazz); } diff --git a/web/comfyui/bypasser.js b/web/comfyui/bypasser.js index a53c2a5..43a602f 100644 --- a/web/comfyui/bypasser.js +++ b/web/comfyui/bypasser.js @@ -10,19 +10,24 @@ class BypasserNode extends BaseNodeModeChanger { this.modeOff = MODE_BYPASS; } async handleAction(action) { - if (action === 'Bypass all') { + if (action === "Bypass all") { for (const widget of this.widgets) { this.forceWidgetOff(widget, true); } } - else if (action === 'Enable all') { + else if (action === "Enable all") { for (const widget of this.widgets) { this.forceWidgetOn(widget, true); } } + else if (action === "Toggle all") { + for (const widget of this.widgets) { + this.forceWidgetToggle(widget, true); + } + } } } -BypasserNode.exposedActions = ['Bypass all', 'Enable all']; +BypasserNode.exposedActions = ["Bypass all", "Enable all", "Toggle all"]; BypasserNode.type = NodeTypesString.FAST_BYPASSER; BypasserNode.title = NodeTypesString.FAST_BYPASSER; app.registerExtension({ diff --git a/web/comfyui/fast_groups_bypasser.js b/web/comfyui/fast_groups_bypasser.js index ea329db..cd5638f 100644 --- a/web/comfyui/fast_groups_bypasser.js +++ b/web/comfyui/fast_groups_bypasser.js @@ -15,7 +15,7 @@ export class FastGroupsBypasser extends FastGroupsMuter { } FastGroupsBypasser.type = NodeTypesString.FAST_GROUPS_BYPASSER; FastGroupsBypasser.title = NodeTypesString.FAST_GROUPS_BYPASSER; -FastGroupsBypasser.exposedActions = ["Bypass all", "Enable all"]; +FastGroupsBypasser.exposedActions = ["Bypass all", "Enable all", "Toggle all"]; app.registerExtension({ name: "rgthree.FastGroupsBypasser", registerCustomNodes() { diff --git a/web/comfyui/fast_groups_muter.js b/web/comfyui/fast_groups_muter.js index a004829..a3de3c5 100644 --- a/web/comfyui/fast_groups_muter.js +++ b/web/comfyui/fast_groups_muter.js @@ -416,7 +416,7 @@ export class FastGroupsMuter extends RgthreeBaseNode { return size; } async handleAction(action) { - var _a, _b; + var _a, _b, _c, _d, _e; if (action === "Mute all" || action === "Bypass all") { const alwaysOne = ((_a = this.properties) === null || _a === void 0 ? void 0 : _a[PROPERTY_RESTRICTION]) === "always one"; for (const [index, widget] of this.widgets.entries()) { @@ -429,6 +429,18 @@ export class FastGroupsMuter extends RgthreeBaseNode { widget === null || widget === void 0 ? void 0 : widget.doModeChange(onlyOne && index > 0 ? false : true, true); } } + else if (action === "Toggle all") { + const onlyOne = (_c = this.properties) === null || _c === void 0 ? void 0 : _c[PROPERTY_RESTRICTION].includes(" one"); + let foundOne = false; + for (const [index, widget] of this.widgets.entries()) { + let newValue = onlyOne && foundOne ? false : !widget.value; + foundOne = foundOne || newValue; + widget === null || widget === void 0 ? void 0 : widget.doModeChange(newValue, true); + } + if (!foundOne && ((_d = this.properties) === null || _d === void 0 ? void 0 : _d[PROPERTY_RESTRICTION]) === "always one") { + (_e = this.widgets[this.widgets.length - 1]) === null || _e === void 0 ? void 0 : _e.doModeChange(true, true); + } + } } getHelp() { return ` @@ -503,7 +515,7 @@ export class FastGroupsMuter extends RgthreeBaseNode { } FastGroupsMuter.type = NodeTypesString.FAST_GROUPS_MUTER; FastGroupsMuter.title = NodeTypesString.FAST_GROUPS_MUTER; -FastGroupsMuter.exposedActions = ["Mute all", "Enable all"]; +FastGroupsMuter.exposedActions = ["Mute all", "Enable all", "Toggle all"]; FastGroupsMuter["@matchColors"] = { type: "string" }; FastGroupsMuter["@matchTitle"] = { type: "string" }; FastGroupsMuter["@showNav"] = { type: "boolean" }; diff --git a/web/comfyui/muter.js b/web/comfyui/muter.js index 65abd3e..8a09986 100644 --- a/web/comfyui/muter.js +++ b/web/comfyui/muter.js @@ -10,19 +10,24 @@ class MuterNode extends BaseNodeModeChanger { this.modeOff = MODE_MUTE; } async handleAction(action) { - if (action === 'Mute all') { + if (action === "Mute all") { for (const widget of this.widgets) { this.forceWidgetOff(widget, true); } } - else if (action === 'Enable all') { + else if (action === "Enable all") { for (const widget of this.widgets) { this.forceWidgetOn(widget, true); } } + else if (action === "Toggle all") { + for (const widget of this.widgets) { + this.forceWidgetToggle(widget, true); + } + } } } -MuterNode.exposedActions = ['Mute all', 'Enable all']; +MuterNode.exposedActions = ["Mute all", "Enable all", "Toggle all"]; MuterNode.type = NodeTypesString.FAST_MUTER; MuterNode.title = NodeTypesString.FAST_MUTER; app.registerExtension({