From abe9db7c0bdb2f086cc95b355af307931b280281 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Fri, 17 Jul 2026 00:59:02 +0200 Subject: [PATCH] Very ugly but working tooling --- crates/config/src/monsters.rs | 23 ++++-- crates/make/src/makepdf.rs | 4 +- crates/monsters/src/lib.rs | 13 ++-- crates/monsters/src/monster_export.rs | 102 +++++++++++++++----------- ravenous_databases | 2 +- 5 files changed, 87 insertions(+), 57 deletions(-) diff --git a/crates/config/src/monsters.rs b/crates/config/src/monsters.rs index 5b6e738..29caf04 100644 --- a/crates/config/src/monsters.rs +++ b/crates/config/src/monsters.rs @@ -23,20 +23,31 @@ pub struct MonsterConfig { #[arg(short, long, default_value = "./ravenous_databases/monsters.db")] pub database: String, - /// Clean all the artefacts (including generated images) - #[arg(short, long)] + /// Export the full monsters as full_bestiaire.tex + #[arg(long, default_value_t = false)] + pub master: bool, + + /// Export the player monsters as player_bestiaire.tex + #[arg(long, default_value_t = false)] + pub player: bool, + + /// Export both + #[arg(long, default_value_t = false)] pub all: bool, + // /// Clean all the artefacts (including generated images) + // #[arg(short, long)] + // pub all: bool, } #[derive(ValueEnum, Debug, Clone)] /// The action to execute pub enum MonsterTarget { - /// Clean the generated monsters directory - Clean, + // /// Clean the generated monsters directory + // Clean, /// Generate the monster list Export, - /// Show useful data - Show, + // /// Show useful data + // Show, } /// Configuration data for generating a monster sheet. diff --git a/crates/make/src/makepdf.rs b/crates/make/src/makepdf.rs index 90a2e3e..6573b42 100644 --- a/crates/make/src/makepdf.rs +++ b/crates/make/src/makepdf.rs @@ -30,7 +30,7 @@ use tokio::{ process::Command, }; -use anyhow::{Result, anyhow}; +use anyhow::{Context, Result, anyhow}; use crate::makepdf_functions::{ BuilderParseResult, make_clean, make_file, make_glossaries, make_list, @@ -102,7 +102,7 @@ async fn launch_subprocess( // Specify that we want the command's standard output piped back to us. cmd.stdout(Stdio::piped()); - let mut child = cmd.spawn().expect("Failed to spawn command"); + let mut child = cmd.spawn().context("Failed to spawn command")?; let stdout = child .stdout diff --git a/crates/monsters/src/lib.rs b/crates/monsters/src/lib.rs index 9ad2895..e1af0f6 100644 --- a/crates/monsters/src/lib.rs +++ b/crates/monsters/src/lib.rs @@ -14,6 +14,7 @@ //! use crate::monster_export::generate_monsters_tex; +use config::monsters::MonsterTarget; use anyhow::Context; mod monster_database; @@ -32,12 +33,10 @@ pub fn monsters_dispatch(args: &MonsterConfig, config: &Config) -> Result<()> { let connection = Connection::open(&args.database).context(format!("Opening database {}", args.database))?; - generate_monsters_tex(args, config, connection)?; - - // match args.target { - // MonsterTarget::Clean => todo!("implement cleaning logic"), - // MonsterTarget::Export => todo!("implement export logic"), - // MonsterTarget::Show => todo!("implement show logic"), - // } + match args.target { + // MonsterTarget::Clean => unimplemented!("implement cleaning logic"), + MonsterTarget::Export => generate_monsters_tex(args, config, connection)?, + // MonsterTarget::Show => unimplemented!("implement show logic"), + } Ok(()) } diff --git a/crates/monsters/src/monster_export.rs b/crates/monsters/src/monster_export.rs index bcbfe98..5423263 100644 --- a/crates/monsters/src/monster_export.rs +++ b/crates/monsters/src/monster_export.rs @@ -67,58 +67,78 @@ pub fn generate_monsters_tex( let all_monsters = fetch_all_data(connection)?; let templates = load_templates(config)?; - let mut out = String::new(); + let mut player_out = String::new(); + let mut master_out = String::new(); let creature = &all_monsters[0]; - write!(out, "{}", templates.render("intro", &creature.data)?)?; + write!(player_out, "{}", templates.render("intro", &creature.data)?)?; write!( - out, + player_out, "{}", templates.render("blood_reward", &creature.stats)? )?; for reward in creature.rewards.rewards.iter() { - write!(out, "{}", templates.render("rewards_row", reward)?)?; + write!(player_out, "{}", templates.render("rewards_row", reward)?)?; } - write!(out, "{}", &config.monster.rewards_end)?; - write!(out, "{}", &config.monster.body_parts_intro)?; - for part in creature.body_parts.body_parts.iter() { - write!(out, "{}", templates.render("body_parts_row", part)?)?; - } - write!( - out, - "{}", - templates.render("body_parts_end", &creature.data)? - )?; - // TODO: Maybe add modularity and not print empty resists - write!(out, "{}", &config.monster.resists_intro)?; - for part in creature.body_parts.body_parts.iter() { - write!(out, "{}", templates.render("resists_row", part)?)?; - } - write!(out, "{}", &config.monster.resists_end)?; - write!(out, "{}", templates.render("stats", &creature.stats)?)?; - for init in MonsterRepetableInitRow::vec_from( - &creature.stats.p1_init, - &creature.stats.p2_init, - &creature.stats.p1_actions, - &creature.stats.p2_actions, - ) - .iter() - .skip(1) - { - write!(out, "{}", templates.render("init_rows", init)?)?; - } - write!(out, "{}", &config.monster.init_end)?; + write!(player_out, "{}", &config.monster.rewards_end)?; + if args.master { + write!(master_out, "{}", &config.monster.body_parts_intro)?; + for part in creature.body_parts.body_parts.iter() { + write!(master_out, "{}", templates.render("body_parts_row", part)?)?; + } + write!( + master_out, + "{}", + templates.render("body_parts_end", &creature.data)? + )?; + // TODO: Maybe add modularity and not print empty resists + write!(master_out, "{}", &config.monster.resists_intro)?; + for part in creature.body_parts.body_parts.iter() { + write!(master_out, "{}", templates.render("resists_row", part)?)?; + } + write!(master_out, "{}", &config.monster.resists_end)?; + write!( + master_out, + "{}", + templates.render("stats", &creature.stats)? + )?; + for init in MonsterRepetableInitRow::vec_from( + &creature.stats.p1_init, + &creature.stats.p2_init, + &creature.stats.p1_actions, + &creature.stats.p2_actions, + ) + .iter() + .skip(1) + { + write!(master_out, "{}", templates.render("init_rows", init)?)?; + } + write!(master_out, "{}", &config.monster.init_end)?; - let all_attacks = MonsterAllAttacks::from_retrieved_data(&creature.attacks.attacks); - write!(out, "{}", &config.monster.attacks_intro)?; - write!(out, "{}", all_attacks.to_tex(&templates, config)?)?; - write!(out, "{}", &config.monster.attacks_end)?; - write!(out, "{}", templates.render("intent_table", &creature.data)?)?; + let all_attacks = MonsterAllAttacks::from_retrieved_data(&creature.attacks.attacks); + write!(master_out, "{}", &config.monster.attacks_intro)?; + write!(master_out, "{}", all_attacks.to_tex(&templates, config)?)?; + write!(master_out, "{}", &config.monster.attacks_end)?; + write!( + master_out, + "{}", + templates.render("intent_table", &creature.data)? + )?; + } - // println!("{}", out); - let mut f = File::create(format!("{}/testmonster.tex", args.destination))?; - write!(f, "{}", out)?; + if args.player || args.all { + println!("Generating player bestiaire"); + let mut f = File::create(format!("{}/player_bestiaire.tex", args.destination))?; + write!(f, "{}", player_out)?; + } + if args.master || args.all { + println!("Generating master bestiaire"); + let mut f = File::create(format!("{}/master_bestiaire.tex", args.destination))?; + write!(f, "{}", player_out)?; + write!(f, "{}", master_out)?; + } Ok(()) } + impl MonsterAllAttacks { pub fn from_retrieved_data(original_data: &[MonsterSingleAttack]) -> MonsterAllAttacks { let mut initial_phases: IndexMap<&String, Vec<&MonsterSingleAttack>> = IndexMap::new(); diff --git a/ravenous_databases b/ravenous_databases index 211b22d..440b8da 160000 --- a/ravenous_databases +++ b/ravenous_databases @@ -1 +1 @@ -Subproject commit 211b22dbe327b66f0da9f5c5a780dd6ec00a88d8 +Subproject commit 440b8dad8361811e14419ac19a90bc7b003ba3e0