Skip to content

Commit

Permalink
No conversion menu for default widgets
Browse files Browse the repository at this point in the history
specific value case for dict->bool
  • Loading branch information
Amorano committed Jun 2, 2024
1 parent 458051f commit 119451a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 84 deletions.
4 changes: 3 additions & 1 deletion sup/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,)):
Expand Down
122 changes: 42 additions & 80 deletions web/nodes/calc_binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,35 @@ 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) {
if (nodeData.name !== _id) {
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)
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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;
}
})
2 changes: 0 additions & 2 deletions web/nodes/workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) ➿"

Expand Down
3 changes: 2 additions & 1 deletion web/widget/widget_vector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down

0 comments on commit 119451a

Please sign in to comment.