All but the attacks

This commit is contained in:
Dandaedre 2026-07-16 01:53:32 +02:00
parent 006ebe9a0b
commit f86199d497
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
6 changed files with 305 additions and 91 deletions

View File

@ -32,44 +32,66 @@ pub enum MonsterTarget {
Show,
}
/// The config data in .toml
/// Configuration data for generating a monster sheet.
///
/// The values are plain LaTeX fragments stored in the `[monster]` section of a `.toml`
#[allow(dead_code)]
#[derive(Deserialize)]
pub struct MonsterMarkup {
/// Intro – the very first chunk of LaTeX that starts a monster page.
/// Header of the page (image + basic attributes).
pub intro: String,
// ──────────────────────── BODY‑PART TABLE ──────────────────────── //
/// Opening `<tblr>` tag and any pre‑header rows for the body‑part table
/// Body‑parts section header.
pub body_parts_intro: String,
/// One row per body part (e.g. “Tête”, “Corps”). Use `{}` placeholders if you need dynamic values.
/// One row of the body‑parts table.
pub body_parts_row: String,
/// Closing `\hline`/`\end{tblr}` tags for the body‑part table
/// Body‑parts table footer.
pub body_parts_end: String,
// ──────────────────────── RESISTANCE TABLE ────────────────────── //
/// Opening tag & any header rows before the resistance rows
pub resists_intro: String,
/// One row per resistance type (e.g. “Slashing”, “Fire”)
pub resists_row: String,
/// Closing `\hline`/`\end{tblr}` tags for the resistance table
pub resist_end: String,
/// Rewards section header (the table that lists each reward).
pub rewards_row: String,
// ──────────────────────── STATS BLOCK ───────────────────────── //
/// The whole stat block (body‑part thresholds, protection, HP…)
/// Rewards table footer.
pub rewards_end: String,
/// Resists section header.
pub resists_intro: String,
/// The blood reward template.
pub blood_reward: String,
/// One line of the resistances table.
pub resists_row: String,
/// Resists table footer.
pub resists_end: String,
/// Stats section (movement, initiative, etc.).
pub stats: String,
// ──────────────────────── ATTACK LIST ─────────────────────── //
/// Opening `<tblr>` tag & header rows for the action list
/// The row of initiatives (turn 2 onwards)
pub init_rows: String,
/// The end of the initiatives
pub init_end: String,
/// Header of the attacks section.
pub attacks_intro: String,
/// Closing `\hline`/`\end{tblr}` tags for the action list
/// Footer of the attacks section.
pub attacks_end: String,
// ──────────────────────── PHASE TABLES ─────────────────────── //
/// One row per “phase” of the monster’s combat routine
/// Row used for each attack’s data (IDs, types, damage, etc.).
pub phase_row: String,
/// A repeatable action row (used inside a phase)
/// Row that lists repeatable attacks.
pub attack_repeatable_row: String,
/// An informational row that expands on the current action
/// Row that contains additional information for an attack.
pub attack_info_row: String,
/// The intent table & Battle plan
pub intent_table: String,
}

View File

