Add powder input error detection
This commit is contained in:
parent
60376aa9c5
commit
e47673ef17
1 changed files with 16 additions and 2 deletions
|
@ -445,7 +445,6 @@ class PowderInputNode extends InputNode {
|
|||
|
||||
compute_func(input_map) {
|
||||
// TODO: haha improve efficiency to O(n) dumb
|
||||
// also, error handling is missing
|
||||
let input = this.input_field.value.trim();
|
||||
let powdering = [];
|
||||
let errorederrors = [];
|
||||
|
@ -453,12 +452,27 @@ class PowderInputNode extends InputNode {
|
|||
let first = input.slice(0, 2);
|
||||
let powder = powderIDs.get(first);
|
||||
if (powder === undefined) {
|
||||
return null;
|
||||
if (first.length > 0)
|
||||
errorederrors.push(first);
|
||||
else
|
||||
break;
|
||||
} else {
|
||||
powdering.push(powder);
|
||||
}
|
||||
input = input.slice(2);
|
||||
}
|
||||
|
||||
if (this.input_field.getAttribute("placeholder") != null) {
|
||||
let placeholder = this.input_field.getAttribute("placeholder");
|
||||
if (placeholder.includes(" slots") && parseInt(placeholder[0]) < powdering.length)
|
||||
errorederrors.push("Too many powders: " + powdering.length);
|
||||
}
|
||||
|
||||
if (errorederrors.length)
|
||||
this.input_field.classList.add("is-invalid");
|
||||
else
|
||||
this.input_field.classList.remove("is-invalid");
|
||||
|
||||
return powdering;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue