Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SafeguardInputs() cleaner #119

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
58 changes: 50 additions & 8 deletions style_editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@
input[type="button"]:active {
background-color: dodgerblue;
}
/*Keep from browser takeover of number inputs */
input[type='number'] {
width: 60px;
height: 22px;
}
input[type='number']::-webkit-inner-spin-button,
input[type='number']::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
input[type='number'] {
-moz-appearance: textfield;
}
button.submit-button {
background-color: limegreen;
border: 1px solid green;
Expand Down Expand Up @@ -1239,6 +1252,19 @@
</script>

<script>

function SafeguardInputs(e) {
if (e.target.value == "") {
console.log("SafeguardInputs() run to avoid null value");
var changeEvent = new Event('change');
e.target.value = 0;
if (e.target.id === "VARIANT_VALUE") {
FIND("VARIANT_SLIDER").value = 0;
}
e.target.dispatchEvent(changeEvent);
}
}

var gl = null;
var shaderProgram = null;
var t = 0.0;
Expand Down Expand Up @@ -1269,7 +1295,7 @@

// Add arg string.
var A = "";
A += "Arg string: <input id=ARGSTR name=arg type=input size=80 value='builtin 0 1' onchange='ArgStringChanged()' /><br><table>";
A += "Arg string: <input id=ARGSTR name=arg type=text size=80 value='builtin 0 1' onchange='ArgStringChanged()' /><br><table>";
var v = Object.keys(ArgumentName_ENUM_BUILDER.value_to_name);
for (var i = 0; i < v.length; i++) {
var V = parseInt(v[i]);
Expand All @@ -1279,7 +1305,7 @@
A += "<input type=color id=ARGSTR_"+N+" onclick='ClickArgColor("+N+")' onchange='ClickArgColor("+N+")' >";
} else {
A += "<input type=button value='<' onclick='IncreaseArg("+N+",-1)' >";
A += "<input id=ARGSTR_"+N+" type=input size=6 value=0 onchange='ArgChanged("+N+")' >";
A += "<input id=ARGSTR_"+N+" type='number' size=6 value=0 onchange='ArgChanged("+N+")' onfocusout='SafeguardInputs(event)' >";
A += "<input type=button value='>' onclick='IncreaseArg("+N+",1)' >";
}
A += "</td></tr>\n";
Expand Down Expand Up @@ -7615,12 +7641,15 @@
console.log("SYNC FIRST");
FIND("ALT").value = VAR;
} else if (VAR != this.last_) {
console.log("SYNC ALT");
if (isNaN(VAR)) VAR = 0;
console.log("SYNC ALT: " + VAR);
FIND("ALT").value = VAR;
blade.addEffect(EFFECT_ALT_SOUND, 0.0);
} else {
console.log("SYNC VAR");
VAR = Alt();
if (isNaN(VAR)) VAR = 0;
console.log("SYNC VAR: " + VAR);
FIND("VARIANT_VALUE").value = VAR;
}
this.last_ = VAR;
Expand Down Expand Up @@ -9446,13 +9475,15 @@
var N = ArgumentName_ENUM_BUILDER.value_to_name[ARG];
var tag = FIND("ARGSTR_"+N);
setARG(ARG, tag.value);
console.log("Updated " + N + " : " + tag.value)
}

function IncreaseArg(ARG, I) {
var N = ArgumentName_ENUM_BUILDER.value_to_name[ARG];
var tag = FIND("ARGSTR_"+N);
tag.value = parseInt(tag.value) + I;
setARG(ARG, tag.value);
console.log("Updated " + N + " : " + tag.value)
}

function ClickArgColor(ARG) {
Expand Down Expand Up @@ -9585,11 +9616,20 @@
return parseInt(FIND("ALT").value);
}

function updateAltValue(newValue) {
if (newValue > num_alternatives) {
newValue = num_alternatives;
}
FIND("ALT").value = newValue;
console.log("Updated Alt: " + newValue);
}

function IncreaseAlt(n) {
var v = Alt() + n;
if (v < 0) v += num_alternatives;
if (v > num_alternatives) v -= num_alternatives;
FIND("ALT").value = v;
console.log("Updated Alt: " + v)
}

function Variant() {
Expand Down Expand Up @@ -9958,10 +9998,10 @@
onmouseup="stopAdjustingValue()"
onmouseleave="stopAdjustingValue()" >
<input
id="VARIANT_VALUE" name=varvalue type=input size="6" value="0"
id="VARIANT_VALUE" name=varvalue type='number' value="0"
title="The current Variant value. You can also type in this field for direct entry of a value."
oninput="updateVariantValue(this.value)" >
<input
oninput="updateVariantValue(this.value)"
onfocusout="SafeguardInputs(event)" > <input
id="VARIANT_PLUS" name=varplus type=button value=">"
title="Increases the Variant value. Hold to increase speed of the changing value."
onmousedown="startAdjustingValue(1, 'VARIANT_SLIDER')"
Expand All @@ -9973,8 +10013,10 @@
title="Decreases the Alt value."
onclick="IncreaseAlt(-1)" >
<input
id="ALT" name=alt type=input size="3" value="0"
title="The current Alt value. You can also type in this field for direct entry of a value." >
id="ALT" name=alt type='number' value="0"
title="The current Alt value. You can also type in this field for direct entry of a value."
oninput="updateAltValue(this.value)"
onfocusout="SafeguardInputs(event)" >
<input
id="ALT_PLUS" name=altplus type=button value=">"
title="Increases the Alt value."
Expand Down