Hideous hack

Maybe some clean tomorrow
This commit is contained in:
Dandaedre 2026-07-16 05:35:37 +02:00
parent 08a66bf2b8
commit 572ad159a2
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
10 changed files with 231 additions and 50 deletions

View File

@ -56,3 +56,4 @@ glob = "0.3.3"
tokio = { version = "1.52.3", features = ["full"] }
dynfmt = { version = "0.1.5", features = ["curly"] }
pretty_assertions = "^1.4"
indexmap = "2.14.0"

View File

@ -7,3 +7,5 @@ edition = "2024"
clap = {workspace = true}
serde = {workspace = true}
phf = {workspace = true}
indexmap = {workspace = true}
anyhow = {workspace = true}

View File

@ -4,8 +4,10 @@
//!
#![allow(dead_code)]
use anyhow::Result;
use clap::{Args, ValueEnum};
use serde::Deserialize;
use indexmap::IndexMap;
use serde::{Deserialize, Deserializer};
#[derive(Args, Debug, Clone)]
/// The configuration struct for the Graph
@ -86,6 +88,12 @@ 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,
/// Before attack
pub attack_before_repeat: String,
/// Row that lists repeatable attacks.
pub attack_repeatable_row: String,
@ -94,4 +102,51 @@ pub struct MonsterMarkup {
/// The intent table & Battle plan
pub intent_table: String,
/// Color map
#[serde(deserialize_with = "parse_monster_color")]
pub color_table: MonsterColor,
/// Default color
pub default_color: String,
}
/// Ghetto color import
pub struct MonsterColor {
/// Inner color
pub inner: IndexMap<String, String>,
}
impl std::ops::Deref for MonsterColor {
type Target = IndexMap<String, String>;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
/// Parse the monster colors from a toml
fn parse_monster_color<'de, D>(deserializer: D) -> Result<MonsterColor, D::Error>
where
D: Deserializer<'de>,
{
let color = String::deserialize(deserializer)?;
Ok(MonsterColor {
inner: color
.lines()
.filter_map(|line| {
let line = line.trim();
if line.is_empty() {
return None;
}
// Split at the first ':' only.
let mut parts = line.splitn(2, ':');
let key = parts.next()?.trim().to_string();
let value = parts.next().map(|v| v.trim()).ok_or(()).ok()?;
Some((key, value.to_owned()))
})
.collect(),
})
}

View File

@ -12,8 +12,8 @@ serde = {workspace = true}
toml = {workspace = true}
tokio = {workspace = true}
dynfmt = {workspace = true}
indexmap = {workspace = true}
indicatif = { version = "0.18.6", features = ["rayon"] }
logos = "0.16.1"
indexmap = "2.14.0"
console = "0.16.4"

View File

@ -8,17 +8,12 @@ config = {workspace = true}
cli_parser = {workspace = true}
more_fields = {workspace = true}
anyhow = {workspace = true}
# regex = {workspace = true}
# csv = {workspace = true}
indexmap = {workspace = true}
serde = {workspace = true}
# comfy-table = "7.2.2"
# probability = "0.20.3"
rusqlite = { version = "0.40.1" } # , features = ["bundled"]
serde_rusqlite = "0.43.0"
# serde_json = { version = "1.0.150", features = ["alloc"] }
strum = { version = "0.28.0", features = ["derive"] }
handlebars = "6.4.3"
# charming = { version = "0.4.0", features = [] }
[dev-dependencies]
regex = {workspace = true}

View File

@ -34,7 +34,7 @@ pub(crate) fn fetch_all_data(connection: Connection) -> Result<Vec<FullMonster>,
connection,
creature,
"creature_abilities",
Some("phase, attack_group, attack_type, name")
Some("phase, attack_group, attack_type")
);
let creature_resistances = fetch_from!(
CreatureBodyPart,

View File

@ -4,10 +4,17 @@ use anyhow::{Context, Result};
use cli_parser::Config;
use config::monsters::MonsterConfig;
use handlebars::Handlebars;
use indexmap::IndexMap;
use rusqlite::Connection;
use std::fmt::Write;
use serde::Serialize;
use std::{collections::HashMap, fmt::Write};
use crate::{monster_database::fetch_all_data, monster_structs::MonsterRepetableInitRow};
use crate::{
monster_database::fetch_all_data,
monster_structs::{
MonsterAllAttacks, MonsterFullAttack, MonsterRepetableInitRow, MonsterSingleAttack,
},
};
/// Load a template from a struct field into a `templates` collection.
///
@ -40,6 +47,10 @@ fn load_templates(config: &Config) -> Result<Handlebars<'_>> {
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, phase_row);
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);
Ok(templates)
}
@ -56,32 +67,32 @@ pub fn generate_monsters_tex(
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("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,
@ -95,11 +106,105 @@ pub fn generate_monsters_tex(
write!(out, "{}", templates.render("init_rows", init)?)?;
}
// write!(out, "{}", &config.monster.attacks_intro)?;
let all_attacks = MonsterAllAttacks::from_retrieved_data(&creature.attacks.attacks);
println!("{:#?}", all_attacks);
all_attacks.to_tex(&templates, config)?;
write!(out, "{}", &config.monster.attacks_intro)?;
// write!(out, "{}", &config.monster.attacks_end)?;
// write!(out, "{}", templates.render("intent_table", &creature.data)?)?;
write!(out, "{}", &config.monster.attacks_end)?;
write!(out, "{}", templates.render("intent_table", &creature.data)?)?;
println!("{}", out);
// println!("{}", out);
Ok(())
}
impl MonsterAllAttacks {
pub fn from_retrieved_data(original_data: &[MonsterSingleAttack]) -> MonsterAllAttacks {
let mut initial_phases: IndexMap<&String, Vec<&MonsterSingleAttack>> = IndexMap::new();
let mut phases: IndexMap<String, Vec<MonsterFullAttack>> = IndexMap::new();
// Intermediate split with hashmaps
for atk in original_data {
if let Some(values) = initial_phases.get_mut(&atk.phase) {
values.push(atk);
} else {
initial_phases.insert(&atk.phase, vec![atk]);
}
}
for (phase, phase_atks) in initial_phases.iter() {
let mut grouped_attacks: IndexMap<&Option<String>, Vec<&MonsterSingleAttack>> =
IndexMap::new();
let phase_name = phase.to_string();
phases.insert(phase_name.clone(), Vec::new());
for &atk in phase_atks {
if let Some(values) = grouped_attacks.get_mut(&atk.attack_group) {
values.push(atk);
} else {
grouped_attacks.insert(&atk.attack_group, vec![atk]);
}
}
for (group, atk) in grouped_attacks {
if group.is_some() {
let group_attack = MonsterFullAttack {
attacklist: atk.iter().map(|&v| v.clone()).collect(),
color: atk.first().unwrap().short_name.clone(),
description: atk.first().unwrap().effects.clone(),
};
phases.get_mut(&phase_name).unwrap().push(group_attack);
} else {
for single_atk in atk {
phases
.get_mut(&phase_name)
.unwrap()
.push(MonsterFullAttack {
attacklist: vec![single_atk.clone()],
color: single_atk.short_name.clone(),
description: single_atk.effects.clone(),
});
}
};
}
}
Self { phases }
}
}
#[derive(Serialize)]
struct Coloring<'a> {
color: &'a str,
}
impl MonsterAllAttacks {
pub fn to_tex(&self, templates: &Handlebars<'_>, config: &Config) -> Result<String> {
let mut out = String::new();
for (phase, list_full_attacks) in &self.phases {
// Print phase name
write!(out, "{}", templates.render("phase_row", phase)?)?;
for attack in list_full_attacks {
write!(out, "{}", config.monster.attack_before_repeat)?;
for sub_attack in &attack.attacklist {
let color = Coloring {
color: config
.monster
.color_table
.inner
.get(&attack.color)
.unwrap_or(&config.monster.default_color),
};
write!(out, "{}", templates.render("attack_color", &color)?)?;
write!(
out,
"{}",
templates.render("attack_repeatable_row", sub_attack)?
)?;
}
write!(
out,
"{}",
templates.render("attack_info_row", &list_full_attacks[0])?
)?;
}
// Print all attacks in that phase
println!("{}", out);
}
Ok(out)
}
}

