56 lines
1.8 KiB
JavaScript
56 lines
1.8 KiB
JavaScript
import { app } from "../../scripts/app.js";
|
|
|
|
const PANEL_TYPE = "SolidlimeMultiBoolPanel";
|
|
|
|
function widget(node, name) {
|
|
return (node.widgets || []).find((w) => w.name === name);
|
|
}
|
|
|
|
function applyBroadcast(node) {
|
|
const filter = (widget(node, "name_filter")?.value || "").trim();
|
|
const mode = widget(node, "broadcast_mode")?.value;
|
|
if (!filter || !mode || mode === "off") return;
|
|
|
|
const slotCount = Math.max(1, parseInt(widget(node, "slot_count")?.value ?? "4", 10) || 1);
|
|
const targets = (app.graph._nodes || [])
|
|
.filter((n) => n.id !== node.id && (
|
|
(n.title && n.title.includes(filter)) ||
|
|
(n.type && n.type.includes(filter))
|
|
))
|
|
.sort((a, b) => (a.title || a.type).localeCompare(b.title || b.type, "ja"));
|
|
|
|
targets.forEach((t, idx) => {
|
|
const on = idx < slotCount ? !!widget(node, `switch_${idx + 1}`)?.value : false;
|
|
if (mode === "bypass") {
|
|
t.bypass = on;
|
|
} else if (mode === "mute") {
|
|
t.mute = on;
|
|
} else if (mode === "widgets") {
|
|
(t.widgets || []).forEach((wid) => {
|
|
if (wid.type === "boolean" || (wid.options && wid.options.type === "boolean")) {
|
|
wid.value = on;
|
|
}
|
|
});
|
|
}
|
|
});
|
|
app.graph.setDirtyCanvas(true, true);
|
|
}
|
|
|
|
app.registerExtension({
|
|
name: "MultiBoolPanel",
|
|
async setup() {
|
|
const origQueue = app.queuePrompt.bind(app);
|
|
app.queuePrompt = function (number, detail) {
|
|
(app.graph._nodes || []).forEach((n) => {
|
|
if (n.type === PANEL_TYPE && widget(n, "auto_apply")?.value) applyBroadcast(n);
|
|
});
|
|
return origQueue(number, detail);
|
|
};
|
|
},
|
|
async nodeCreated(node) {
|
|
if (node.type === PANEL_TYPE || node.constructor.type === PANEL_TYPE) {
|
|
node.addWidget("button", "Apply to matching nodes", null, () => applyBroadcast(node));
|
|
}
|
|
},
|
|
});
|