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,6 +19,31 @@ export function addValueControlWidget(node, targetWidget, defaultValue = "random
var v = valueControl.value; var v = valueControl.value;
console.log(targetWidget);
if (targetWidget.type == "combo" && v !== "fixed") {
let current_index = targetWidget.options.values.indexOf(targetWidget.value);
let current_length = targetWidget.options.values.length;
switch (v) {
case "increment":
current_index += 1;
break;
case "decrement":
current_index -= 1;
break;
case "randomize":
current_index = Math.floor(Math.random() * current_length);
default:
break;
}
current_index = Math.max(0, current_index);
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 min = targetWidget.options.min;
let max = targetWidget.options.max; let max = targetWidget.options.max;
// limit to something that javascript can handle // limit to something that javascript can handle
@ -49,6 +74,7 @@ export function addValueControlWidget(node, targetWidget, defaultValue = "random
if (targetWidget.value > max) if (targetWidget.value > max)
targetWidget.value = max; targetWidget.value = max;
} }
}
return valueControl; return valueControl;
}; };