Allow to run workflows with parameter nodes
- fix validation error due to missing min/max - fix errors due to numbers being passed as string
This commit is contained in:
@@ -94,6 +94,11 @@ function valueMatchesType(value, type, options) {
|
||||
return typeof value === "string"
|
||||
}
|
||||
|
||||
function optionalWidgetValue(widgets, index, fallback) {
|
||||
const result = widgets.length > index ? widgets[index].value : null
|
||||
return result === null || result === 0 ? fallback : result
|
||||
}
|
||||
|
||||
function changeWidgets(node, type, connectedNode, connectedWidget) {
|
||||
if (type === "customtext") {
|
||||
type = "text"
|
||||
@@ -110,8 +115,8 @@ function changeWidgets(node, type, connectedNode, connectedWidget) {
|
||||
node.widgets[1].value = defaultParameterType(type, connectedNode, connectedWidget)
|
||||
}
|
||||
const oldDefault = node.widgets.length > 2 ? node.widgets[2].value : connectedWidget.value
|
||||
const oldMin = node.widgets.length > 3 ? node.widgets[3].value : (options?.min ?? 0)
|
||||
const oldMax = node.widgets.length > 4 ? node.widgets[4].value : (options?.max ?? 100)
|
||||
const oldMin = optionalWidgetValue(node.widgets, 3, options?.min ?? 0)
|
||||
const oldMax = optionalWidgetValue(node.widgets, 4, options?.max ?? 100)
|
||||
const isDefaultValid = valueMatchesType(oldDefault, type, connectedWidget.options)
|
||||
while (node.widgets.length > 2) {
|
||||
node.widgets.pop()
|
||||
|
||||
@@ -204,9 +204,11 @@ class Parameter:
|
||||
"name": ("STRING", {"default": "Parameter"}),
|
||||
"type": (_param_types, {"default": "auto"}),
|
||||
"default": ("STRING", {"default": ""}),
|
||||
},
|
||||
"optional": {
|
||||
"min": ("FLOAT", _any_float),
|
||||
"max": ("FLOAT", _any_float),
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = (BasicTypes,)
|
||||
@@ -214,7 +216,11 @@ class Parameter:
|
||||
FUNCTION = "placeholder"
|
||||
CATEGORY = "krita"
|
||||
|
||||
def placeholder(self, name: str, type: str, default, min, max):
|
||||
def placeholder(self, name: str, type: str, default, min=0.0, max=1.0):
|
||||
if type == "number":
|
||||
return (float(default),)
|
||||
elif type == "number (integer)":
|
||||
return (int(default),)
|
||||
return (default,)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user