Add control_after_generate to combo primitive.

This commit is contained in:
comfyanonymous 2023-05-16 03:18:11 -04:00
parent 5f7968f1fa
commit 13d94caf49
2 changed files with 54 additions and 28 deletions

View File

@ -300,7 +300,7 @@ app.registerExtension({
} }
} }
if (widget.type === "number") { if (widget.type === "number" || widget.type === "combo") {
addValueControlWidget(this, widget, "fixed"); addValueControlWidget(this, widget, "fixed");
} }

View File

@ -19,35 +19,61 @@ export function addValueControlWidget(node, targetWidget, defaultValue = "random
var v = valueControl.value; var v = valueControl.value;
let min = targetWidget.options.min; console.log(targetWidget);
let max = targetWidget.options.max; if (targetWidget.type == "combo" && v !== "fixed") {
// limit to something that javascript can handle let current_index = targetWidget.options.values.indexOf(targetWidget.value);
max = Math.min(1125899906842624, max); let current_length = targetWidget.options.values.length;
min = Math.max(-1125899906842624, min);
let range = (max - min) / (targetWidget.options.step / 10);
//adjust values based on valueControl Behaviour switch (v) {
switch (v) { case "increment":
case "fixed": current_index += 1;
break; break;
case "increment": case "decrement":
targetWidget.value += targetWidget.options.step / 10; current_index -= 1;
break; break;
case "decrement": case "randomize":
targetWidget.value -= targetWidget.options.step / 10; current_index = Math.floor(Math.random() * current_length);
break; default:
case "randomize": break;
targetWidget.value = Math.floor(Math.random() * range) * (targetWidget.options.step / 10) + min; }
default: current_index = Math.max(0, current_index);
break; current_index = Math.min(current_length - 1, current_index);
if (current_index >= 0) {
let value = targetWidget.options.values[current_index];
targetWidget.value = value;
targetWidget.callback(value);
}
} else { //number
let min = targetWidget.options.min;
let max = targetWidget.options.max;
// limit to something that javascript can handle
max = Math.min(1125899906842624, max);
min = Math.max(-1125899906842624, min);
let range = (max - min) / (targetWidget.options.step / 10);
//adjust values based on valueControl Behaviour
switch (v) {
case "fixed":
break;
case "increment":
targetWidget.value += targetWidget.options.step / 10;
break;
case "decrement":
targetWidget.value -= targetWidget.options.step / 10;
break;
case "randomize":
targetWidget.value = Math.floor(Math.random() * range) * (targetWidget.options.step / 10) + min;
default:
break;
}
/*check if values are over or under their respective
* ranges and set them to min or max.*/
if (targetWidget.value < min)
targetWidget.value = min;
if (targetWidget.value > max)
targetWidget.value = max;
} }
/*check if values are over or under their respective
* ranges and set them to min or max.*/
if (targetWidget.value < min)
targetWidget.value = min;
if (targetWidget.value > max)
targetWidget.value = max;
} }
return valueControl; return valueControl;
}; };