ravenous-tools/src/table_structs.rs

122 lines
3.5 KiB
Rust

//! Holds all the data structures away from the main routine
use clap::Args;
use phf::phf_map;
use regex::Regex;
use serde::Deserialize;
use std::fmt::Debug;
use regex_static::once_cell::sync::Lazy;
#[derive(Deserialize)]
/// The Craft configs
pub(crate) struct Craft {
/// The food header string formatter
pub(crate) header_food: String,
/// The alchemy header string formatter
pub(crate) header_alchemy: String,
/// The forge header string formatter
pub(crate) header_forge: String,
/// The mtrap header string formatter
pub(crate) header_mtrap: String,
/// The weapons header string formatter
pub(crate) header_weapons: String,
/// The armors header string formatter
pub(crate) header_armors: String,
/// The gadgets header string formatter
pub(crate) header_gadgets: String,
/// The potions header string formatter
pub(crate) header_potions: String,
/// The traps header string formatter
pub(crate) header_traps: String,
/// The table end string formatter
pub(crate) end: String,
}
/// Configuration options for processing TSV files and generating LaTeX tables.
#[derive(Debug, Args)]
pub(crate) struct TableArgs {
/// A boolean indicating whether to generate LaTeX code and write it to an output file
/// (if true) or just print the generated code to stdout
#[arg(short)]
pub export: bool,
/// The kind of tables to operate on: classes, craft or files followed by a list of files
pub kind: TableGenerationTarge,
/// A vector of strings representing the names of TSV files to process.
pub filenames: Vec<String>,
}
/// An enumeration representing different target types.
#[derive(Debug, Clone)]
pub enum TableGenerationTarge {
/// Processes all classes
Classes,
/// Processes all the craft tables
Craft,
/// Processes only the given files
Files,
}
/// A mapping of string representations to target types.
static STR_TO_TARGET: phf::Map<&'static str, TableGenerationTarge> = phf_map! {
"classes" => TableGenerationTarge::Classes,
"craft" => TableGenerationTarge::Craft,
"files" => TableGenerationTarge::Files,
};
/// All the type of tsv that can be processed by the program
// #[enum_dispatch]
#[derive(Clone)]
pub enum TableTargets {
/// A class tsv
Classes,
/// Foods tsv
Food,
/// Alchemy tsv
Alchemy,
/// Forge tsv
Forge,
/// MPieges tsv
MPieges,
/// Weapons tsv
Weapons,
/// Armors tsv
Armors,
/// Gadgets tsv
Gadgets,
/// Potions tsv
Potions,
/// Traps tsv
Traps,
}
/// A mapping of string names to target types.
pub(crate) static STR_TO_TARGET_FULL: phf::Map<&'static str, TableTargets> = phf_map! {
"cls" => TableTargets::Classes,
"fud" => TableTargets::Food,
"alc" => TableTargets::Alchemy,
"frg" => TableTargets::Forge,
"mpi" => TableTargets::MPieges,
"wpn" => TableTargets::Weapons,
"arm" => TableTargets::Armors,
"gdg" => TableTargets::Gadgets,
"pot" => TableTargets::Potions,
"trp" => TableTargets::Traps,
};
/// The regex for finding and replacing all stars with a custom DD
pub(crate) static RE: Lazy<Regex> = regex_static::lazy_regex!(r"★+");
impl From<&str> for TableGenerationTarge {
fn from(value: &str) -> Self {
if let Some(target) = STR_TO_TARGET.get(value).cloned() {
target
} else {
panic!(
"Only the following target can be used: {:?}",
STR_TO_TARGET.keys()
)
}
}
}