From c50785a27b20dc80b93dd00ce979feb6d9a69c89 Mon Sep 17 00:00:00 2001 From: Wynd Date: Sun, 29 Jun 2025 14:03:58 +0300 Subject: [PATCH] Added a KH1 Synth table --- public/scripts/kh1.js | 65 ++++++++++++++++++++++++++++++ src/bbs.rs | 2 +- src/ddd.rs | 2 +- src/kh1.rs | 14 ++++++- src/kh2.rs | 2 +- src/kh3.rs | 2 +- src/main.rs | 4 +- templates/components/kh1/style.css | 62 ++++++++++++++++++++++++++++ templates/pages/index.html | 1 + templates/pages/kh1/synth.html | 45 +++++++++++++++++++++ 10 files changed, 191 insertions(+), 8 deletions(-) create mode 100644 templates/components/kh1/style.css create mode 100644 templates/pages/kh1/synth.html diff --git a/public/scripts/kh1.js b/public/scripts/kh1.js index df5e1f4..1b19ad9 100644 --- a/public/scripts/kh1.js +++ b/public/scripts/kh1.js @@ -4,4 +4,69 @@ import { track, } from "./modules/common/mat-kind-filter.js"; +document.addEventListener("DOMContentLoaded", (event) => { + const recipes = document.querySelectorAll(".recipe"); + + for (const recipe of recipes) { + recipe.checked = + localStorage.getItem("kh1-synth-" + recipe.id) === "true" ?? false; + update_synth_completions(recipe); + + recipe.addEventListener("input", function () { + localStorage.setItem("kh1-synth-" + this.id, this.checked); + update_synth_completions(this); + calc_total_ingredients(); + }); + } + + calc_total_ingredients(); +}); + +function update_synth_completions(recipe) { + if (recipe.checked) { + recipe.parentElement.classList.add("complete"); + } else { + recipe.parentElement.classList.remove("complete"); + } +} + +function calc_total_ingredients() { + const needed = new Map(); + const recipes = document.querySelectorAll(".recipe"); + + for (const recipe of recipes) { + const isComplete = recipe.checked; + if (isComplete) { + continue; + } + + const ingredients = + recipe.parentElement.querySelectorAll("label ul li"); + for (const ingredient of ingredients) { + let name = ingredient.dataset["synthItemName"]; + let amount = Number(ingredient.dataset["synthItemAmount"]); + + if (needed.has(name)) { + let new_amount = Number(needed.get(name)) + amount; + needed.set(name, new_amount); + } else { + needed.set(name, amount); + } + } + } + + const sortedMap = new Map([...needed].sort((a, b) => b[1] - a[1])); + + // generating the new list with materials needed + const matsList = document.getElementById("mats"); + matsList.innerHTML = "

Materials Needed

"; + const uiList = document.createElement("ul"); + for (const entry of sortedMap) { + const liElem = document.createElement("li"); + liElem.innerHTML = entry[0] + " x" + entry[1]; + uiList.appendChild(liElem); + } + matsList.appendChild(uiList); +} + Object.assign(window, { track }); diff --git a/src/bbs.rs b/src/bbs.rs index 84929f2..3a85a58 100644 --- a/src/bbs.rs +++ b/src/bbs.rs @@ -71,7 +71,7 @@ impl RuntimeModule for Module { tracing::info!("Generating the BBS melding table template"); let melding_template = CommandsTemplate { commands, crystals }; - create_file("./out/bbs", "melding", melding_template.render().unwrap()).unwrap(); + create_file("./out/bbs", "melding", melding_template).unwrap(); } fn get_js_hash() -> String { diff --git a/src/ddd.rs b/src/ddd.rs index a7fd84d..6cc8eae 100644 --- a/src/ddd.rs +++ b/src/ddd.rs @@ -55,7 +55,7 @@ impl RuntimeModule for Module { tracing::info!("Generating the DDD ability boards template"); let boards_template = AbilitiesTemplate { boards }; - create_file("./out/ddd", "boards", boards_template.render().unwrap()).unwrap(); + create_file("./out/ddd", "boards", boards_template).unwrap(); } fn get_js_hash() -> String { diff --git a/src/kh1.rs b/src/kh1.rs index f3ad7a4..85f418d 100644 --- a/src/kh1.rs +++ b/src/kh1.rs @@ -22,6 +22,12 @@ struct DropsTemplate { pub material_kinds: Vec, } +#[derive(Template)] +#[template(path = "pages/kh1/synth.html")] +struct SynthTemplate { + pub data: SynthesisData, +} + pub struct Module; impl RuntimeModule for Module { @@ -38,7 +44,6 @@ impl RuntimeModule for Module { tracing::info!("Loading synthesis data from {}", SYNTHESIS_PATH); let synth = SynthesisData::new(SYNTHESIS_PATH); - dbg!(synth.total_amounts()); tracing::info!("Generating the KH1 drops template"); let drops_template = DropsTemplate { @@ -47,7 +52,12 @@ impl RuntimeModule for Module { material_kinds, }; - create_file("./out/kh1", "drops", drops_template.render().unwrap()).unwrap(); + create_file("./out/kh1", "drops", drops_template).unwrap(); + + tracing::info!("Generating the KH1 synth template"); + let synth_template = SynthTemplate { data: synth }; + + create_file("./out/kh1", "synth", synth_template).unwrap(); } fn get_js_hash() -> String { diff --git a/src/kh2.rs b/src/kh2.rs index 723e3c3..b62bacd 100644 --- a/src/kh2.rs +++ b/src/kh2.rs @@ -42,7 +42,7 @@ impl RuntimeModule for Module { material_kinds, }; - create_file("./out/kh2", "drops", drops_template.render().unwrap()).unwrap(); + create_file("./out/kh2", "drops", drops_template).unwrap(); } fn get_js_hash() -> String { diff --git a/src/kh3.rs b/src/kh3.rs index 7e319d4..e4c5de1 100644 --- a/src/kh3.rs +++ b/src/kh3.rs @@ -28,7 +28,7 @@ impl RuntimeModule for Module { tracing::info!("Generating the KH3 recipes template"); let food_template = RecipesTemplate { recipes }; - create_file("./out/kh3", "food-sim", food_template.render().unwrap()).unwrap(); + create_file("./out/kh3", "food-sim", food_template).unwrap(); } fn get_js_hash() -> String { diff --git a/src/main.rs b/src/main.rs index 58daabb..605d0c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -103,8 +103,8 @@ fn hash_file(path: PathBuf, hasher: &mut Hasher) { } } -fn create_file(dir: &str, file: &str, buf: String) -> std::io::Result<()> { +fn create_file(dir: &str, file: &str, buf: impl Template) -> std::io::Result<()> { std::fs::create_dir_all(dir)?; - std::fs::write(format!("{}/{}.html", dir, file), buf)?; + std::fs::write(format!("{}/{}.html", dir, file), buf.render().unwrap())?; Ok(()) } diff --git a/templates/components/kh1/style.css b/templates/components/kh1/style.css new file mode 100644 index 0000000..61932ca --- /dev/null +++ b/templates/components/kh1/style.css @@ -0,0 +1,62 @@ +#mats { + position: fixed; + width: 20%; + height: 100%; + + h1 { + margin: 0; + font-size: 24px; + text-align: center; + } + + ul { + display: flex; + flex-direction: column; + flex-wrap: wrap; + height: 90%; + list-style: none; + line-height: 2; + } +} + +#recipes { + display: flex; + width: calc(80% - 20px); + flex-wrap: wrap; + margin: 20px 10px; + user-select: none; + margin-left: auto; + margin-right: 0; + + .recipe-wrapper { + cursor: pointer; + padding: 10px 20px 10px 10px; + + input[type="checkbox"] { + display: none; + } + + label { + display: inline-block; + width: 100%; + height: 100%; + cursor: pointer; + } + + img { + vertical-align: middle; + } + + &:hover { + box-shadow: 0px 0px 20px 0px limegreen; + scale: 1.1; + } + + &.complete { + color: limegreen; + > * { + text-decoration: line-through; + } + } + } +} diff --git a/templates/pages/index.html b/templates/pages/index.html index 06fc051..f54cd21 100644 --- a/templates/pages/index.html +++ b/templates/pages/index.html @@ -38,6 +38,7 @@

Kingdom Hearts I

{% endif %} {% endblock %} diff --git a/templates/pages/kh1/synth.html b/templates/pages/kh1/synth.html new file mode 100644 index 0000000..18e11c8 --- /dev/null +++ b/templates/pages/kh1/synth.html @@ -0,0 +1,45 @@ +{% extends "layouts/base.html" %} +{% import "macros/common/macros.html" as macros %} + +{% block title %}KH1 - Sythensis{% endblock %} + +{% block head %} + + +{% endblock %} + +{% block content %} +
+
+ {% for recipe in data.recipes %} +
+ + +
+ {% endfor %} +
+{% endblock %}