database_monsters #119

Merged
Dandaedre merged 6 commits from database_monsters into main 2026-07-19 04:28:49 +02:00
9 changed files with 117 additions and 80 deletions

View File

@ -6,7 +6,7 @@ resolver = "3"
# edition = "2024"
# license = "MIT OR Apache-2.0"
[workspace.package]
version = "0.3.6"
version = "0.3.7"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -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"

View File

@ -237,12 +237,16 @@ pub(super) enum LineType {
#[token("Remove \\makeglossaries if you don't want any glossaries.")]
NoGlossary,
#[regex(r"No file [^$]\.gls\.", |_| "".to_string())]
/// The glossary file wasn't found
NoGlossaryFile(String),
#[regex(
r" ?\)?<?/usr/share/texlive/texmf-dist/fonts/type1/public/fontawesome5[^\n]+",
r" ?\)?<?/usr/share/texlive/texmf.dist/fonts/type1/public/fontawesome5[^\n]+",
allow_greedy = true
)]
/// The fontawesome package has loaded it's fonts
Fontawesome,
FontAwesome,
/// The warning generated by a package
#[regex(r"Package [A-z_-]+ Warning: [^\n]+", |lex| split_by(":",lex.slice()), allow_greedy=true)]
@ -343,7 +347,8 @@ impl LineType {
LineType::BoxFullnessPrs => VerboseLevel::Critical,
LineType::PackageWarningPrs(_) => VerboseLevel::Critical,
LineType::NoGlossary => VerboseLevel::Warning,
LineType::Fontawesome => VerboseLevel::Info,
LineType::FontAwesome => VerboseLevel::Info,
LineType::NoGlossaryFile(_) => VerboseLevel::Warning,
}
}
}

View File

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

View File

@ -47,7 +47,7 @@ pub(crate) fn fetch_all_data(connection: Connection) -> Result<Vec<FullMonster>,
connection,
creature,
"creature_body_parts",
Some("body_part_name")
None
);
let creature_stats =

View File

