// Workspace: weaponry // File: examples/usage_scenario.rs //! Test use case of a scenario //! //! use clap::Parser; use std::path::Path; use weaponry::interfaces::ToAnalysis; use weaponry::sort_by; use weaponry::sort_by_cat_then; use weaponry::weaponry_structs::RefinedEquipement; // TODO : All of these should likely be in the prelude if used like this use weaponry::weaponry_structs::CrossRecipeScenario; use weaponry::weaponry_structs::equipement_scenario::ConfigEquipementScenario; use weaponry::{ interfaces::{Reportable, Scenario, ToCSV}, weaponry_structs::RefinedEquipementList, }; // use weaponry::interfaces:: fn main() { let args = CLIArgs::parse(); let save_path = args.path.unwrap_or("data/first_data".into()); let scenarios = CrossRecipeScenario::new_with_config(ConfigEquipementScenario { table_name: "Equipements".into(), db_path: "./databases/weapons.db".into(), shape: (!args.no_shapes).then_some(()), materials: args.materials, nature: (!args.no_natures).then_some(()), finishing: args.finishing.then_some(()), }) .unwrap(); let mut refined_list = scenarios .generate_refined_recipes() .unwrap() // .inner_filter(|e| (e.advanced.max_damage_per_attack > 0.)) .inner_filter(|e| { e.inner.macro_category.as_ref().is_some_and(|v| { !matches!(v, weaponry::weaponry_structs::WeaponMacroCategory::Shields) && !matches!(v, weaponry::weaponry_structs::WeaponMacroCategory::Armor) }) }); // TODO[!]: Have an enum match args.sort.as_str() { "avg_huge" => refined_list.inner_sort(sort_by!(avg_damage_single_huge_hit)), "avg_safe" => refined_list.inner_sort(sort_by!(avg_damage_2a_safe)), "max_armor" => refined_list.inner_sort(sort_by!(armor_break_per_attack)), "cat+avg" => refined_list.inner_sort(sort_by_cat_then!(avg_damage_2a_safe)), _ => (), } // if args.html_export{} refined_list.write_html(&save_path).unwrap(); // if args.csv_export{} // export_as_csv(&refined_list, save_path); } #[derive(Parser, Debug)] /// Basic cli pub struct CLIArgs { /// The path to save to. pub path: Option, /// Wether to generate shapes #[arg(short('S'), long, default_value_t)] pub no_shapes: bool, /// Wether to generate materials #[arg(short, long)] pub materials: Option, /// Wether to generate all natures #[arg(short('N'), long)] pub no_natures: bool, /// Wether to generate all finishing #[arg(short, long, default_value_t = false)] pub finishing: bool, #[arg(long, default_value_t = String::from("safe"))] pub sort: String, } #[allow(dead_code)] fn export_as_csv(refined_list: &RefinedEquipementList, save_path: &str) { println!("{}", refined_list.get_report(Some("Refined List"))); println!( "Saved initial data as {}.html: {:?}", save_path, refined_list.write_csv(Path::new(&format!("{save_path}.csv"))) ); }