From a1319396b642b17ce82214e18db04540d9f67422 Mon Sep 17 00:00:00 2001 From: Wynd Date: Sat, 25 Oct 2025 00:06:31 +0300 Subject: [PATCH] Saving and loading tracked drops --- input/kh3/enemies/helmed-body.toml | 1 + public/scripts/common/mat-kind-filter.js | 53 +++++++++++++++++++++++- public/scripts/kh1/synth.js | 4 +- public/scripts/kh3/food-sim.js | 2 - 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/input/kh3/enemies/helmed-body.toml b/input/kh3/enemies/helmed-body.toml index 296c58d..cc584ab 100644 --- a/input/kh3/enemies/helmed-body.toml +++ b/input/kh3/enemies/helmed-body.toml @@ -5,6 +5,7 @@ name = "Arendelle" [[world]] name = "San Fransokyo" +rooms = ["Battlegate 11"] [[drops]] name = "Writhing Gem" diff --git a/public/scripts/common/mat-kind-filter.js b/public/scripts/common/mat-kind-filter.js index 00f9026..ed180e9 100644 --- a/public/scripts/common/mat-kind-filter.js +++ b/public/scripts/common/mat-kind-filter.js @@ -1,7 +1,19 @@ +const TRACKED_STORAGE_NAME = "/drops/tracked/"; + +let gameName; + export let showOnlyTracked = false; export let kindFilter = new Set(); export function init() { + const url = window.location.href; + const firstPoint = url.indexOf("/", 8); + const subUrl = url.substring(firstPoint + 1); + const finalPoint = subUrl.indexOf("/"); + gameName = subUrl.substring(0, finalPoint); + + loadTracked(); + const onlyTrackedFilter = document.querySelector( 'input[name="onlyTracked"]', ); @@ -49,12 +61,49 @@ function filter() { } } +function loadTracked() { + const categories = document.querySelectorAll(".category-wrapper"); + let updates = 0; + + for (const category of categories) { + let id = + category.dataset["matKind"] + "-" + category.dataset["matType"]; + id = gameName + TRACKED_STORAGE_NAME + id; + + let isTracked = localStorage.getItem(id) === "true"; + if (isTracked) { + category.dataset["isTracked"] = true; + let trackButton = category.querySelector(".category button"); + updateTrackedState(trackButton, isTracked); + updates += 1; + } + } + + if (updates > 0) { + filter(); + } +} + export function track(element) { let parent = element.parentElement.parentElement; + let id = parent.dataset["matKind"] + "-" + parent.dataset["matType"]; + id = gameName + TRACKED_STORAGE_NAME + id; + let isTracked = parent.dataset["isTracked"] ?? false; isTracked = isTracked === "true" ? false : true; + + if (isTracked) { + localStorage.setItem(id, true); + } else { + localStorage.removeItem(id); + } + parent.dataset["isTracked"] = isTracked; - element.innerHTML = isTracked ? "Stop tracking" : "Start tracking"; - element.style["border-bottom-color"] = isTracked ? "#a00" : "#0a0"; + updateTrackedState(element, isTracked); filter(); } + +function updateTrackedState(element, isTracked) { + element.innerHTML = isTracked ? "Stop tracking" : "Start tracking"; + element.style["border-bottom-color"] = isTracked ? "#a00" : "#0a0"; +} diff --git a/public/scripts/kh1/synth.js b/public/scripts/kh1/synth.js index 794c836..6f5e1ee 100644 --- a/public/scripts/kh1/synth.js +++ b/public/scripts/kh1/synth.js @@ -1,7 +1,7 @@ import "../common/prototypes.js"; -const RECIPE_STORAGE_NAME = "kh1/synth/recipe."; -const LIST_STORAGE_NAME = "kh1/synth/needed-maths"; +const RECIPE_STORAGE_NAME = "kh1/synth/"; +const LIST_STORAGE_NAME = "kh1/synth/needed-mats"; let markedNeededMaterials = []; diff --git a/public/scripts/kh3/food-sim.js b/public/scripts/kh3/food-sim.js index bec4fab..37b6eec 100644 --- a/public/scripts/kh3/food-sim.js +++ b/public/scripts/kh3/food-sim.js @@ -107,8 +107,6 @@ function selectRecipe(item, index) { } let recipeName = item.querySelector(".title").innerText; - console.log(item); - console.log(item.querySelectorAll(".title")); localStorage.setItem(STORAGE_NAME + index, recipeName); let stats = JSON.parse(item.dataset["stats"]);