ravenous-tools/crates/config/src/monsters.rs

168 lines
4.2 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Workspace: config
// File: config/src/monsters.rs
//! The inner config for monster module
//!
#![allow(dead_code)]
use anyhow::Result;
use clap::{Args, ValueEnum};
use indexmap::IndexMap;
use serde::{Deserialize, Deserializer};
#[derive(Args, Debug, Clone)]
/// The configuration struct for the Graph
pub struct MonsterConfig {
/// Special target
pub target: MonsterTarget,
/// A special export path
#[arg(long, default_value = "./Bestiaire/")]
pub destination: String,
/// Database to load from
#[arg(short, long, default_value = "./ravenous_databases/monsters.db")]
pub database: String,
/// Export the full monsters as full_bestiaire.tex
#[arg(long, default_value_t = false)]
pub master: bool,
/// Export the player monsters as player_bestiaire.tex
#[arg(long, default_value_t = false)]
pub player: bool,
/// Export both
#[arg(long, default_value_t = false)]
pub all: bool,
// /// Clean all the artefacts (including generated images)
// #[arg(short, long)]
// pub all: bool,
}
#[derive(ValueEnum, Debug, Clone)]
/// The action to execute
pub enum MonsterTarget {
// /// Clean the generated monsters directory
// Clean,
/// Generate the monster list
Export,
// /// Show useful data
// Show,
}
/// 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 {
/// Header of the page (image + basic attributes).
pub intro: String,
/// Body‑parts section header.
pub body_parts_intro: String,
/// One row of the body‑parts table.
pub body_parts_row: String,
/// Body‑parts table footer.
pub body_parts_end: String,
/// Rewards section header (the table that lists each reward).
pub rewards_row: String,
/// 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,
/// 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,
/// Footer of the attacks section.
pub attacks_end: String,
/// 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,
/// Row that contains additional information for an attack.
pub attack_info_row: String,
/// 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(),
})
}