mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-30 16:20:17 +08:00
Merge branch 'pr/296' into fizzle296
This commit is contained in:
commit
04e43b78a6
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@ temp/
|
|||||||
custom_nodes/
|
custom_nodes/
|
||||||
!custom_nodes/example_node.py.example
|
!custom_nodes/example_node.py.example
|
||||||
extra_model_paths.yaml
|
extra_model_paths.yaml
|
||||||
|
/.vs
|
||||||
|
|||||||
@ -1,13 +1,17 @@
|
|||||||
import { ComfyWidgets, addRandomizeWidget } from "/scripts/widgets.js";
|
import { ComfyWidgets, addSeedControlWidget } from "/scripts/widgets.js";
|
||||||
import { app } from "/scripts/app.js";
|
import { app } from "/scripts/app.js";
|
||||||
|
|
||||||
const CONVERTED_TYPE = "converted-widget";
|
const CONVERTED_TYPE = "converted-widget";
|
||||||
const VALID_TYPES = ["STRING", "combo", "number"];
|
const VALID_TYPES = ["STRING", "combo", "number"];
|
||||||
|
|
||||||
function isConvertableWidget(widget, config) {
|
function isConvertableWidget(widget, config) {
|
||||||
return VALID_TYPES.includes(widget.type) || VALID_TYPES.includes(config[0]);
|
if (widget.name == "seed control after generating")
|
||||||
|
widget.allowConvertToInput = false;
|
||||||
|
else
|
||||||
|
return VALID_TYPES.includes(widget.type) || VALID_TYPES.includes(config[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function hideWidget(node, widget, suffix = "") {
|
function hideWidget(node, widget, suffix = "") {
|
||||||
widget.origType = widget.type;
|
widget.origType = widget.type;
|
||||||
widget.origComputeSize = widget.computeSize;
|
widget.origComputeSize = widget.computeSize;
|
||||||
@ -23,7 +27,7 @@ function hideWidget(node, widget, suffix = "") {
|
|||||||
return widget.value;
|
return widget.value;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Hide any linked widgets, e.g. seed+randomize
|
// Hide any linked widgets, e.g. seed+seedControl
|
||||||
if (widget.linkedWidgets) {
|
if (widget.linkedWidgets) {
|
||||||
for (const w of widget.linkedWidgets) {
|
for (const w of widget.linkedWidgets) {
|
||||||
hideWidget(node, w, ":" + widget.name);
|
hideWidget(node, w, ":" + widget.name);
|
||||||
@ -40,7 +44,7 @@ function showWidget(widget) {
|
|||||||
delete widget.origComputeSize;
|
delete widget.origComputeSize;
|
||||||
delete widget.origSerializeValue;
|
delete widget.origSerializeValue;
|
||||||
|
|
||||||
// Hide any linked widgets, e.g. seed+randomize
|
// Hide any linked widgets, e.g. seed+seedControl
|
||||||
if (widget.linkedWidgets) {
|
if (widget.linkedWidgets) {
|
||||||
for (const w of widget.linkedWidgets) {
|
for (const w of widget.linkedWidgets) {
|
||||||
showWidget(w);
|
showWidget(w);
|
||||||
@ -271,21 +275,35 @@ app.registerExtension({
|
|||||||
}
|
}
|
||||||
|
|
||||||
let widget;
|
let widget;
|
||||||
if (type in ComfyWidgets) {
|
|
||||||
widget = (ComfyWidgets[type](this, "value", inputData, app) || {}).widget;
|
// ComfyWidgets allows a subtype of widgets which is defined by "<type>:<widgetName>"
|
||||||
|
// common example is "INT:seed"
|
||||||
|
// so let's check for those first
|
||||||
|
let combinedWidgetType = type + ":" + widgetName;
|
||||||
|
if (combinedWidgetType in ComfyWidgets) {
|
||||||
|
// widget = (ComfyWidgets[combinedWidgetType](this, "value", inputData, app) || {}).widget;
|
||||||
|
widget = (ComfyWidgets[combinedWidgetType](this, widgetName, inputData, app) || {}).widget;
|
||||||
} else {
|
} else {
|
||||||
widget = this.addWidget(type, "value", null, () => {}, {});
|
// we did not find a subtype, so proceed with "<type>" only
|
||||||
}
|
if (type in ComfyWidgets) {
|
||||||
|
widget = (ComfyWidgets[type](this, widgetName/*"value*"*/, inputData, app) || {}).widget;
|
||||||
|
} else {
|
||||||
|
widget = this.addWidget(type, widgetName /*"value"*/, null, () => { }, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
// addSeedControlWidget(node, seed.widget, "randomize");
|
||||||
|
|
||||||
if (node?.widgets && widget) {
|
if (widget.type === "number") {
|
||||||
const theirWidget = node.widgets.find((w) => w.name === widgetName);
|
addSeedControlWidget(this, widget, "fixed seed");
|
||||||
if (theirWidget) {
|
|
||||||
widget.value = theirWidget.value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget.type === "number") {
|
if (node?.widgets && widget) {
|
||||||
addRandomizeWidget(this, widget, "Random after every gen");
|
|
||||||
|
const theirWidget = node.widgets.find((w) => w.name === widgetName);
|
||||||
|
if (theirWidget) {
|
||||||
|
widget.value = theirWidget.value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// When our value changes, update other widgets to reflect our changes
|
// When our value changes, update other widgets to reflect our changes
|
||||||
|
|||||||
@ -828,11 +828,15 @@ class ComfyApp {
|
|||||||
widget.value = widget.value.slice(7);
|
widget.value = widget.value.slice(7);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (widget.name == "seed control after generating") {
|
||||||
|
if (widget.value == true) {
|
||||||
|
widget.value = "randomize";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.#invokeExtensions("loadedGraphNode", node);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#invokeExtensions("loadedGraphNode", node);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,37 +10,56 @@ function getNumberDefaults(inputData, defaultStep) {
|
|||||||
return { val: defaultVal, config: { min, max, step: 10.0 * step } };
|
return { val: defaultVal, config: { min, max, step: 10.0 * step } };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addRandomizeWidget(node, targetWidget, name, defaultValue = false) {
|
export function addSeedControlWidget(node, targetWidget, defaultValue = "randomize", values) {
|
||||||
const randomize = node.addWidget("toggle", name, defaultValue, function (v) {}, {
|
const seedControl = node.addWidget("combo", "seed control after generating", defaultValue, function (v) { }, {
|
||||||
on: "enabled",
|
values: ["fixed seed", "increment", "decrement", "randomize"],
|
||||||
off: "disabled",
|
|
||||||
serialize: false, // Don't include this in prompt.
|
serialize: false, // Don't include this in prompt.
|
||||||
});
|
})
|
||||||
|
seedControl.afterQueued = () => {
|
||||||
|
|
||||||
randomize.afterQueued = () => {
|
var v = seedControl.value;
|
||||||
if (randomize.value) {
|
|
||||||
const min = targetWidget.options?.min;
|
switch (v) {
|
||||||
let max = targetWidget.options?.max;
|
case ("fixed seed"):
|
||||||
if (min != null || max != null) {
|
console.log("Fixed Seed");
|
||||||
if (max) {
|
break;
|
||||||
// limit max to something that javascript can handle
|
case ("increment"):
|
||||||
max = Math.min(1125899906842624, max);
|
targetWidget.value += 1;
|
||||||
|
console.log("increment");
|
||||||
|
break;
|
||||||
|
case ("decrement"):
|
||||||
|
targetWidget.value -= 1;
|
||||||
|
console.log("decrement");
|
||||||
|
break;
|
||||||
|
case ("randomize"):
|
||||||
|
const min = targetWidget.options?.min;
|
||||||
|
let max = targetWidget.options?.max;
|
||||||
|
if (min != null || max != null) {
|
||||||
|
if (max) {
|
||||||
|
// limit max to something that javascript can handle
|
||||||
|
max = Math.min(1125899906842624, max);
|
||||||
|
console.log("Random");
|
||||||
|
}
|
||||||
|
targetWidget.value = Math.floor(Math.random() * ((max ?? 9999999999) - (min ?? 0) + 1) + (min ?? 0));
|
||||||
|
console.log("Random");
|
||||||
|
} else {
|
||||||
|
targetWidget.value = Math.floor(Math.random() * 1125899906842624);
|
||||||
|
console.log("Random");
|
||||||
}
|
}
|
||||||
targetWidget.value = Math.floor(Math.random() * ((max ?? 9999999999) - (min ?? 0) + 1) + (min ?? 0));
|
break;
|
||||||
} else {
|
default:
|
||||||
targetWidget.value = Math.floor(Math.random() * 1125899906842624);
|
console.log("default (fail)");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return randomize;
|
return seedControl;
|
||||||
}
|
}
|
||||||
|
|
||||||
function seedWidget(node, inputName, inputData) {
|
function seedWidget(node, inputName, inputData) {
|
||||||
const seed = ComfyWidgets.INT(node, inputName, inputData);
|
const seed = ComfyWidgets.INT(node, inputName, inputData);
|
||||||
const randomize = addRandomizeWidget(node, seed.widget, "Random seed after every gen", true);
|
const seedControl = addSeedControlWidget(node, seed.widget, "randomize");
|
||||||
|
|
||||||
seed.widget.linkedWidgets = [randomize];
|
seed.widget.linkedWidgets = [seedControl];
|
||||||
return { widget: seed, randomize };
|
return seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MultilineSymbol = Symbol();
|
const MultilineSymbol = Symbol();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user