diff --git a/sup/util.py b/sup/util.py index 3ee1d79..f3773d0 100644 --- a/sup/util.py +++ b/sup/util.py @@ -125,7 +125,9 @@ def parse_value(val:Any, typ:EnumConvertType, default: Any, ret = False if isinstance(new_val, (torch.Tensor,)): ret = True - elif (nv := new_val[0]) is not None: + elif isinstance(new_val, (dict,)): + ret = len(new_val.keys()) > 0 + elif len(new_val) > 0 and (nv := new_val[0]) is not None: if isinstance(nv, (bool, str,)): ret = bool(nv) elif isinstance(nv, (int, float,)): diff --git a/web/nodes/calc_binary.js b/web/nodes/calc_binary.js index cdd792f..773acd1 100644 --- a/web/nodes/calc_binary.js +++ b/web/nodes/calc_binary.js @@ -33,6 +33,28 @@ function process_value(input, widget, precision=0, visible=false, typ="number", } } +function show_boolean(widget_x, in_x, visible_x, typ="toggle") { + if (!in_x && visible_x) { + widget_show(widget_x); + widget_x.origType = widget_x.type; + widget_x.type = typ; + } +} + +function show_vector(widget, precision=0) { + widget_show(widget); + widget.origType = widget.type; + if (precision == 0) { + widget.options.step = 1; + widget.options.round = 1; + widget.options.precision = 0; + } else { + widget.options.step = 1 / (10^Math.max(1, precision-2)); + widget.options.round = 1 / (10^Math.max(1, precision-1)); + widget.options.precision = precision; + } +} + app.registerExtension({ name: 'jovimetrix.node.' + _id, async beforeRegisterNodeDef(nodeType, nodeData, app) { @@ -40,31 +62,6 @@ app.registerExtension({ return; } - function show_boolean(widget_x, in_x, visible_x, typ="toggle") { - if (!in_x && visible_x) { - widget_show(widget_x); - widget_x.origType = widget_x.type; - widget_x.type = typ; - } - } - - function show_vector(widget, inputs, what, visible, precision=0) { - if (inputs.find(w => w.name === what) && visible) - { - widget_show(widget); - widget.origType = widget.type; - if (precision == 0) { - widget.options.step = 1; - widget.options.round = 0.1; - widget.options.precision = 0; - } else { - widget.options.step = 0.1; - widget.options.round = 0.01; - widget.options.precision = 4; - } - } - } - const onNodeCreated = nodeType.prototype.onNodeCreated nodeType.prototype.onNodeCreated = function () { const me = onNodeCreated?.apply(this) @@ -84,6 +81,14 @@ app.registerExtension({ const widget_yy = this.widgets.find(w => w.name === '🅱️2'); const widget_yyz = this.widgets.find(w => w.name === '🅱️3'); const widget_yyzw = this.widgets.find(w => w.name === '🅱️4'); + widget_x.options.forceInput = true; + widget_xy.options.forceInput = true; + widget_xyz.options.forceInput = true; + widget_xyzw.options.forceInput = true; + widget_y.options.forceInput = true; + widget_yy.options.forceInput = true; + widget_yyz.options.forceInput = true; + widget_yyzw.options.forceInput = true; // const visible_x = widget_a.link === null; const visible_y = widget_b.link === null; @@ -107,23 +112,23 @@ app.registerExtension({ process_value(in_x, widget_x, 0, visible_x, "number", "INT"); process_value(in_y, widget_y, 0, visible_y, "number", "INT"); } else if (combo.value == "VEC2INT") { - show_vector(widget_xy, this.inputs, '🇽🇾', visible_x, "number", "INT"); - show_vector(widget_yy, this.inputs, '🅱️2', visible_y, "number", "INT"); + show_vector(widget_xy); + show_vector(widget_yy); } else if (combo.value == "VEC2") { - show_vector(widget_xy, this.inputs, '🇽🇾', visible_x, 2, "number", "FLOAT"); - show_vector(widget_yy, this.inputs, '🅱️2', visible_y, 2, "number", "FLOAT"); + show_vector(widget_xy, 3); + show_vector(widget_yy, 3); } else if (combo.value == "VEC3INT") { - show_vector(widget_xyz, this.inputs, '🇽🇾\u200c🇿', visible_x, "number", "INT"); - show_vector(widget_yyz, this.inputs, '🅱️3', visible_y, "number", "INT"); + show_vector(widget_xyz); + show_vector(widget_yyz); } else if (combo.value == "VEC3") { - show_vector(widget_xyz, this.inputs, '🇽🇾\u200c🇿', visible_x, 2, "number", "FLOAT"); - show_vector(widget_yyz, this.inputs, '🅱️3', visible_y, 2, "number", "FLOAT"); + show_vector(widget_xyz, 3); + show_vector(widget_yyz, 3); } else if (combo.value == "VEC4INT") { - show_vector(widget_xyzw, this.inputs, '🇽🇾\u200c🇿\u200c🇼', visible_x, "number", "INT"); - show_vector(widget_yyzw, this.inputs, '🅱️4', visible_y, "number", "INT"); + show_vector(widget_xyzw); + show_vector(widget_yyzw); } else if (combo.value == "VEC4") { - show_vector(widget_xyzw, this.inputs, '🇽🇾\u200c🇿\u200c🇼', visible_x, 2, "number", "FLOAT"); - show_vector(widget_yyzw, this.inputs, '🅱️4', visible_y, 2, "number", "FLOAT"); + show_vector(widget_xyzw, 3); + show_vector(widget_yyzw, 3); } this.outputs[0].name = widget_type_name(combo.value); fitHeight(this); @@ -141,49 +146,6 @@ app.registerExtension({ } return onConnectionsChange?.apply(this, arguments); } - - // MENU CONVERSIONS - /* - const getExtraMenuOptions = nodeType.prototype.getExtraMenuOptions; - nodeType.prototype.getExtraMenuOptions = function (_, options) { - // const me = getExtraMenuOptions?.apply(this, arguments); - const combo = this.widgets.find(w => w.name === '❓'); - let toWidget = []; - let toInput = []; - for (const w of this.widgets) { - if (w.options?.forceInput) { - continue; - } - if (w.type === CONVERTED_JOV_TYPE && w.hidden) { - toWidget.push({ - content: `Convertz ${w.name} to widget`, - callback: () => { - convertToWidget(this, w) - setTimeout(() => { combo.callback(); }, 10); - }, - }); - } else { - const config = getConfig.call(this, w.name) ?? [w.type, w.options || {}]; - toInput.push({ - content: `Convertz ${w.name} to input`, - callback: () => { - convertToInput(this, w, config); - setTimeout(() => { combo.callback(); }, 10); - }, - }); - } - } - if (toInput.length) { - options.push(...toInput, null); - } - - if (toWidget.length) { - options.push(...toWidget, null); - } - // return me; - - }; - */ return nodeType; } }) diff --git a/web/nodes/workflow.js b/web/nodes/workflow.js index 4c79d4c..1f605fe 100644 --- a/web/nodes/workflow.js +++ b/web/nodes/workflow.js @@ -5,8 +5,6 @@ */ import { app } from "../../../scripts/app.js" -import { fitHeight } from '../util/util.js' -import { widget_hide, widget_show } from '../util/util_widget.js' const _id = "WORKFLOW (JOV) ➿" diff --git a/web/widget/widget_vector.js b/web/widget/widget_vector.js index 32eaf6a..fe3ad93 100644 --- a/web/widget/widget_vector.js +++ b/web/widget/widget_vector.js @@ -233,7 +233,8 @@ app.registerExtension({ const convertToInputArray = []; for (const w of matchingTypes) { const widget = Object.values(this.widgets).find(m => m.name === w[0]); - if (widget.type !== CONVERTED_TYPE && myTypes.includes(widget.type)) { + if (widget.type !== CONVERTED_TYPE && myTypes.includes(widget.type) && widget?.options?.forceInput === false) { + console.info(widget); const who = matchingTypes.find(w => w[0] === widget.name) const convertToInputObject = { content: `Convert ${widget.name} to input`,