@ -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!(
@ -193,13 +202,12 @@ impl MonsterAllAttacks {
// Ungroup them to have nice bundles
for (group, atk) in grouped_attacks {
if group.is_some() {
let monster_first_atk = atk.first().unwrap();
let group_attack = MonsterFullAttack {
attacklist: atk.iter().map(|&v| v.clone()).collect(),
// color: atk.first().unwrap().attack_type.clone(),
size: atk.len() + 1,
description_final: atk
.first()
.unwrap()
size: atk.len() + number_of_description(monster_first_atk),
description_final: monster_first_atk
.description_all
.clone()
.unwrap_or_default(),
@ -214,7 +222,7 @@ impl MonsterAllAttacks {
.unwrap()
.push(MonsterFullAttack {
attacklist: vec![single_atk.clone()],
size: 2,
size: 1 + number_of_description(&single_atk),
description_final: single_atk
.description_all
.clone()
@ -227,6 +235,15 @@ impl MonsterAllAttacks {
Self { phases }
}
}
/// The number of description fields
fn number_of_description(monster_first_atk: &&MonsterSingleAttack) -> usize {
if monster_first_atk.description_all.is_some() {
1
} else {
0
}
}
#[derive(Serialize)]
struct Coloring<'a> {
color: &'a str,

View File

@ -62,40 +62,40 @@ pub struct CreatureData {
pub danger_level: i64,
/// Type of habitat
#[TEXT]
pub habitat: String,
pub habitat: Option<String>,
/// Wether a dismorphism exists
#[TEXT]
pub dysmorphism: String,
pub dysmorphism: Option<String>,
/// Monster size
#[TEXT]
pub size: Option<String>,
/// Generic color describing the creature
#[TEXT]
pub colors: String,
pub colors: Option<String>,
/// Default reaction to human presence
#[TEXT]
pub default_human_reaction: String,
pub default_human_reaction: Option<String>,
/// Known variants
#[TEXT]
pub variants: String,
pub variants: Option<String>,
/// General habits
#[TEXT]
pub habits: String,
pub habits: Option<String>,
/// Generic creature description
#[TEXT]
pub description: String,
pub description: Option<String>,
/// Annotations
#[TEXT]
pub annotations: String,
pub annotations: Option<String>,
/// Annotations GM
#[TEXT]
pub annotations_master: Option<String>,
/// The battle plan of the creature
#[TEXT]
pub battle_plan: String,
pub battle_plan: Option<String>,
/// The graph of intents (image)
#[TEXT]
pub intent_graph: String,
pub intent_graph: Option<String>,
/// Wether to show it to players
#[INTEGER]
pub show_to_master: Option<i64>,
@ -121,6 +121,9 @@ pub struct CreatureReward {
/// Category of the ability
#[TEXT]
pub category: String,
/// The cost of the reward
#[TEXT]
pub cost: Option<String>,
/// Effect of the ability
pub effect: String,
}
@ -284,6 +287,10 @@ pub struct CreatureStats {
#[INTEGER]
pub fatigue: i64,
#[INTEGER]
pub physical_bonus_dmg: i64,
#[INTEGER]
pub elemental_bonus_dmg: Option<i64>,
#[INTEGER]
pub mvt_walk: i64,
#[INTEGER]
pub mvt_trot: i64,

View File

@ -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 = [] }

View File

@ -154,45 +154,45 @@ intro = '''\begin{tblr}{
cell{1}{1}={c=2}{c},
}
\includegraphics[height=5cm]{ {{{image}}} } & \\
{{#if image}}\includegraphics[height=5cm]{ {{{image}}} } & \\{{/if}}
& \\
Nom & {{{name}}} \\
Dénomination & {{{denomination}}} \\
Calamité & {{{calamity}}} \\
Niveau de danger (HSE) & {{{danger_level}}} \\
& \\
Habitat & \SetCell{font=\footnotesize} {{{habitat}}} \\
Dysmorphisme & \SetCell{font=\footnotesize} {{{dysmorphism}}} \\
Couleurs & \SetCell{font=\footnotesize} {{{colors}}} \\
Réaction à l'homme & \SetCell{font=\footnotesize} {{{default_human_reaction}}} \\
Variantes & \SetCell{font=\footnotesize} {{{variants}}}\\
Taille & \SetCell{font=\footnotesize} {{{size}}}\\
Mœurs & \SetCell{font=\footnotesize} {{{habits}}} \\
\end{tblr}
{{#if denomination}}Dénomination & {{{denomination}}} \\
{{/if}}{{#if calamity}}Calamité & {{{calamity}}} \\
{{/if}}{{#if danger_level}}Niveau de danger (HSE) & {{{danger_level}}} \\
{{/if}}& \\
{{#if habitat}}Habitat & \SetCell{font=\footnotesize} {{{habitat}}} \\
{{/if}}{{#if dysmorphism}}Dysmorphisme & \SetCell{font=\footnotesize} {{{dysmorphism}}} \\
{{/if}}{{#if colors}}Couleurs & \SetCell{font=\footnotesize} {{{colors}}} \\
{{/if}}{{#if default_human_reaction}}Réaction à l'homme & \SetCell{font=\footnotesize} {{{default_human_reaction}}} \\
{{/if}}{{#if variants}}Variantes & \SetCell{font=\footnotesize} {{{variants}}}\\
{{/if}}{{#if size}}Taille & \SetCell{font=\footnotesize} {{{size}}}\\
{{/if}}{{#if habits}}Mœurs & \SetCell{font=\footnotesize} {{{habits}}} \\
{{/if}}\end{tblr}
\vfill
\begin{tblr}{
colspec={X[-1]},
hline{2,4,6},
row{2,4,6}={font=\footnotesize}
}
\textbf{Description} \\
{{{description}}} \\
\textbf{Annotations} \\
{{{annotations}}} \\
{{#if description}}\textbf{Description} \\
{{{description}}} \\ {{/if}}
{{#if annotations}}\textbf{Annotations} \\
{{{annotations}}} \\ {{/if}}
\textbf{Récompenses} \\
\end{tblr}
\begin{tblr}{
colspec={X[1] X[1,c] X[5,j]},
colspec={X[1] X[1,c] X[2,c] X[3,j]},
vspan=even, hspan=minimal,
row{1-Z}={font=\footnotesize},
rows={m},
}
'''
blood_reward='''
\SetCell[c=2]{j} Sang (base, combat, dépeçage) & & {{{blood_base}}}, {{{blood_battle}}}, {{{blood_carve}}} \\
\SetCell[c=3]{j} Sang (base, combat, dépeçage) & & & {{{blood_base}}}, {{{blood_battle}}}, {{{blood_carve}}} \\
'''
rewards_row=''' {{{name}}} & {{{category}}} & {{{effect}}} \\
rewards_row=''' {{{name}}} & {{{category}}} & {{#if cost}} {{{cost}}} & {{{effect}}} {{else}} \SetCell[c=2]{j} {{{effect}}} & {{/if}} \\
'''
rewards_end='''
\end{tblr}
@ -212,13 +212,15 @@ 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_end= ''' \hline
\SetCell[c=9]{j,h} {\textbf{Notes} \\ {{{annotations_master}}}}\\
\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}}
\hline
\end{tblr}'''
resists_intro=''' \begin{center}
@ -227,7 +229,6 @@ resists_intro=''' \begin{center}
rowspec={Q[c,f] Q[c,m] Q[c] Q[c] Q[c] Q[c] Q[c] Q[c] Q[c] Q[c] Q[c]},
row{3-11}={font=\tiny},
}
% & & & & & & & \small{*} & & & & \small{*} & \small{*} & \\
& & & & & & & & & & & & & \\
\SetCell{c} Res & \slash & \pierce & \blunt & \symceleste & \symfire & \symearth & \symwood & \symmagma & \symabyss & \symwater & \symwind & \symice & \symthunder \\
\hline
@ -240,14 +241,14 @@ resists_end='''
'''
stats='''\begin{tblr}{
colspec={c c c c c c c c c c c c c c c c c c c},
colspec={c c c c c c c c c c c c c c c c c c c c c {{#if elemental_bonus}}c{{/if}}},
row{2}={font=\footnotesize},
row{3-6}={font=\tiny},
}
& \SetCell[c=2]{c} P1 & & \SetCell[c=2]{c} P2 & & & \SetCell[c=7]{c} Stats & & & & & & & & \SetCell[c=4]{c} Mouvement & & & & \\
\cline{2-3} \cline{4-5} \cline{7-13} \cline{15-18}
\rb{Initiative} & \rb{Valeur} & \rb{Actions} & \rb{Valeur} & \rb{Actions} & & \rb{Force} & \rb{Perception} & \rb{Volonté} & \rb{Res Alt} & \rb{Torque} & \rb{Vigilance} & \rb{Fatigue} & & \rb{Marche} & \rb{Trot} & \rb{Course} & \rb{Vol} \\
\SetCell{font=\footnotesize} $t_1 $ & ${{{p1_init}}} $ & $4 $A & ${{{p2_init}}} $ & $4 $A & & ${{{strength}}} $ & ${{{perception}}} $ & ${{{willpower}}} $ & ${{{alteration_resistance}}} $ & ${{{torque}}} $ & ${{{awareness}}} $ & ${{{fatigue}}} $ & & ${{{mvt_walk}}} $ & ${{{mvt_trot}}} $ & ${{{mvt_run}}} $ & ${{{mvt_flight}}} $ \\
& \SetCell[c=2]{c} P1 & & \SetCell[c=2]{c} P2 & & & \SetCell[c=7]{c} Stats & & & & & & & & \SetCell[c=4]{c} Mouvement & & & & & Extra & \\
\cline{2-3} \cline{4-5} \cline{7-13} \cline{15-18} \cline{20-21}
\rb{Initiative} & \rb{Valeur} & \rb{Actions} & \rb{Valeur} & \rb{Actions} & & \rb{Force} & \rb{Perception} & \rb{Volonté} & \rb{Res Alt} & \rb{Torque} & \rb{Vigilance} & \rb{Fatigue} & & \rb{Marche} & \rb{Trot} & \rb{Course} & \rb{Vol} & & \rb{Bon. Phy} {{#if elemental_bonus_dmg}}& \rb{Bon. Élém} {{/if}}\\
\SetCell{font=\footnotesize} $t_1 $ & ${{{p1_init}}} $ & $4 $A & ${{{p2_init}}} $ & $4 $A & & ${{{strength}}} $ & ${{{perception}}} $ & ${{{willpower}}} $ & ${{{alteration_resistance}}} $ & ${{{torque}}} $ & ${{{awareness}}} $ & ${{{fatigue}}} $ & & ${{{mvt_walk}}} $ & ${{{mvt_trot}}} $ & ${{{mvt_run}}} $ & ${{{mvt_flight}}} $ & & ${{{physical_bonus_dmg}}} $ {{#if elemental_bonus_dmg}} & ${{elemental_bonus_dmg}} $ {{/if}} \\
'''
init_rows='''
\SetCell{font=\footnotesize} $t_{{{turn}}} $ & ${{{p1_value}}} $ & {{{pt1_actions}}} & ${{{p2_value}}} $ & {{{p2_actions}}} \\
@ -274,12 +275,17 @@ phase_row= '''
\SetCell[c=13]{white} {{{phase_name}}} & & & & & & & & & & \\
'''
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_before_repeat=''' \hline
'''
attack_info_row='''& \SetCell[c=12]{j} {{{description_final}}} & & & & & & & & & & \\
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
'''
attacks_end= ''' \end{tblr}
@ -290,14 +296,13 @@ attacks_end= ''' \end{tblr}
intent_table='''
\pagebreak
\begin{tblr}{
colspec={X[7] X[3]},
colspec={X[7] {{#if intent_graph}}|X[3] {{/if}} },
rowspec={X[c] X[j,h,8cm]},
vline{2},
hline{2},
row{2}={font=\footnotesize},
}
Plan de combat & Graphique d'intentions \\
{{{battle_plan}}} & {{{intent_graph}}} \\
Plan de combat {{#if intent_graph}}& Graphique d'intentions \\ {{/if}}
{{{battle_plan}}} {{#if intent_graph}}& {{{intent_graph}}} \\ {{/if}}
\end{tblr}
\vfill
\pagebreak
@ -328,5 +333,6 @@ SRG: ravpur
HRG: ravpur
BAD: ravora
BIS: ravredD
BYP: ravredD
'''
default_color=''

@ -1 +1 @@
Subproject commit ec988aabeb3c94233d7f60deef2ff3873c8e9100
Subproject commit fbd9ba5052cd95f081db4bdeb9f3e04b6b5898fe