View File

@ -12,6 +12,7 @@
//!
#![allow(dead_code)]
use indexmap::IndexMap;
use more_fields::FieldsAsSlice;
use serde::{Deserialize, Serialize};
@ -159,16 +160,16 @@ pub struct MonsterSingleAttack {
pub targetting: Option<String>,
/// Fatigue cost for activating the ability.
#[INTEGER]
pub cost_fatigue: Option<i64>,
pub cost_fatigue: Option<String>,
/// Action‑point cost (used in systems where actions and fatigue are separate).
#[INTEGER]
pub cost_action: Option<i64>,
pub cost_action: Option<String>,
/// Element or school that powers the ability.
#[TEXT]
pub element: Option<String>,
/// Damage dealt as a *fatigue* penalty (i.e. non‑instant death).
#[INTEGER]
pub damage_fatigue: Option<i64>,
pub damage_fatigue: Option<String>,
/// Regular textual description
#[TEXT]
pub damage_regular: Option<String>,
@ -353,3 +354,19 @@ impl Serialize for MonsterInitString {
)
}
}
/// The full list of all monster attacks
///
/// Split by phasing
#[derive(Debug)]
pub struct MonsterAllAttacks {
pub phases: IndexMap<String, Vec<MonsterFullAttack>>,
}
/// A single attack, grouping all sub attacks
/// Also extract extra info to allow easier insertions
#[derive(Serialize, Deserialize, Debug)]
pub struct MonsterFullAttack {
pub attacklist: Vec<MonsterSingleAttack>,
pub color: String,
pub description: String,
}

View File

@ -261,13 +261,14 @@ attacks_intro= '''\scriptsize{
'''
phase_row= '''
\SetHline{1}{0pt}
\SetCell[c=13]{white} PHASE 1 & & & & & & & & & & \\
\SetCell[c=13]{white} {{phase_name}} & & & & & & & & & & \\
'''
attack_repeatable_row= ''' \hline
\SetCell[r=2]{bg=ravred} & Thunder Bolt & THB & ATK & S & 2 & 2 & \symthunder & 3 & 18 25 32 & AB1 AB2 & 2 & 4 \\
attack_before_repeat=' \hline'
attack_color='\SetCell[r=2]{bg={{color}}}' # Very ugly hack, going to bed
attack_repeatable_row= ''' & {{name}} & {{short_name}} & {{atk_type}} & {{targetting}} & {{cost_fatigue}} & {{cost_action}} & {{element}} & {{damage_fatigue}} &{{damage_regular}} & {{effects}} & {{threshold_parry}} & {{threshold_dodge}} \\
'''
attack_info_row='''
& \SetCell[c=12]{j} \lipsum[7][1-6] & & & & & & & & & & \\
attack_info_row='''& \SetCell[c=12]{j} {{description}} & & & & & & & & & & \\
\hline
'''
attacks_end= ''' \end{tblr}
@ -288,3 +289,8 @@ Plan de combat & Graphique d'intentions \\
\end{tblr}
\vfill
'''
color_table='''
THB: \ravblue
TBD: \nocolor
'''
default_color='\blu'

@ -1 +1 @@
Subproject commit bdcf919c1066f5b175eb9c6896539fea72d03368
Subproject commit 211b22dbe327b66f0da9f5c5a780dd6ec00a88d8