diff --git a/js/external_tooling_nodes.js b/js/external_tooling_nodes.js index 0fd5573..66904a8 100644 --- a/js/external_tooling_nodes.js +++ b/js/external_tooling_nodes.js @@ -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() diff --git a/krita.py b/krita.py index 69f738b..93eecfb 100644 --- a/krita.py +++ b/krita.py @@ -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,)