Commit 13d94caf authored by comfyanonymous's avatar comfyanonymous
Browse files

Add control_after_generate to combo primitive.

parent 5f7968f1
...@@ -300,7 +300,7 @@ app.registerExtension({ ...@@ -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");
} }
......
...@@ -19,6 +19,31 @@ export function addValueControlWidget(node, targetWidget, defaultValue = "random ...@@ -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 ...@@ -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;
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment