mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-26 22:30:19 +08:00
random commit
This commit is contained in:
parent
d3a375c8fb
commit
ee1e423ac3
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@ temp/
|
||||
custom_nodes/
|
||||
!custom_nodes/example_node.py.example
|
||||
extra_model_paths.yaml
|
||||
/.vs
|
||||
|
||||
@ -1,13 +1,14 @@
|
||||
import { ComfyWidgets, addRandomizeWidget } from "/scripts/widgets.js";
|
||||
import { ComfyWidgets, addSeedControlWidget } from "/scripts/widgets.js";
|
||||
import { app } from "/scripts/app.js";
|
||||
|
||||
const CONVERTED_TYPE = "converted-widget";
|
||||
const VALID_TYPES = ["STRING", "combo", "number"];
|
||||
|
||||
function isConvertableWidget(widget, config) {
|
||||
return VALID_TYPES.includes(widget.type) || VALID_TYPES.includes(config[0]);
|
||||
return VALID_TYPES.includes(widget.type) || VALID_TYPES.includes(config[0]);
|
||||
}
|
||||
|
||||
|
||||
function hideWidget(node, widget, suffix = "") {
|
||||
widget.origType = widget.type;
|
||||
widget.origComputeSize = widget.computeSize;
|
||||
@ -23,7 +24,7 @@ function hideWidget(node, widget, suffix = "") {
|
||||
return widget.value;
|
||||
};
|
||||
|
||||
// Hide any linked widgets, e.g. seed+randomize
|
||||
// Hide any linked widgets, e.g. seed+seedControl
|
||||
if (widget.linkedWidgets) {
|
||||
for (const w of widget.linkedWidgets) {
|
||||
hideWidget(node, w, ":" + widget.name);
|
||||
@ -40,7 +41,7 @@ function showWidget(widget) {
|
||||
delete widget.origComputeSize;
|
||||
delete widget.origSerializeValue;
|
||||
|
||||
// Hide any linked widgets, e.g. seed+randomize
|
||||
// Hide any linked widgets, e.g. seed+seedControl
|
||||
if (widget.linkedWidgets) {
|
||||
for (const w of widget.linkedWidgets) {
|
||||
showWidget(w);
|
||||
@ -172,6 +173,10 @@ app.registerExtension({
|
||||
node.pos = pos;
|
||||
node.connect(0, this, slot);
|
||||
node.title = input.name;
|
||||
if (node.title == "seed") {
|
||||
node.widgets.addSeedControlWidget(node, node.widgets[0], "randomize");
|
||||
value.widget.linkedWidgets = [seedControl];
|
||||
}
|
||||
|
||||
// Prevent adding duplicates due to triple clicking
|
||||
input[ignoreDblClick] = true;
|
||||
@ -188,7 +193,7 @@ app.registerExtension({
|
||||
constructor() {
|
||||
this.addOutput("connect to widget input", "*");
|
||||
this.serialize_widgets = true;
|
||||
this.isVirtualNode = true;
|
||||
this.isVirtualNode = true;
|
||||
}
|
||||
|
||||
applyToGraph() {
|
||||
@ -284,9 +289,9 @@ app.registerExtension({
|
||||
}
|
||||
}
|
||||
|
||||
if (widget.type === "number") {
|
||||
addRandomizeWidget(this, widget, "Random after every gen");
|
||||
}
|
||||
if (widget.type === "combo")
|
||||
addSeedControlWidget(this, widget, "randomize");
|
||||
|
||||
|
||||
// When our value changes, update other widgets to reflect our changes
|
||||
// e.g. so LoadImage shows correct image
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { ComfyWidgets } from "./widgets.js";
|
||||
import { addSeedControlWidget, ComfyWidgets } from "./widgets.js";
|
||||
import { ComfyUI } from "./ui.js";
|
||||
import { api } from "./api.js";
|
||||
import { defaultGraph } from "./defaultGraph.js";
|
||||
@ -771,10 +771,16 @@ class ComfyApp {
|
||||
widget.value = widget.value.slice(7);
|
||||
}
|
||||
}
|
||||
|
||||
if (widget.name == "seed control after generating") {
|
||||
if (widget.value == true) {
|
||||
widget.value = "randomize";
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.#invokeExtensions("loadedGraphNode", node);
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,37 +10,55 @@ function getNumberDefaults(inputData, defaultStep) {
|
||||
return { val: defaultVal, config: { min, max, step: 10.0 * step } };
|
||||
}
|
||||
|
||||
export function addRandomizeWidget(node, targetWidget, name, defaultValue = false) {
|
||||
const randomize = node.addWidget("toggle", name, defaultValue, function (v) {}, {
|
||||
on: "enabled",
|
||||
off: "disabled",
|
||||
serialize: false, // Don't include this in prompt.
|
||||
});
|
||||
export function addSeedControlWidget(node, targetWidget, defaultValue = "randomize", values) {
|
||||
const seedControl = node.addWidget("combo", "seed control after generating", "randomize", function (v) { }, {
|
||||
values: ["fixed seed", "increment", "decrement", "randomize"]
|
||||
})
|
||||
seedControl.afterQueued = () => {
|
||||
|
||||
randomize.afterQueued = () => {
|
||||
if (randomize.value) {
|
||||
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);
|
||||
var v = seedControl.value;
|
||||
|
||||
switch (v) {
|
||||
case ("fixed seed"):
|
||||
console.log("Fixed Seed");
|
||||
break;
|
||||
case ("increment"):
|
||||
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));
|
||||
} else {
|
||||
targetWidget.value = Math.floor(Math.random() * 1125899906842624);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
console.log("default (fail)");
|
||||
}
|
||||
};
|
||||
return randomize;
|
||||
return seedControl;
|
||||
}
|
||||
|
||||
function seedWidget(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];
|
||||
return { widget: seed, randomize };
|
||||
seed.widget.linkedWidgets = [seedControl];
|
||||
return { widget: seed, seedControl };
|
||||
}
|
||||
|
||||
const MultilineSymbol = Symbol();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user