use std::sync::OnceLock; use askama::Template; use blake3::Hash; use itertools::Itertools; use crate::{ RuntimeModule, common::{Game, enemy::Enemy, materials::MaterialDrops}, create_file, create_hashes, }; const ENEMIES_PATH: &str = "./input/kh1/enemies"; static JS_HASH: OnceLock = OnceLock::new(); #[derive(Template)] #[template(path = "pages/kh1/drops.html")] struct DropsTemplate { pub game: Game, pub drops: Vec, pub material_kinds: Vec, } pub struct Module; impl RuntimeModule for Module { fn start_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(); tracing::info!("Generating the KH1 drops template"); let drops_template = DropsTemplate { game: Game::Kh1, drops, material_kinds, }; create_file("./out/kh1", "drops", drops_template.render().unwrap()).unwrap(); } fn get_js_hash() -> String { JS_HASH.get_or_init(|| create_hashes("kh1")).to_string() } }