Add an explosed action for fast toggler nodes to flip all toggles. Addresses #98

This commit is contained in:
rgthree
2024-01-15 15:51:42 -05:00
parent 06a67bfd74
commit a8ec2cd993
10 changed files with 68 additions and 22 deletions
@@ -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<T extends RgthreeBaseNode>(clazz: new(title?: string) => T) {
+8 -6
View File
@@ -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];
}
}
});
});
+1 -1
View File
@@ -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';
+14 -1
View File
@@ -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);
}
}
}
+8 -5
View File
@@ -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];
}
}
});
});
+3
View File
@@ -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);
}
+8 -3
View File
@@ -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({
+1 -1
View File
@@ -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() {
+14 -2
View File
@@ -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" };
+8 -3
View File
@@ -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({