diff --git a/Cargo.toml b/Cargo.toml index d2bdd17..34d0e3d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,6 +50,7 @@ phf = { version = "0.14.0", features = ["macros"] } regex = "1.13.0" regex_static = "0.1.1" serde = { version = "1.0.228", features = ["derive", "alloc"] } +serde_json = { version = "1.0.150", features = ["alloc"] } csv = "1.4.0" ron = "0.12.2" glob = "0.3.3" diff --git a/crates/monsters/Cargo.toml b/crates/monsters/Cargo.toml index 4011bef..a252d1c 100644 --- a/crates/monsters/Cargo.toml +++ b/crates/monsters/Cargo.toml @@ -12,6 +12,7 @@ indexmap = {workspace = true} serde = {workspace = true} rusqlite = {workspace = true} serde_rusqlite = {workspace = true} +serde_json = {workspace = true} strum = { version = "0.28.0", features = ["derive"] } handlebars = "6.4.3" diff --git a/crates/monsters/src/monster_export.rs b/crates/monsters/src/monster_export.rs index cc1ae60..edc2e0a 100644 --- a/crates/monsters/src/monster_export.rs +++ b/crates/monsters/src/monster_export.rs @@ -3,19 +3,16 @@ use anyhow::{Context, Result}; use cli_parser::Config; use config::monsters::MonsterConfig; -use handlebars::Handlebars; +use handlebars::{Handlebars, handlebars_helper}; use indexmap::IndexMap; use rusqlite::Connection; use serde::Serialize; -use std::fmt::Write; -use std::fs::File; -use std::io::Write as OtherWrite; +use std::{fmt::Write, fs::File, io::Write as OtherWrite}; -use crate::{ - monster_database::fetch_all_data, - monster_structs::{ - MonsterAllAttacks, MonsterFullAttack, MonsterRepetableInitRow, MonsterSingleAttack, - }, +use crate::monster_database::fetch_all_data; +use crate::monster_structs::{ + CreatureBodyPart, CreatureStats, MonsterAllAttacks, MonsterFullAttack, MonsterRepetableInitRow, + MonsterSingleAttack, }; /// Load a template from a struct field into a `templates` collection. @@ -39,6 +36,8 @@ macro_rules! template_load { // fn export_to_tex(self) -> String; // } +handlebars_helper!(plus: |x:i64 ,y:Option| x+y.unwrap_or(0)); + fn load_templates(config: &Config) -> Result> { let mut templates = Handlebars::new(); template_load!(templates, &config.monster, intro); @@ -54,6 +53,7 @@ fn load_templates(config: &Config) -> Result> { template_load!(templates, &config.monster, attack_repeatable_row); template_load!(templates, &config.monster, attack_info_row); template_load!(templates, &config.monster, intent_table); + templates.register_helper("plus", Box::new(plus)); Ok(templates) } @@ -95,18 +95,27 @@ pub fn generate_monsters_tex( if args.master || args.all { write!(master_out, "{}", &config.monster.body_parts_intro)?; for part in creature.body_parts.body_parts.iter() { + #[derive(Serialize)] + struct UnionCreature<'a> { + part: &'a CreatureBodyPart, + stats: &'a CreatureStats, + } + let temp_creature = UnionCreature { + part, + stats: &creature.stats, + }; let mut fixed_part = part.clone(); - fixed_part.protection_p1 = fixed_part - .protection_p1 - .map(|v| v + creature.stats.strength); - fixed_part.protection_p2 = fixed_part - .protection_p2 - .map(|v| v + creature.stats.strength); + // fixed_part.protection_p1 = fixed_part + // .protection_p1 + // .map(|v| v + creature.stats.strength); + // fixed_part.protection_p2 = fixed_part + // .protection_p2 + // .map(|v| v + creature.stats.strength); // println!("{:#?}", templates.render("body_parts_row", &fixed_part)?); write!( master_out, "{}", - templates.render("body_parts_row", &fixed_part)? + templates.render("body_parts_row", &temp_creature)? )?; } write!( diff --git a/crates/weaponry/Cargo.toml b/crates/weaponry/Cargo.toml index 26df699..b94b176 100644 --- a/crates/weaponry/Cargo.toml +++ b/crates/weaponry/Cargo.toml @@ -14,7 +14,7 @@ comfy-table = "7.2.2" probability = "0.20.3" rusqlite = {workspace = true} serde_rusqlite = {workspace = true} -serde_json = { version = "1.0.150", features = ["alloc"] } +serde_json = {workspace = true} strum = { version = "0.28.0", features = ["derive"] } thiserror = "2.0.18" charming = { version = "0.4.0", features = [] } diff --git a/helper_config.toml b/helper_config.toml index f584bec..15a9d03 100644 --- a/helper_config.toml +++ b/helper_config.toml @@ -212,11 +212,12 @@ body_parts_intro=''' } & P1 & & & & P2 & \\ & Seuil & Prot & Intégrité & PV & Seuil & Prot & Intégrité & PV\\ -\hline -''' -body_parts_row=''' -\SetCell{font=\footnotesize} {{{body_part_name }}} & ${{{threshold_p1 }}} $ & ${{{protection_p1}}} {{{protection_total_p1 }}} $ & \SetCell{r,f}\tiny ${{{integrity_p1}}} $ & \SetCell{r,f}\tiny ${{{life_points_p1}}} $ & ${{{threshold_p2}}} $ & ${{{protection_p2}}} {{{protection_total_p2}}} $ & \SetCell{r,f}\tiny ${{{integrity_p2}}} $ & \SetCell{r,f}\tiny ${{{life_points_p2}}} $\\ -''' +\hline ''' +# body_parts_row=''' +# \SetCell{font=\footnotesize} {{{body_part_name }}} & ${{{threshold_p1 }}} $ & ${{{protection_p1}}} {{{protection_total_p1 }}} $ & \SetCell{r,f}\tiny ${{{integrity_p1}}} $ & \SetCell{r,f}\tiny ${{{life_points_p1}}} $ & ${{{threshold_p2}}} $ & ${{{protection_p2}}} {{{protection_total_p2}}} $ & \SetCell{r,f}\tiny ${{{integrity_p2}}} $ & \SetCell{r,f}\tiny ${{{life_points_p2}}} $\\ +# ''' +body_parts_row='''{{#with stats as | s | }} {{#with ../part}} +\SetCell{font=\footnotesize} {{{body_part_name}}} & ${{{threshold_p1}}} $ & ${{{plus s.strength protection_p1}}}[{{{protection_p1}}}]$ & \SetCell{r,f}\tiny ${{{integrity_p1}}} $ & \SetCell{r,f}\tiny ${{{life_points_p1}}} $ & ${{{threshold_p2}}} $ & ${{{plus s.strength protection_p1}}}[{{{protection_p1}}}]$ & \SetCell{r,f}\tiny ${{{integrity_p2}}} $ & \SetCell{r,f}\tiny ${{{life_points_p2}}} $\\ {{/with}} {{/with}} ''' body_parts_end= ''' {{#if annotations_master}} \hline \SetCell[c=9]{j,h} {\textbf{Notes} \\ {{{annotations_master}}}}\\ {{/if}} diff --git a/ravenous_databases b/ravenous_databases index ec988aa..fbd9ba5 160000 --- a/ravenous_databases +++ b/ravenous_databases @@ -1 +1 @@ -Subproject commit ec988aabeb3c94233d7f60deef2ff3873c8e9100 +Subproject commit fbd9ba5052cd95f081db4bdeb9f3e04b6b5898fe