diff --git a/web/scripts/widgets.js b/web/scripts/widgets.js index a38f89f28..5868e9d4a 100644 --- a/web/scripts/widgets.js +++ b/web/scripts/widgets.js @@ -18,37 +18,29 @@ export function addValueControlWidget(node, targetWidget, defaultValue = "random valueControl.afterQueued = () => { var v = valueControl.value; - var w = targetWidget.type; let min = targetWidget.options?.min; let max = targetWidget.options?.max; let range = Math.max(min, max); //adjust values based on valueControl Behaviour - switch (v) { + if (min != null && max != null) { + switch (v) { case "fixed": break; case "increment": - if (min != null && max != null) { - if (max) { - targetWidget.value += targetWidget.options?.increment; - } - } + targetWidget.value += targetWidget.options.step / 10; break; case "decrement": - if (min != null && max != null) { - if (max) { - targetWidget.value -= targetWidget.options?.increment; - } - } + targetWidget.value -= targetWidget.options.step / 10; break; case "randomize": - if (min != null && max != null) { - switch (w) { - case "FLOAT": + var w = targetWidget.type; + switch (w) { + case FLOAT: targetWidget.value = parseFloat((Math.floor(Math.random() * ((range * 100) + 1)) / 100).toFixed(2)); break; - case "INT": + case INT: if (targetWidget.name == "width" || targetWidget.name == "height") { targetWidget.value = Math.floor(Math.random() * range) * 64 + min; } else { @@ -58,11 +50,11 @@ export function addValueControlWidget(node, targetWidget, defaultValue = "random default: break; } - } break; default: break; } + } /*check if values are over or under their respective * ranges and set them to min or max.*/ if (targetWidget.value < min)