//! 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; // This config is can contain unconstructed code for compatibility purposes #[allow(dead_code)] #[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, /// The long table end string formatter pub(crate) end_long: String, /// The long sideways table end string formatter pub(crate) end_long_side: String, /// The no_headers table end string formatter pub(crate) end_empty: 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: TableGenerationTarget, /// A vector of strings representing the names of TSV files to process. pub filenames: Vec, } /// An enumeration representing different target types. #[derive(Debug, Clone)] pub enum TableGenerationTarget { /// Processes all classes Classes, /// Processes all the craft tables Craft, /// Processes only the given files Files, /// Processes all the known targets All, } /// A mapping of string representations to target types. static STR_TO_TARGET: phf::Map<&'static str, TableGenerationTarget> = phf_map! { "classes" => TableGenerationTarget::Classes, "craft" => TableGenerationTarget::Craft, "files" => TableGenerationTarget::Files, "all" => TableGenerationTarget::All, }; /// 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_static::lazy_regex!(r"★+"); impl From<&str> for TableGenerationTarget { 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() ) } } }