100 lines
3.1 KiB
Rust
100 lines
3.1 KiB
Rust
// Workspace: config
|
|
// File: config/src/tablegen.rs
|
|
//! Table generation structs
|
|
|
|
use clap::Args;
|
|
use phf::phf_map;
|
|
use serde::Deserialize;
|
|
use std::sync::LazyLock;
|
|
|
|
/// 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,
|
|
}
|
|
|
|
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: {}",
|
|
*HELP_STR_TO_TARGET_TABLES
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
/// 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,
|
|
};
|
|
|
|
/// A help of all the table targets to be built
|
|
static HELP_STR_TO_TARGET_TABLES: LazyLock<String> = LazyLock::new(|| {
|
|
let mut targets = STR_TO_TARGET
|
|
.keys()
|
|
.map(|v| v.to_string())
|
|
.collect::<Vec<String>>();
|
|
targets.sort();
|
|
targets.join(", ").to_string()
|
|
});
|
|
/// Configuration options for processing TSV files and generating LaTeX tables.
|
|
#[derive(Debug, Args)]
|
|
pub struct TableArgs {
|
|
/// Wether to export all files (if used), or output everything to stdout
|
|
#[arg(short)]
|
|
pub export: bool,
|
|
|
|
/// The kind of tables to operate on: classes, craft or files followed by a list of files
|
|
// #[arg(help = format!("The kind of tables to operate on : {}", "TODO: FIX"))]
|
|
#[arg(help = format!("The kind of tables to operate on : {}", *HELP_STR_TO_TARGET_TABLES))]
|
|
pub kind: TableGenerationTarget,
|
|
/// A vector of strings representing the names of TSV files to process.
|
|
pub filenames: Vec<String>,
|
|
}
|
|
|
|
// This config is can contain unconstructed code for compatibility purposes
|
|
#[allow(dead_code)]
|
|
#[derive(Deserialize)]
|
|
/// The Craft configs
|
|
pub struct Craft {
|
|
/// The food header string formatter
|
|
pub header_food: String,
|
|
/// The alchemy header string formatter
|
|
pub header_alchemy: String,
|
|
/// The forge header string formatter
|
|
pub header_forge: String,
|
|
/// The mtrap header string formatter
|
|
pub header_mtrap: String,
|
|
/// The weapons header string formatter
|
|
pub header_weapons: String,
|
|
/// The armors header string formatter
|
|
pub header_armors: String,
|
|
/// The gadgets header string formatter
|
|
pub header_gadgets: String,
|
|
/// The potions header string formatter
|
|
pub header_potions: String,
|
|
/// The traps header string formatter
|
|
pub header_traps: String,
|
|
/// The table end string formatter
|
|
pub end: String,
|
|
/// The long table end string formatter
|
|
pub end_long: String,
|
|
/// The long sideways table end string formatter
|
|
pub end_long_side: String,
|
|
/// The no_headers table end string formatter
|
|
pub end_empty: String,
|
|
}
|