From 1d1b3c02ddaeb5315fe9f4c2591b6b8526004abf Mon Sep 17 00:00:00 2001 From: Wynd Date: Sun, 13 Jul 2025 23:56:34 +0300 Subject: [PATCH] Some more organization and splits --- public/styles/common/base.css | 4 +++ public/styles/common/drops.css | 10 +++--- src/common.rs | 1 + src/common/drops.rs | 45 ++++++++++++++++++++++++++ src/common/synthesis.rs | 8 ++--- src/kh1.rs | 24 ++++---------- src/kh2.rs | 20 +++--------- src/kh3.rs | 20 +++--------- templates/components/common/drops.html | 28 ++++++++-------- templates/macros/common/macros.html | 4 +-- 10 files changed, 88 insertions(+), 76 deletions(-) create mode 100644 src/common/drops.rs diff --git a/public/styles/common/base.css b/public/styles/common/base.css index d96b481..e4eb943 100644 --- a/public/styles/common/base.css +++ b/public/styles/common/base.css @@ -84,6 +84,10 @@ input[type="checkbox"] { height: 24px; padding-top: 8px; + & + label { + cursor: pointer; + } + &::before { position: absolute; width: 100%; diff --git a/public/styles/common/drops.css b/public/styles/common/drops.css index 60cd18b..3b752ca 100644 --- a/public/styles/common/drops.css +++ b/public/styles/common/drops.css @@ -89,11 +89,11 @@ .material-filters { display: flex; flex-wrap: wrap; - width: 25%; + width: 40%; row-gap: 20px; position: relative; - - div { - flex-basis: 25%; - } +} + +.tracked-filter { + margin-bottom: 16px; } diff --git a/src/common.rs b/src/common.rs index 1c17718..560932c 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1,6 +1,7 @@ use serde::Deserialize; pub mod direction; +pub mod drops; pub mod enemy; pub mod materials; pub mod synthesis; diff --git a/src/common/drops.rs b/src/common/drops.rs new file mode 100644 index 0000000..ed4de3d --- /dev/null +++ b/src/common/drops.rs @@ -0,0 +1,45 @@ +use itertools::Itertools; + +use super::{Game, enemy::Enemy, materials::MaterialDrops}; + +#[derive(Debug, PartialEq, Eq)] +pub struct Drops { + pub game: Game, + pub drops: Vec, + pub material_kinds: Vec, + + filter_max_len: usize, +} + +impl Drops { + pub fn new(game: Game, enemies: Vec) -> Self { + let drops = MaterialDrops::new(enemies); + + let material_kinds = drops + .iter() + .map(|d| d.category.get_category(&Game::Kh1)) + .dedup() + .collect::>(); + + let mut filter_max_len: usize = 0; + for kind in &material_kinds { + if kind.len() > filter_max_len { + filter_max_len = kind.len(); + } + } + filter_max_len *= 10; + filter_max_len += 60; + + Self { + game, + drops, + material_kinds, + + filter_max_len, + } + } + + pub fn get_filter_len(&self) -> usize { + self.filter_max_len + } +} diff --git a/src/common/synthesis.rs b/src/common/synthesis.rs index ede1903..f8bbd15 100644 --- a/src/common/synthesis.rs +++ b/src/common/synthesis.rs @@ -3,15 +3,15 @@ use std::collections::HashMap; use serde::Deserialize; #[derive(Debug, Default, Clone, Deserialize, PartialEq, Eq)] -pub struct SynthesisData { +pub struct Synthesis { pub sets: Vec, pub recipes: Vec, } -impl SynthesisData { - pub fn new(path: &str) -> SynthesisData { +impl Synthesis { + pub fn new(path: &str) -> Synthesis { let str = std::fs::read_to_string(path).unwrap(); - let mut data = toml::from_str::(&str).unwrap(); + let mut data = toml::from_str::(&str).unwrap(); for recipe in &mut data.recipes { for set in &data.sets { diff --git a/src/kh1.rs b/src/kh1.rs index 20d2fc9..3ce4568 100644 --- a/src/kh1.rs +++ b/src/kh1.rs @@ -1,9 +1,8 @@ use askama::Template; -use itertools::Itertools; use crate::{ RuntimeModule, - common::{Game, enemy::Enemy, materials::MaterialDrops, synthesis::SynthesisData}, + common::{Game, drops::Drops, enemy::Enemy, synthesis::Synthesis}, create_file, }; @@ -13,15 +12,13 @@ const SYNTHESIS_PATH: &str = "./input/kh1/synthesis.toml"; #[derive(Template)] #[template(path = "pages/kh1/drops.html")] struct DropsTemplate { - pub game: Game, - pub drops: Vec, - pub material_kinds: Vec, + pub data: Drops, } #[derive(Template)] #[template(path = "pages/kh1/synth.html")] struct SynthTemplate { - pub data: SynthesisData, + pub data: Synthesis, } pub struct Module; @@ -31,22 +28,13 @@ impl RuntimeModule for Module { tracing::info!("Loading enemy data from {}", ENEMIES_PATH); let enemies = Enemy::import(ENEMIES_PATH); - let drops = MaterialDrops::new(enemies); - let material_kinds = drops - .iter() - .map(|d| d.category.get_category(&Game::Kh1)) - .dedup() - .collect(); + let drops = Drops::new(Game::Kh1, enemies); tracing::info!("Loading synthesis data from {}", SYNTHESIS_PATH); - let synth = SynthesisData::new(SYNTHESIS_PATH); + let synth = Synthesis::new(SYNTHESIS_PATH); tracing::info!("Generating the KH1 drops template"); - let drops_template = DropsTemplate { - game: Game::Kh1, - drops, - material_kinds, - }; + let drops_template = DropsTemplate { data: drops }; create_file("./out/kh1", "drops", drops_template).unwrap(); diff --git a/src/kh2.rs b/src/kh2.rs index 97bf219..1e764df 100644 --- a/src/kh2.rs +++ b/src/kh2.rs @@ -1,9 +1,8 @@ use askama::Template; -use itertools::Itertools; use crate::{ RuntimeModule, - common::{Game, enemy::Enemy, materials::MaterialDrops}, + common::{Game, drops::Drops, enemy::Enemy}, create_file, }; @@ -12,9 +11,7 @@ const ENEMIES_PATH: &str = "./input/kh2/enemies"; #[derive(Template)] #[template(path = "pages/kh2/drops.html")] struct DropsTemplate { - pub game: Game, - pub drops: Vec, - pub material_kinds: Vec, + pub data: Drops, } pub struct Module; @@ -24,19 +21,10 @@ impl RuntimeModule for Module { tracing::info!("Loading enemy data from {}", ENEMIES_PATH); let enemies = Enemy::import(ENEMIES_PATH); - let drops = MaterialDrops::new(enemies); - let material_kinds = drops - .iter() - .map(|d| d.category.get_category(&Game::Kh2)) - .dedup() - .collect(); + let drops = Drops::new(Game::Kh2, enemies); tracing::info!("Generating the KH2 drops template"); - let drops_template = DropsTemplate { - game: Game::Kh2, - drops, - material_kinds, - }; + let drops_template = DropsTemplate { data: drops }; create_file("./out/kh2", "drops", drops_template).unwrap(); } diff --git a/src/kh3.rs b/src/kh3.rs index ea7f77e..8016089 100644 --- a/src/kh3.rs +++ b/src/kh3.rs @@ -1,10 +1,9 @@ use askama::Template; use food::Recipes; -use itertools::Itertools; use crate::{ RuntimeModule, - common::{Game, enemy::Enemy, materials::MaterialDrops}, + common::{Game, drops::Drops, enemy::Enemy}, create_file, }; @@ -16,9 +15,7 @@ const RECIPES_PATH: &str = "./input/kh3/recipes.toml"; #[derive(Template)] #[template(path = "pages/kh3/drops.html")] struct DropsTemplate { - pub game: Game, - pub drops: Vec, - pub material_kinds: Vec, + pub data: Drops, } #[derive(Template)] @@ -34,23 +31,14 @@ impl RuntimeModule for Module { tracing::info!("Loading enemy data from {}", ENEMIES_PATH); let enemies = Enemy::import(ENEMIES_PATH); - let drops = MaterialDrops::new(enemies); - let material_kinds = drops - .iter() - .map(|d| d.category.get_category(&Game::Kh3)) - .dedup() - .collect(); + let drops = Drops::new(Game::Kh3, enemies); tracing::info!("Loading recipes data from {}", RECIPES_PATH); let recipes_str = std::fs::read_to_string(RECIPES_PATH).unwrap(); let recipes = toml::from_str::(&recipes_str).unwrap(); tracing::info!("Generating the KH3 drops template"); - let drops_template = DropsTemplate { - game: Game::Kh3, - drops, - material_kinds, - }; + let drops_template = DropsTemplate { data: drops }; create_file("./out/kh3", "drops", drops_template).unwrap(); diff --git a/templates/components/common/drops.html b/templates/components/common/drops.html index 37f75ca..c245b68 100644 --- a/templates/components/common/drops.html +++ b/templates/components/common/drops.html @@ -1,16 +1,17 @@ - - -
+
+ + +
- {% for kind in material_kinds %} -
+ {% for kind in data.material_kinds %} +
- {#{% if loop.index0 == 6 %} -
- {% endif %}#} {% endfor %}

-{% for drop in drops %} +{% for drop in data.drops %} {% call macros::drop("shard") %} {% call macros::drop("stone") %} {% call macros::drop("gem") %} diff --git a/templates/macros/common/macros.html b/templates/macros/common/macros.html index f28a43e..7972491 100644 --- a/templates/macros/common/macros.html +++ b/templates/macros/common/macros.html @@ -3,12 +3,12 @@ {% if drops.len() > 0 %}