This commit is contained in:
justumen
2024-09-22 17:27:56 +02:00
parent 37520a9366
commit 6a9d31022a
26 changed files with 455 additions and 51 deletions

52
web/js/combine_images.js Normal file
View File

@@ -0,0 +1,52 @@
import { app } from "../../../scripts/app.js";
app.registerExtension({
name: "Bjornulf.CombineImages",
async nodeCreated(node) {
if (node.comfyClass === "Bjornulf_CombineImages") {
const updateInputs = () => {
const numInputsWidget = node.widgets.find(w => w.name === "number_of_images");
if (!numInputsWidget) return;
const numInputs = numInputsWidget.value;
// Initialize node.inputs if it doesn't exist
if (!node.inputs) {
node.inputs = [];
}
// Filter existing text inputs
const existingInputs = node.inputs.filter(input => input.name.startsWith('image_'));
// Determine if we need to add or remove inputs
if (existingInputs.length < numInputs) {
// Add new text inputs if not enough existing
for (let i = existingInputs.length + 1; i <= numInputs; i++) {
const inputName = `image_${i}`;
if (!node.inputs.find(input => input.name === inputName)) {
node.addInput(inputName, "IMAGE");
}
}
} else {
// Remove excess text inputs if too many
node.inputs = node.inputs.filter(input => !input.name.startsWith('image_') || parseInt(input.name.split('_')[1]) <= numInputs);
}
node.setSize(node.computeSize());
};
// Move number_of_images to the top initially
const numInputsWidget = node.widgets.find(w => w.name === "number_of_images");
if (numInputsWidget) {
node.widgets = [numInputsWidget, ...node.widgets.filter(w => w !== numInputsWidget)];
numInputsWidget.callback = () => {
updateInputs();
app.graph.setDirtyCanvas(true);
};
}
// Delay the initial update to ensure node is fully initialized
setTimeout(updateInputs, 0);
}
}
});

View File

@@ -47,6 +47,10 @@ app.registerExtension({
color = '#0096FF'; // Integer
} else if (/^-?\d*\.?\d+$/.test(value)) {
color = 'orange'; // Float
} else if (value.startsWith("If-Else ERROR: ")) {
color = 'red'; // If-Else ERROR lines
} else if (value.startsWith("tensor(")) {
color = '#0096FF'; // Lines starting with "tensor("
}
w.inputEl.style.color = color;