From 7ec926432e547ca7023c921e4611c61c2c8c3250 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Mon, 20 Jul 2026 00:04:51 +0200 Subject: [PATCH] Solves the multiline mistake --- Cargo.toml | 2 +- crates/config/src/monsters.rs | 5 +-- crates/monsters/src/monster_export.rs | 56 ++++++++++++-------------- crates/monsters/src/monster_structs.rs | 2 +- helper_config.toml | 17 ++------ 5 files changed, 34 insertions(+), 48 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2606e5b..d8cc0e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ resolver = "3" # edition = "2024" # license = "MIT OR Apache-2.0" [workspace.package] -version = "0.3.8" +version = "0.3.9" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/crates/config/src/monsters.rs b/crates/config/src/monsters.rs index 2c0a481..2a0bad6 100644 --- a/crates/config/src/monsters.rs +++ b/crates/config/src/monsters.rs @@ -104,9 +104,8 @@ pub struct MonsterMarkup { /// Row used for each attack’s data (IDs, types, damage, etc.). pub phase_row: String, - /// The color of the attack row - pub attack_color: String, - + // /// The color of the attack row + // pub attack_color: String, /// Before attack pub attack_before_repeat: String, diff --git a/crates/monsters/src/monster_export.rs b/crates/monsters/src/monster_export.rs index edc2e0a..0e5011b 100644 --- a/crates/monsters/src/monster_export.rs +++ b/crates/monsters/src/monster_export.rs @@ -49,7 +49,7 @@ fn load_templates(config: &Config) -> Result> { template_load!(templates, &config.monster, resists_row); template_load!(templates, &config.monster, stats); template_load!(templates, &config.monster, phase_row); - template_load!(templates, &config.monster, attack_color); + // template_load!(templates, &config.monster, attack_color); template_load!(templates, &config.monster, attack_repeatable_row); template_load!(templates, &config.monster, attack_info_row); template_load!(templates, &config.monster, intent_table); @@ -104,14 +104,6 @@ pub fn generate_monsters_tex( 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); - // println!("{:#?}", templates.render("body_parts_row", &fixed_part)?); write!( master_out, "{}", @@ -147,7 +139,8 @@ pub fn generate_monsters_tex( } write!(master_out, "{}", &config.monster.init_end)?; - let all_attacks = MonsterAllAttacks::from_retrieved_data(&creature.attacks.attacks); + let all_attacks = + MonsterAllAttacks::from_retrieved_data(&creature.attacks.attacks, config); write!(master_out, "{}", &config.monster.attacks_intro)?; write!(master_out, "{}", all_attacks.to_tex(&templates, config)?)?; write!(master_out, "{}", &config.monster.attacks_end)?; @@ -175,7 +168,10 @@ pub fn generate_monsters_tex( } impl MonsterAllAttacks { - pub fn from_retrieved_data(original_data: &[MonsterSingleAttack]) -> MonsterAllAttacks { + pub fn from_retrieved_data( + original_data: &[MonsterSingleAttack], + config: &Config, + ) -> MonsterAllAttacks { let mut initial_phases: IndexMap<&String, Vec<&MonsterSingleAttack>> = IndexMap::new(); let mut phases: IndexMap> = IndexMap::new(); // Intermediate split with hashmaps @@ -203,9 +199,10 @@ impl MonsterAllAttacks { for (group, atk) in grouped_attacks { if group.is_some() { let monster_first_atk = atk.first().unwrap(); + let color = color(monster_first_atk, config); let group_attack = MonsterFullAttack { + color, attacklist: atk.iter().map(|&v| v.clone()).collect(), - // color: atk.first().unwrap().attack_type.clone(), size: atk.len() + number_of_description(monster_first_atk), description_final: monster_first_atk .description_all @@ -221,6 +218,7 @@ impl MonsterAllAttacks { .get_mut(&phase_name) .unwrap() .push(MonsterFullAttack { + color: color(single_atk, config), attacklist: vec![single_atk.clone()], size: 1 + number_of_description(&single_atk), description_final: single_atk @@ -236,6 +234,16 @@ impl MonsterAllAttacks { } } +fn color(atk: &MonsterSingleAttack, config: &Config) -> String { + config + .monster + .color_table + .inner + .get(&atk.attack_type) + .unwrap_or(&config.monster.default_color) + .clone() +} + /// The number of description fields fn number_of_description(monster_first_atk: &&MonsterSingleAttack) -> usize { if monster_first_atk.description_all.is_some() { @@ -247,7 +255,7 @@ fn number_of_description(monster_first_atk: &&MonsterSingleAttack) -> usize { #[derive(Serialize)] struct Coloring<'a> { color: &'a str, - size: usize, + // size: usize, } #[derive(Serialize)] struct PhaseName<'a> { @@ -265,23 +273,11 @@ impl MonsterAllAttacks { )?; for attack in list_full_attacks { write!(out, "{}", config.monster.attack_before_repeat)?; - let color = Coloring { - size: attack.size, - color: config - .monster - .color_table - .inner - .get(&attack.attacklist[0].attack_type) - .unwrap_or(&config.monster.default_color), - }; - write!(out, "{}", templates.render("attack_color", &color)?)?; - for sub_attack in &attack.attacklist { - write!( - out, - "{}", - templates.render("attack_repeatable_row", sub_attack)? - )?; - } + write!( + out, + "{}", + templates.render("attack_repeatable_row", &attack)? + )?; write!(out, "{}", templates.render("attack_info_row", attack)?)?; } } diff --git a/crates/monsters/src/monster_structs.rs b/crates/monsters/src/monster_structs.rs index dc68e68..8c9c20d 100644 --- a/crates/monsters/src/monster_structs.rs +++ b/crates/monsters/src/monster_structs.rs @@ -394,7 +394,7 @@ pub struct MonsterAllAttacks { #[derive(Serialize, Deserialize, Debug)] pub struct MonsterFullAttack { pub attacklist: Vec, - // pub color: String, + pub color: String, pub size: usize, pub description_final: String, } diff --git a/helper_config.toml b/helper_config.toml index 85934bb..22ceae1 100644 --- a/helper_config.toml +++ b/helper_config.toml @@ -213,9 +213,6 @@ 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}}} $\\ -# ''' 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= ''' @@ -278,16 +275,10 @@ phase_row= ''' attack_before_repeat=''' \hline ''' -attack_color=''' -\SetCell[r={{{size}}}]{bg={{{color}}}}''' # Very ugly hack, going to bed -# attack_repeatable_row= ''' & {{{name}}} & {{{short_name}}} & {{{prerequisites}}} & {{{atk_type}}} & {{{targetting}}} & {{{cost_fatigue}}} & {{{cost_action}}} & {{{element}}} & {{{damage_fatigue}}} &{{{damage_regular}}} & {{{effects}}} & {{{threshold_parry}}} & {{{threshold_dodge}}} \\ -attack_repeatable_row= ''' - & {{{name}}} & {{{attack_type}}} & {{{prerequisites}}} & {{{targetting}}} & {{{cost_fatigue}}} & {{{cost_action}}} & {{{element}}} & {{{damage_fatigue}}} &{{{damage_regular}}} {{{success}}}& {{{effects}}} & {{{threshold_parry}}} & {{{threshold_dodge}}} \\ -''' -# attack_info_row='''& \SetCell[c=12]{j} {{{description_final}}} & & & & & & & & & & \\ -attack_info_row=''' -{{#if description_final}}& \SetCell[c=12]{j} {{{description_final}}} & & & & & & & & & & \\ {{/if}} -\hline +attack_repeatable_row= '''{{#each attacklist}}\SetCell{bg={{{../color}}}} & {{{name}}} & {{{attack_type}}} & {{{prerequisites}}} & {{{targetting}}} & {{{cost_fatigue}}} & {{{cost_action}}} & {{{element}}} & {{{damage_fatigue}}} &{{{damage_regular}}} {{{success}}}& {{{effects}}} & {{{threshold_parry}}} & {{{threshold_dodge}}} \\ +{{/each}} ''' +attack_info_row='''{{#if description_final}}\SetCell{bg={{{color}}}} & \SetCell[c=12]{j} {{{description_final}}} & & & & & & & & & & \\ +{{/if}} \hline ''' attacks_end= ''' \end{longtblr} }