khguide/src/kh1.rs

46 lines
1.1 KiB
Rust
Raw Normal View History

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