diff --git a/public/scripts/kh1/synth.js b/public/scripts/kh1/synth.js index 9574c50..696f853 100644 --- a/public/scripts/kh1/synth.js +++ b/public/scripts/kh1/synth.js @@ -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); }