Fixed the synth list for needed mats not being consistent and having empty elements

master
Wynd 2025-07-01 14:47:08 +03:00
parent 3e2b73d130
commit c3304099bd
1 changed files with 13 additions and 3 deletions

View File

@ -11,6 +11,7 @@ document.addEventListener("DOMContentLoaded", (event) => {
updateSynthRecipeState(recipe);
recipe.addEventListener("input", function () {
// Change the recipe's state and update and needed materials list based on the remaining recipes
localStorage.setItem("kh1-synth-" + this.id, this.checked);
updateSynthRecipeState(this);
calcNeededMats();
@ -24,9 +25,17 @@ document.addEventListener("DOMContentLoaded", (event) => {
});
}
markedNeededMaterials = Array(
localStorage.getItem("kh1-synth-needed-mats") ?? [],
);
// Turn the single saved string into an array with each material
if (localStorage.getItem("kh1-synth-needed-mats") != null) {
let saved = localStorage.getItem("kh1-synth-needed-mats");
saved = saved.split(",");
markedNeededMaterials = saved;
markedNeededMaterials = markedNeededMaterials.filter(
(n) => n && n !== "",
);
} else {
markedNeededMaterials = new Array();
}
calcNeededMats();
});
@ -118,6 +127,7 @@ function updateMarkedNeededMats(ingredient) {
} else {
markedNeededMaterials.push(ingredient);
}
markedNeededMaterials = markedNeededMaterials.filter((n) => n && n !== "");
localStorage.setItem("kh1-synth-needed-mats", markedNeededMaterials);
}