80 lines
2.7 KiB
Rust
80 lines
2.7 KiB
Rust
// 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::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();
|
|
|
|
match args.sort.as_str() {
|
|
"max_per_turn" => refined_list.inner_sort(sort_by!(max_damage_per_turn)),
|
|
"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)),
|
|
// "id" => refined_list.inner_sort(|a, b| a.inner.id[0].cmp(&b.inner.id[0])), // It's actually the natural sorted way
|
|
_ => (),
|
|
}
|
|
|
|
// 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<String>,
|
|
/// 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<usize>,
|
|
/// 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")))
|
|
);
|
|
}
|