@ -13,8 +13,8 @@
//! (`MonsterConfig`) and delegates to the appropriate sub‑routine (clean, export or show).
//!
use crate::monster_database::fetch_all_data;
use std::collections::BTreeMap;
use crate::{monster_database::fetch_all_data, monster_structs::MonsterRepetableInitRow};
use std::fmt::Write;
use anyhow::Context;
use handlebars::Handlebars;
@ -27,6 +27,24 @@ use cli_parser::Config;
use config::monsters::MonsterConfig;
use rusqlite::Connection;
/// Load a template from a struct field into a `templates` collection.
///
/// $templates – the variable that holds the template collection
/// $cfg_path – any path (e.g. `config`, `self.cfg`, …) that points to a
/// struct containing the field we want
/// $name – the identifier of the field / template name
macro_rules! template_load {
($templates:ident, $cfg_path:expr, $name:ident) => {{
$templates
.register_template_string(
stringify!($name), // "intro"
&$cfg_path.$name, // &config.monster.intro
)
.context(concat!("Registering ", stringify!($name), " template"))? // ? propagates errors
}};
}
// TODO: Create a method on the struct instead of this inane bs
/// Dispatches the chosen monster action.
pub fn monsters_dispatch(args: &MonsterConfig, config: &Config) -> Result<()> {
// use config::monsters::MonsterTarget;
@ -35,18 +53,65 @@ pub fn monsters_dispatch(args: &MonsterConfig, config: &Config) -> Result<()> {
Connection::open(&args.database).context(format!("Opening database {}", args.database))?;
let all_monsters = fetch_all_data(connection)?;
let table_end = &config.monster.intro;
let mut template = Handlebars::new();
template
.register_template_string("intro", &config.monster.intro)
.context("Registering intro template")?;
let mut templates = Handlebars::new();
template_load!(templates, &config.monster, intro);
template_load!(templates, &config.monster, body_parts_row);
template_load!(templates, &config.monster, body_parts_end);
template_load!(templates, &config.monster, blood_reward);
template_load!(templates, &config.monster, rewards_row);
template_load!(templates, &config.monster, init_rows);
template_load!(templates, &config.monster, resists_row);
template_load!(templates, &config.monster, stats);
template_load!(templates, &config.monster, intent_table);
let mut data = BTreeMap::new();
data.insert("calamity", "Bob");
println!(
"{:#}",
template.render("intro", &all_monsters[0].data).unwrap()
);
let mut out = String::new();
let creature = &all_monsters[0];
// write!(out, "{}", templates.render("intro", &creature.data)?)?;
// write!(
// out,
// "{}",
// templates.render("blood_reward", &creature.stats)?
// )?;
// for reward in creature.rewards.rewards.iter() {
// write!(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, "{}", &config.monster.stats)?;
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.attacks_intro)?;
// write!(out, "{}", &config.monster.attacks_end)?;
// write!(out, "{}", templates.render("intent_table", &creature.data)?)?;
println!("{}", out);
// templates
// match args.target {
// MonsterTarget::Clean => todo!("implement cleaning logic"),
// MonsterTarget::Export => todo!("implement export logic"),

View File

@ -1,8 +1,9 @@
#![allow(dead_code)]
use crate::monster_structs;
use crate::monster_structs::{self, CreatureReward};
use crate::monster_structs::{
CreatureBodyPart, CreatureData, CreatureStats, FullMonster, MonsterAttacks, MonsterSingleAttack,
CreatureBodyPart, CreatureData, CreatureListAttacks, CreatureStats, FullMonster,
MonsterSingleAttack,
};
use anyhow::{Context, anyhow};
use rusqlite::Connection;
@ -54,17 +55,27 @@ pub(crate) fn fetch_all_data(connection: Connection) -> Result<Vec<FullMonster>,
};
let creature_stats = creature_stats.first().unwrap().clone();
let creature_rewards = fetch_from!(
CreatureReward,
connection,
creature,
"creature_rewards",
None
);
finished_creatures.push(FullMonster {
id: creature.id,
name: creature.name.clone(),
stats: creature_stats,
attacks: MonsterAttacks {
attacks: CreatureListAttacks {
attacks: creature_attacks,
},
body_parts: monster_structs::CreatureBodyParts {
body_parts: monster_structs::CreatureListBodyParts {
body_parts: creature_resistances,
},
data: creature.clone(),
rewards: monster_structs::CreatureListRewards {
rewards: creature_rewards,
},
});
}
Ok(finished_creatures)

View File

@ -11,6 +11,8 @@
//! ```
//!
#![allow(dead_code)]
use std::iter::Zip;
use more_fields::FieldsAsSlice;
use serde::{Deserialize, Serialize};
@ -26,10 +28,13 @@ pub struct FullMonster {
pub data: CreatureData,
/// Collection of attacks, wrapped in a helper that exposes useful functions.
pub attacks: MonsterAttacks,
pub attacks: CreatureListAttacks,
/// Collection of resistances, wrapped in a helper for convenient iteration.
pub body_parts: CreatureBodyParts,
pub body_parts: CreatureListBodyParts,
/// Collection of all the rewards, wraped in a helper for iteration.
pub rewards: CreatureListRewards,
/// Serialized stats directly copied from the database table.
pub stats: CreatureStats,
@ -77,16 +82,36 @@ pub struct CreatureData {
/// Annotations
#[TEXT]
pub annotations: String,
/// Annotations GM
#[TEXT]
pub annotations_master: Option<String>,
/// The battle plan of the creature
#[TEXT]
pub battle_plan: String,
/// The graph of intents (image)
#[TEXT]
pub intent_graph: String,
/// Problematic list of rewards
// TODO: FIX
}
/// A helper wrapper around all rewards
pub struct CreatureListRewards {
pub rewards: Vec<CreatureReward>,
}
/// One row from the `rewards` table.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, FieldsAsSlice)]
pub struct CreatureReward {
/// The id of the creature that owns the reward (FOREIGN KEY to `creature_data.id`).
#[INTEGER]
pub creature_id: i64,
/// Full name of the reward.
#[TEXT]
pub rewards: String,
pub name: String,
/// Category of the ability
#[TEXT]
pub category: String,
/// Effect of the ability
pub effect: String,
}
/// A helper wrapper around all attacks belonging to a monster.
@ -94,7 +119,7 @@ pub struct CreatureData {
/// The inner vector holds individual attack rows (`MonsterSingleAttack`);
/// helper methods on this struct (not shown here) can split or aggregate
/// these rows into more ergonomic data structures.
pub struct MonsterAttacks {
pub struct CreatureListAttacks {
/// All attack rows for the monster, as read from the database.
pub attacks: Vec<MonsterSingleAttack>,
}
@ -104,7 +129,7 @@ pub struct MonsterAttacks {
/// The inner vector contains `MonsterSingleResistance` entries; methods
/// on this struct can provide iterators or lookup functions that are
/// easier to consume than raw rows.
pub struct CreatureBodyParts {
pub struct CreatureListBodyParts {
/// All resistance rows for the monster, as read from the database.
pub body_parts: Vec<CreatureBodyPart>,
}
@ -217,13 +242,13 @@ pub struct CreatureStats {
#[INTEGER]
pub creature_id: i64,
#[TEXT]
pub p1_init: String,
pub p1_init: MonsterInitString,
#[TEXT]
pub p2_init: String,
pub p2_init: MonsterInitString,
#[TEXT]
pub p1_actions: String,
pub p1_actions: MonsterInitString,
#[TEXT]
pub p2_actions: String,
pub p2_actions: MonsterInitString,
#[INTEGER]
pub strength: i64,
#[INTEGER]
@ -253,3 +278,87 @@ pub struct CreatureStats {
#[INTEGER]
pub blood_carve: i64,
}
// ----------- HERE BE WARCRIMES -------------
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[serde(transparent)]
/// A custom string used to avoid work
pub struct MonsterInitString {
inner: String,
}
/// A monster init row (entire)
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct MonsterRepetableInitRow {
pub turn: usize,
pub p1_value: String,
pub p1_actions: String,
pub p2_value: String,
pub p2_actions: String,
}
impl MonsterRepetableInitRow {
pub fn vec_from(
p1_vals: &MonsterInitString,
p2_vals: &MonsterInitString,
p1_acts: &MonsterInitString,
p2_acts: &MonsterInitString,
) -> Vec<Self> {
let p1_vals = MonsterRepetableInitValue::from(p1_vals);
let p2_vals = MonsterRepetableInitValue::from(p2_vals);
let p1_acts = MonsterRepetableInitValue::from(p1_acts);
let p2_acts = MonsterRepetableInitValue::from(p2_acts);
p1_acts
.inner
.iter()
.zip(p2_acts.inner.iter())
.zip(p1_vals.inner.iter())
.zip(p2_vals.inner.iter())
.enumerate()
.map(|(turn, (((p1_actions, p2_actions), p1_value), p2_value))| {
MonsterRepetableInitRow {
p1_value: p1_value.clone(),
p1_actions: p1_actions.clone(),
p2_value: p2_value.clone(),
p2_actions: p2_actions.clone(),
turn: turn + 1,
}
})
.collect::<Vec<Self>>()
}
}
#[derive(Debug, Clone)]
/// A repeteable init string
pub struct MonsterRepetableInitValue {
inner: Vec<String>,
}
impl From<&MonsterInitString> for MonsterRepetableInitValue {
fn from(value: &MonsterInitString) -> Self {
Self {
inner: value.inner.split(',').map(|s| s.to_string()).collect(),
}
}
}
impl Serialize for MonsterInitString {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let mut c = self.inner.split(',');
serializer.collect_str(
c.next()
.unwrap_or_else(|| panic!("Trying to split {} by ','", self.inner)),
)
}
}
// impl From<&str> for CustomString {
// fn from(value: &str) -> Self {
// Self {
// inner: value.to_string(),
// }
// }
// }

View File

@ -179,11 +179,24 @@ Mœurs & \SetCell{font=\footnotesize} {{habits}} \\
\textbf{Annotations} \\
{{annotations}} \\
\textbf{Récompenses} \\
{{rewards}}
\end{tblr}
\begin{tblr}{
colspec={X[-1] X[-1,c] X[-1,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}} \\
'''
rewards_row=''' {{name}} & {{category}} & {{effect}} \\
'''
rewards_end='''\end{tblr}
\vfill
'''
body_parts_intro='''
\begin{tblr}{
colspec={X[l,-1] X[-1] X[-1] X[] X[] X[-1] X[-1] X[] X[]},
@ -197,19 +210,10 @@ body_parts_intro='''
& P1 & & & & P2 & \\
& Seuil & Prot & Intégrité & PV & Seuil & Prot & Intégrité & PV\\
\hline
\SetCell{font=\footnotesize} Tête & $(s1)$ & $(p1)$ & \SetCell{r,f}\tiny$(i1)$ & \SetCell{r,f}\tiny$(h1)$ & $(s2)$ & $(p2)$ & \SetCell{r,f}\tiny$(i2)$ & \SetCell{r,f}\tiny$(h2)$\\
'''
body_parts_row=''' \SetCell{font=\footnotesize} Corps & $3$ & $3$ & \SetCell{r,f}\tiny$999$ & \SetCell{r,f}\tiny$999$ & $3$ & $3$ & \SetCell{r,f}\tiny$999$ & \SetCell{r,f}\tiny$999$\\
\SetCell{font=\footnotesize} M AvD & $3$ & $3$ & \SetCell{r,f}\tiny$999$ & \SetCell{r,f}\tiny$999$ & $3$ & $3$ & \SetCell{r,f}\tiny$999$ & \SetCell{r,f}\tiny$999$\\
\SetCell{font=\footnotesize} M AvG & $3$ & $3$ & \SetCell{r,f}\tiny$999$ & \SetCell{r,f}\tiny$999$ & $3$ & $3$ & \SetCell{r,f}\tiny$999$ & \SetCell{r,f}\tiny$999$\\
\SetCell{font=\footnotesize} M ArD & $3$ & $3$ & \SetCell{r,f}\tiny$999$ & \SetCell{r,f}\tiny$999$ & $3$ & $3$ & \SetCell{r,f}\tiny$999$ & \SetCell{r,f}\tiny$999$\\
\SetCell{font=\footnotesize} M ArG & $3$ & $3$ & \SetCell{r,f}\tiny$999$ & \SetCell{r,f}\tiny$999$ & $3$ & $3$ & \SetCell{r,f}\tiny$999$ & \SetCell{r,f}\tiny$999$\\
\SetCell{font=\footnotesize} Queue & $3$ & $3$ & \SetCell{r,f}\tiny$999$ & \SetCell{r,f}\tiny$999$ & $3$ & $3$ & \SetCell{r,f}\tiny$999$ & \SetCell{r,f}\tiny$999$\\
\SetCell{font=\footnotesize} Aile G & $3$ & $3$ & \SetCell{r,f}\tiny$999$ & \SetCell{r,f}\tiny$999$ & $3$ & $3$ & \SetCell{r,f}\tiny$999$ & \SetCell{r,f}\tiny$999$\\
\SetCell{font=\footnotesize} Aile D & $3$ & $3$ & \SetCell{r,f}\tiny$999$ & \SetCell{r,f}\tiny$999$ & $3$ & $3$ & \SetCell{r,f}\tiny$999$ & \SetCell{r,f}\tiny$999$\\
'''
body_parts_row='''\SetCell{font=\footnotesize} {{body_part_name}} & ${{threshold_p1}}$ & ${{protection_p1}}$ & \SetCell{r,f}\tiny${{integrity_p1}}$ & \SetCell{r,f}\tiny${{life_points_p1}}$ & ${{threshold_p2}}$ & ${{protection_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} \\ \lipsum[11][1-5]}\\
\SetCell[c=9]{j,h} {\textbf{Notes} \\ {{annotations_master}}\\
\hline
\end{tblr}'''
resists_intro=''' \center{
@ -222,38 +226,28 @@ resists_intro=''' \center{
\SetCell{c} Res & \slash & \pierce & \blunt & \symceleste & \symfire & \symearth & \symwood & \symmagma & \symabyss & \symwater & \symwind & \symice & \symthunder \\
\hline
'''
resists_row= ''' \SetCell{font=\footnotesize} Tête & $+$ & $+$ & $+$ & $+$ & $+$ & $+$ & $+$ & $+$ & $+++$ & $---$ & $+$ & $--$ & $+$ \\'''
resist_end=' \end{tblr} '
resists_row= ''' \SetCell{font=\footnotesize} {{name}} & ${{slash}}$ & ${{pierce}}$ & ${{blunt}}$ & ${{celestial}}$ & ${{fire}}$ & ${{earth}}$ & ${{wood}}$ & ${{magma}}$ & ${{celeste}}$ & ${{water}}$ & ${{wind}}$ & ${{ice}}$ & ${{thunder}}$ \\
'''
resists_end=' \end{tblr}'
stats=''' \begin{tblr}{
colspec={c c c c c c c c c c c c c c c c c c c c c c c},
row{2}={font=\footnotesize},
row{3-6}={font=\tiny},
stats='''\begin{tblr}{
colspec={c c c c c c c c c c c c c c c c c c c},
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 & & & & & \SetCell[c=3]{c} Sang\\
\cline{2-3} \cline{4-5} \cline{7-13} \cline{15-18} \cline{20-23}
\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{Base} & \rb{Combat} & \rb{Dépeçage}\\
\SetCell{font=\footnotesize}$1$ & $20$ & $4$A & $22$ & $4$A & & $990$ & $991$ & $992$ & $993$ & $994$ & $995$ & $996$ & & $997$ & $998$ & $999$ & $111$ & & $20$ & $5$ & $7$ \\
\SetCell{font=\footnotesize}$2$ & $15$ & $3$A & $17$ & $3$A \\
\SetCell{font=\footnotesize}$3$ & $10$ & $2$A & $12$ & $2$A \\
\SetCell{font=\footnotesize}$4$ & $5$ & $1$A & $7$ & $1$A \\
& \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}}$ \\
'''
init_rows='''
\SetCell{font=\footnotesize}$t_{{turn}}$ & ${{p1_value}}$ & {{pt1_actions}} & ${{p2_value}}$ & {{p2_actions}} \\
'''
init_end= '''
\end{tblr}
}
\vfill ''' # Warn, annoying init
attacks_intro= '''\begin{tblr}{
colspec={X[7] X[3]},
rowspec={X[c] X[j,h,8cm]},
vline{2},
hline{2},
row{2}={font=\footnotesize},
}
Plan de combat & Graphique d'intentions \\
\lipsum[10] & \lipsum[15][1-3] \\
\end{tblr}
\vfill
\scriptsize{
\vfill '''
attacks_intro= '''\scriptsize{
\begin{tblr}{
colspec={X[0.05] X[4,l] X[1,c] X[1,c] X[0.3,c] X[0.3,c] X[0.3,c] X[0.3,c] X[0.3,c] X[2,r] X[2,c] X[0.3,c] X[0.3,c]},
hspan=minimal,
@ -281,3 +275,16 @@ attacks_end= ''' \end{tblr}
\vfill
\renewcommand{\rb}{\undefined}
'''
intent_table=''' \begin{tblr}{
colspec={X[7] X[3]},
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}} \\
\end{tblr}
\vfill
'''

@ -1 +1 @@
Subproject commit dd0e1eba2cf34521dfdccbe84b2cf71cd851e9e9
Subproject commit bdcf919c1066f5b175eb9c6896539fea72d03368