Very ugly but working tooling
Build Successful The build was successful
Ravenous/ravenous-tools/pipeline/head This commit looks good Details

This commit is contained in:
Dandaedre 2026-07-17 00:59:02 +02:00
parent d01ce27d5b
commit abe9db7c0b
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
5 changed files with 87 additions and 57 deletions

View File

@ -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.

View File

@ -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

View File

@ -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(())
}

View File

@ -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();

@ -1 +1 @@
Subproject commit 211b22dbe327b66f0da9f5c5a780dd6ec00a88d8
Subproject commit 440b8dad8361811e14419ac19a90bc7b003ba3e0