// Workspace: config // File: config/src/graph.rs //! The inner config for graph module //! use clap::{Args, ValueEnum}; use phf::phf_map; use serde::{Deserialize, Serialize}; use std::{ops::Add, sync::LazyLock}; #[derive(Args, Debug, Clone)] /// The configuration struct for the Graph pub struct GraphConfig { /// Special target pub target: GraphTargetType, /// Alternative origin #[arg(short, long, default_value = "Images/Radar/radar.csv")] pub origin: String, /// Alternative destination #[arg(short, long, default_value = "Images/Radar")] pub destination: String, /// Alternative config to load (generate a new one with init) #[arg(short, long)] pub config: Option, /// Clean all the artefacts (including generated images) #[arg(short, long)] pub all: bool, } /// Link from user str input to the action to perform static STR_TO_GRAPH_TARGET_TYPE: phf::Map<&'static str, GraphTargetType> = phf_map! { "load" => GraphTargetType::Load, "generate" => GraphTargetType::Generate, "gen" => GraphTargetType::Generate, "remove" => GraphTargetType::Remove, "clean" => GraphTargetType::Remove, "init" => GraphTargetType::Init, }; /// Help listing all the actions availables static HELP_STR_TO_GRAPH: LazyLock = LazyLock::new(|| { let targets = STR_TO_GRAPH_TARGET_TYPE .keys() .map(|v| v.to_string()) .collect::>(); targets.join(", ").to_string() }); #[derive(ValueEnum, Debug, Clone)] /// All target type pub enum GraphTargetType { /// Load graph data from the classes Load, /// Make all graphs Generate, /// Clean all graphs Remove, /// Initialize the connfig Init, } impl From<&str> for GraphTargetType { fn from(value: &str) -> Self { if let Some(target) = STR_TO_GRAPH_TARGET_TYPE.get(&value.to_lowercase()).cloned() { target } else { panic!( "Invalid target {}. The target available are : [{}]", value, *HELP_STR_TO_GRAPH ) } } } /// The named categories to save on file #[derive(Default, Debug, Deserialize, Serialize)] pub struct FinalClassRadar { /// A name to identify the categories #[serde(rename = "Classe")] pub name: String, /// The values of the different radar categories /// The ability to survive. #[serde(rename = "Survivabilité")] pub survivability: f64, /// The ability to deal damage. #[serde(rename = "Dégats")] pub damage: f64, // /// The ability to move. // Mobility is merged with survivability & QoL // #[serde(rename = "Mobilité")] // pub mobility: f64, // /// The ability to inflict state alterations. // Altérations is now merged with damage // #[serde(rename = "Altérations")] // pub alterations: f64, /// The ability to provide support. #[serde(rename = "Support")] pub support: f64, /// The ability to inflict crowd control. #[serde(rename = "C.C")] pub cc: f64, // /// The ability to improve quality of life. // QoL is part of complexity // #[serde(rename = "QoL")] // pub qol: f64, /// The armor break of the class #[serde(rename = "Brise-Armure")] pub armorbreak: f64, /// The complexity to play the class #[serde(rename = "Complexité")] pub complexity: f64, // / The class complexity } /// All the categories to load from the tables #[derive(Default, Debug, Deserialize, Serialize)] pub struct LoadedClassRadar { /// The ability to survive. pub survivability: f64, /// The ability to deal damage. pub damage: f64, /// The ability to move. pub mobility: f64, /// The ability to inflict state alterations. pub alterations: f64, /// The ability to break armor. pub armorbreak: f64, /// The ability to provide support. pub support: f64, /// The ability to inflict crowd control. pub cc: f64, /// The ability to improve quality of life. pub qol: f64, /// The class complexity pub complexity: f64, } /// All the categories to load from the tables #[derive(Deserialize, Clone, Debug)] pub struct RawRow { /// The name of a technique. pub technique: String, /// The level or rank of a technique pub niveau: String, /// The type of technique, such as Actif or Exclusif. pub technique_type: String, /// The blood cost for this technique. pub cout_blood: String, /// The gauge cost for this technique. pub cout_jauge: String, /// A brief description of the effect or outcome of using this technique. pub effet: String, /// A indicative column for notes pub indicative: String, /// The ability to provide support. pub support: String, /// The ability to deal damage. pub damage: String, /// The ability to survive. pub survivability: String, /// The ability to move. pub mobility: String, /// The ability to inflict crowd control. pub cc: String, /// The ability to inflict state alterations. pub alterations: String, /// The ability to improve quality of life. pub qol: String, /// The ability to break armor. pub armorbreak: String, /// The complexity of the skill pub complexity: String, } impl From for LoadedClassRadar { fn from(value: RawRow) -> Self { Self { survivability: value.survivability.parse().unwrap_or(0.0), damage: value.damage.parse().unwrap_or(0.0), mobility: value.mobility.parse().unwrap_or(0.0), alterations: value.alterations.parse().unwrap_or(0.0), support: value.support.parse().unwrap_or(0.0), cc: value.cc.parse().unwrap_or(0.0), qol: value.qol.parse().unwrap_or(0.0), armorbreak: value.armorbreak.parse().unwrap_or(0.0), complexity: value.complexity.parse().unwrap_or(0.0), } } } impl Add for LoadedClassRadar { type Output = Self; fn add(self, rhs: Self) -> Self::Output { Self { survivability: self.survivability + rhs.survivability, damage: self.damage + rhs.damage, mobility: self.mobility + rhs.mobility, alterations: self.alterations + rhs.alterations, support: self.support + rhs.support, cc: self.cc + rhs.cc, qol: self.qol + rhs.qol, armorbreak: self.armorbreak + rhs.armorbreak, complexity: self.complexity + rhs.complexity, } } } impl FinalClassRadar { /// A very wastful (but simple) way to only add the max value pub fn find_max(self, rhs: &Self) -> Self { // Self { // survivability: self.survivability.max(rhs.survivability), // damage: self.damage.max(rhs.damage), // mobility: self.mobility.max(rhs.mobility), // alterations: self.alterations.max(rhs.alterations), // support: self.support.max(rhs.support), // cc: self.cc.max(rhs.cc), // qol: self.qol.max(rhs.qol), // armorbreak: self.armorbreak.max(rhs.armorbreak), // name: self.name, // } Self { name: self.name, survivability: self.survivability.max(rhs.survivability), damage: self.damage.max(rhs.damage), support: self.support.max(rhs.support), cc: self.cc.max(rhs.cc), armorbreak: self.armorbreak.max(rhs.armorbreak), complexity: self.complexity.max(rhs.complexity), } } /// Create a class from a loaded categories pub fn from_radar_with_name(name: String, categorie: LoadedClassRadar) -> Self { // Self { // name, // survivability: categorie.survivability, // damage: categorie.damage, // mobility: categorie.mobility, // alterations: categorie.alterations, // support: categorie.support, // cc: categorie.cc, // qol: categorie.qol, // armorbreak: categorie.armorbreak, // } Self { name, survivability: (categorie.survivability + categorie.mobility / 2.) / 1.5, damage: (categorie.damage + categorie.alterations) / 2., support: categorie.support, cc: categorie.cc, armorbreak: categorie.armorbreak, complexity: (categorie.complexity), } } /// A default value for accumulation pub fn default_for_acc() -> FinalClassRadar { Self { name: "Max".to_owned(), ..Default::default() } } }