Adds better templating for protection
This commit is contained in:
parent
161a7d2ab4
commit
bcf01e2004
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
|
|
@ -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<i64>| x+y.unwrap_or(0));
|
||||
|
||||
fn load_templates(config: &Config) -> Result<Handlebars<'_>> {
|
||||
let mut templates = Handlebars::new();
|
||||
template_load!(templates, &config.monster, intro);
|
||||
|
|
@ -54,6 +53,7 @@ fn load_templates(config: &Config) -> Result<Handlebars<'_>> {
|
|||
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!(
|
||||
|
|
|
|||
|
|
@ -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 = [] }
|
||||
|
|
|
|||
|
|
@ -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}}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit ec988aabeb3c94233d7f60deef2ff3873c8e9100
|
||||
Subproject commit fbd9ba5052cd95f081db4bdeb9f3e04b6b5898fe
|
||||
Loading…
Reference in New Issue