Silly bug on one macro, filter corrected and macroified

This commit is contained in:
Dandaedre 2025-02-23 21:50:57 +01:00
parent 21618a8782
commit cb6c7ebc2a
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
10 changed files with 195 additions and 138 deletions

View File

@ -5,7 +5,9 @@
//!
use clap::Parser;
use std::path::Path;
use weaponry::filter_by;
use weaponry::interfaces::ToAnalysis;
use weaponry::weaponry_structs::RefinedEquipement;
// TODO : All of these should likely be in the prelude if used like this
use weaponry::weaponry_structs::CrossRecipeScenario;
@ -27,8 +29,9 @@ fn main() {
finishing: args.finishing.then_some(()),
})
.unwrap();
let mut refined_list = scenarios.generate_refined_recipes().unwrap();
refined_list.inner_sort(|a, b| a.advanced.avg_dps_safe.total_cmp(&b.advanced.avg_dps_safe));
refined_list.inner_sort(filter_by!(max_damage_per_action));
// if args.html_export{}
refined_list.write_html(&save_path).unwrap();

View File

@ -61,9 +61,19 @@ macro_rules! add_field_to_chart {
.series(
charming::series::Line::new()
.data($table_names)
.name(stringify!($table_names)), // .line_style(LineStyle::new().color("paleblue")),
.name(stringify!($table_names)),
);
)*
let $chart = $chart.legend(
charming::component::Legend::new()
.left(10)
.top("middle")
.orient(charming::element::Orient::Vertical)
.data(vec![
$(stringify!($table_names),)*
]),
);
}
}
@ -75,18 +85,6 @@ pub fn initial_chart(chart_name: &str) -> charming::Chart {
.text(chart_name)
.left("center"),
)
.legend(
charming::component::Legend::new()
.left(10)
.top("middle")
.orient(charming::element::Orient::Vertical)
.data(vec![
"dps_safe",
"max_damage_per_action",
"max_damage_per_turn",
"armor_break_per_turn",
]),
)
.tooltip(charming::element::Tooltip::new().trigger(charming::element::Trigger::Axis))
.data_zoom(
charming::component::DataZoom::new()

View File

@ -156,6 +156,7 @@ pub trait ToAnalysis {
type InnerData;
/// Sort the inner data with a given closure
// TODO[4]: Consider changing the signature to (self) -> Self, to match the filter
fn inner_sort<T>(&mut self, closure: T)
where
T: FnMut(&Self::InnerData, &Self::InnerData) -> std::cmp::Ordering;
@ -163,6 +164,8 @@ pub trait ToAnalysis {
/// Apply a filter to the inner data
///
/// Careful this filter will consume the original data to avoir reallocating
// TODO[6]: Consider implementing base filters as a struct to allow implementation / choice to be polymorphic
// : Maybe more downsides over a dynamic choosing by default
fn inner_filter<T>(self, closure: T) -> Self
where
T: FnMut(&Self::InnerData) -> bool;

View File

@ -75,6 +75,17 @@ impl ToTex for RefinedEquipementList {
}
}
#[macro_export]
/// A simple macro to sort the inner advanced field by a specific field
// TODO[6] find a way to not have to import the refinedequipement
macro_rules! filter_by {
($field:ident) => {
|a: &RefinedEquipement, b: &RefinedEquipement| {
a.advanced.$field.total_cmp(&b.advanced.$field)
}
};
}
impl ToAnalysis for RefinedEquipementList {
type InnerData = RefinedEquipement;
@ -110,13 +121,15 @@ impl ToAnalysis for RefinedEquipementList {
dps_safe # f64,
max_damage_per_action # f64,
armor_break_per_turn # f64,
dps_huge # f64,
),
|ref_equipement| {
(
&ref_equipement.advanced.display_name,
ref_equipement.advanced.avg_dps_safe,
ref_equipement.advanced.max_damage_per_action,
ref_equipement.advanced.damage_per_turn,
ref_equipement.advanced.armor_break_per_turn,
ref_equipement.advanced.avg_huge_hit,
)
}
);

View File

@ -11,8 +11,11 @@ use strum::Display;
#[cfg_attr(test, derive(PartialEq))]
/// The special category, a vec of string, for display purposes only
// TODO: avoid pub make an impl ?
pub struct SpecialCategory(pub Vec<String>);
pub struct SpecialField(pub Vec<String>);
// TODO[6]: This cross target specification existed for combines weapons,
// : that do not really need any balancing and only rendering
// : therefore migh need cleanup
/// The kind of target this nature can apply to
#[derive(Clone)]
pub enum NatureTarget {
@ -34,22 +37,6 @@ pub enum PhysicalDamageType {
Pierce,
}
// impl TryFrom<&str> for PhysicalDamageType {
// type Error = FatalEquipementError;
// fn try_from(value: &str) -> Result<Self, Self::Error> {
// match value.to_ascii_lowercase().as_str() {
// "blunt" => Ok(Self::Blunt),
// "slash" => Ok(Self::Slash),
// "pierce" => Ok(Self::Pierce),
// _ => Err(FatalEquipementError::Conversion {
// origin_type: std::any::type_name::<Self>().to_owned(),
// data: value.to_string(),
// }),
// }
// }
// }
/// Weapon damage, combining the base weapon damage type and it's level
///
/// Signifying wether the damage is pure or [secondary] or [[tertiary]]
@ -82,34 +69,6 @@ impl Display for DamageType {
}
}
// impl TryFrom<&str> for DamageType {
// type Error = FatalEquipementError;
// fn try_from(value: &str) -> Result<Self, Self::Error> {
// let re = regex::Regex::new(r"(?<tertiary>\[\[\w+\]\])|(?<secondary>\[\w+\])|(?<pure>\w+)")
// .unwrap();
// let v = value
// .split(",")
// .map(
// |v| {
// let groups = re.captures(v).unwrap();
// *groups
// }, // match v.trim() {
// // _ => Ok(DamageMod::Primary(PhysicalDamageType::Blunt)),
// // }
// )
// .collect::<Result<Vec<DamageMod>, FatalEquipementError>>();
// Ok(Self(v?))
// }
// }
// impl FromSql for DamageType {
// fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult<Self> {
// Ok(DamageType(vec![DamageMod::Secondary(
// PhysicalDamageType::Pierce,
// )]))
// }
// }
impl Add for DamageType {
type Output = Self;
@ -125,7 +84,8 @@ impl Add for DamageType {
// #[cfg_attr(test, derive(PartialEq))]
pub enum WeaponCategory {
Exotic,
Dagger,
// HeavyExotic ?
Dagger, // Light sword ? Kill it tbh
Claws,
Blade,
Haroth,
@ -143,72 +103,8 @@ pub enum WeaponCategory {
// Shield,
}
// TODO[4]: Have a final weapon category tied to the speciality, if any appliable to the character
// : Since this is not needed for balencing, this will be left alone for a while
// impl WeaponCategory {
// fn from_category_and_size(macro_category: &WeaponBaseShape, size: &WeaponBaseSize) -> Self {
// match (macro_category, size) {
// (WeaponBaseShape::Axe, WeaponBaseSize::SuperHeavy) => Self::Kahml,
// (WeaponBaseShape::Blade, WeaponBaseSize::SuperHeavy) => Self::Haroth,
// (WeaponBaseShape::Hammer, WeaponBaseSize::SuperHeavy) => Self::Rhodarak,
// (WeaponBaseShape::Claws, WeaponBaseSize::SuperHeavy) => Self::Landscapper,
// (WeaponBaseShape::Staves, WeaponBaseSize::SuperHeavy) => Self::Landscapper,
// (WeaponBaseShape::Bow, WeaponBaseSize::SuperHeavy) => Self::Bow,
// (WeaponBaseShape::Crossbow, WeaponBaseSize::SuperHeavy) => Self::Crossbow,
// (WeaponBaseShape::Cannon, WeaponBaseSize::SuperHeavy) => Self::Cannon,
// (WeaponBaseShape::Exotic, WeaponBaseSize::SuperHeavy) => Self::Exotic,
// }
// }
// }
// TODO: This is the real initial category
/// The list of initial weapon meta categories
// TODO[!]: This enum should only include Weapons, Shields, Armors and no <BaseShape>
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
#[derive(Clone, Debug, Display, Deserialize, Serialize, strum::EnumString)]
pub enum WeaponMacroCategory {
Staves,
Blunt,
Slash,
Ranged,
Armor,
Shields,
Exotic,
/// A custom weapon category, only used by the target
// TODO: Get rid of this category and make a custom category for target
Weapons,
/// A custom none category, used to forbid a part to be cast upon of from
// TODO: Check the soundness of this implementation
None,
}
/// The Base Shape of the weapon, used to infer the final category of the weapon
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
#[derive(Clone, Debug, Display, Deserialize, Serialize, strum::EnumString)]
pub enum WeaponBaseShape {
Staves,
Blunt,
Slash,
Ranged,
Armor,
Shields,
Exotic,
// TODO[!]: Check the soundness of this
None,
}
/// The Base Size of the weapon, used to infer the final category of the weapon
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
#[derive(Clone, Debug, Display, Deserialize, Serialize, strum::EnumString)]
pub enum WeaponBaseSize {
Light,
Medium,
Heavy,
SuperHeavy,
}
// TODO: This is only needed as long as we dont have a special category for the target
// TODO[!]: This is only needed as long as we dont have a special category for the target
// TODO[!]: This part should be handled by a category filter instead, filtering Shape on Shape
impl PartialEq for WeaponMacroCategory {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
@ -245,3 +141,146 @@ mod test {
unimplemented!()
}
}
// TODO[!]: Implement all the soundness below
/// The final enum of all categories to be given to the character sheet
///
/// This enum is only created at the end of the refining process with all the given information
/// Note that some weapons might not be created or might be too niche to be created by the recipes
/// however the full cross implementation should cover all weapons or reconsider the validity of said implementation
#[allow(dead_code, clippy::missing_docs_in_private_items)]
pub enum FinalWeaponCategory {
Hast(HastSpecialties),
Slash(SlashSpecialties),
Blunt(BluntSpecialties),
Collosal(ColossalSpeciaties),
Ranged(RangedSpecialties),
Throw(ThrowSpecialties),
}
#[allow(dead_code, clippy::missing_docs_in_private_items)]
pub enum HastSpecialties {
Lance,
Staff,
}
#[allow(dead_code, clippy::missing_docs_in_private_items)]
pub enum SlashSpecialties {
Sword,
#[deprecated]
Dagger,
Axe,
Claws,
}
#[allow(dead_code, clippy::missing_docs_in_private_items)]
pub enum BluntSpecialties {
Hammer,
Improvised,
}
#[allow(dead_code, clippy::missing_docs_in_private_items)]
pub enum ColossalSpeciaties {
Rhodarak,
Haroth,
Kahml,
Landscapper,
}
#[allow(dead_code, clippy::missing_docs_in_private_items)]
pub enum RangedSpecialties {
Bow,
Crossbow,
Cannon,
}
#[allow(dead_code, clippy::missing_docs_in_private_items)]
pub enum ThrowSpecialties {
Light,
Lances,
Improvised,
}
// TODO[4]: Have a final weapon category tied to the speciality, if any appliable to the character
// : Since this is not needed for balencing, this will be left alone for a while
// impl FinalWeaponCategory{
// fn from_category_and_size(macro_category: &WeaponBaseShape, size: &WeaponBaseSize) -> Self {
// match (macro_category, size) {
// (WeaponBaseShape::Axe, WeaponBaseSize::SuperHeavy) => Self::Colossal(..),
// }
// }
// }
// TODO[!]: This is the real initial category for the shapes, as only shapes should be described by shapes
// TODO[!]: Shapes should also have a generic category of course (weapons/armor/shield) to help the filter to apply to it
/// The list of initial weapon meta categories
// TODO[!]: This enum should only include Weapons, Shields, Armors and no <BaseShape>
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
#[derive(Clone, Debug, Display, Deserialize, Serialize, strum::EnumString)]
pub enum WeaponMacroCategory {
Staves,
Blunt,
Slash,
Ranged,
Armor,
Shields,
Exotic,
/// A custom weapon category, only used by the target
// TODO: Get rid of this category and make a custom category for target
Weapons,
/// A custom none category, used to forbid a part to be cast upon of from
// TODO: Check the soundness of this implementation
None,
}
// TODO[!] : This is the corrected real initial shape
// : This should replace the used MacroCategory
/// The Base Shape of the weapon, used to infer the final category of the weapon
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
#[derive(Clone, Debug, Display, Deserialize, Serialize, strum::EnumString)]
pub enum WeaponBaseShape {
Staves,
Blunt,
Slash,
Ranged,
Armor,
Shields,
Exotic,
// TODO[!]: Check the soundness of this
None,
}
// TODO[!]: While maybe not directly filling a field these categories should be inferred by the BaseShape for comparison
// [!]: However using a new column for this Section will greatly help in the Serde soundness and avoidance on over-reliance of implicit conversions
/// Specifies the exact nature of the weapon, used for generic filter mainly
#[allow(dead_code, clippy::missing_docs_in_private_items, missing_docs)]
pub enum EquipementSection {
Weapon,
Armor,
Shield,
}
// TODO[!]: Add this as a target and nature instead of the old Type
// : Remember it's the applied into that specify wether they can be applied not the other way around
/// Specifies the exact nature of the target this element can be applied to
#[allow(dead_code, clippy::missing_docs_in_private_items, missing_docs)]
pub enum EquipementFilter {
/// This element can only be applied to a specific category
Target(EquipementSection),
/// This element exists only for recipes or for export to tex, it cannot be auto-applied
NoTarget,
/// This element can be applied to any target
AnyTarget,
// /// This element can only be applied to a specific base shape
// TargetShape(WeaponBaseShape)
}
// TODO[!] : This part is initialized by the natures subtable and might be better of being a new column in the database
/// The Base Size of the weapon, used to infer the final category of the weapon
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
#[derive(Clone, Debug, Display, Deserialize, Serialize, strum::EnumString)]
pub enum WeaponBaseSize {
Light,
Medium,
Heavy,
SuperHeavy,
}

View File

@ -52,7 +52,7 @@ mod test {
use crate::{
interfaces::RecipeCollection,
weaponry_structs::{
DamageMod, DamageType, Equipement, InitialEquipementList, SpecialCategory,
DamageMod, DamageType, Equipement, InitialEquipementList, SpecialField,
equipement_fields::{PhysicalDamageType, WeaponMacroCategory},
equipement_structs::InnerEquipementStats,
},
@ -95,7 +95,7 @@ mod test {
range: 3,
agility_bonus: 4.,
macro_category: Some(WeaponMacroCategory::Staves),
special: SpecialCategory(vec!["zero".into()]),
special: SpecialField(vec!["zero".into()]),
damage_type: Some(DamageType(vec![DamageMod::Secondary(
PhysicalDamageType::Slash,
)])),
@ -108,7 +108,7 @@ mod test {
damage_type: Some(DamageType(vec![DamageMod::Primary(
PhysicalDamageType::Blunt,
)])),
special: SpecialCategory(vec!["one".into(), "two".into()]),
special: SpecialField(vec!["one".into(), "two".into()]),
..Default::default()
};
assert_eq!(
@ -120,7 +120,7 @@ mod test {
damage: 10,
range: 3,
macro_category: Some(WeaponMacroCategory::Staves),
special: SpecialCategory(vec!["zero".into(), "one".into(), "two".into()]),
special: SpecialField(vec!["zero".into(), "one".into(), "two".into()]),
damage_type: Some(DamageType(vec![
DamageMod::Secondary(PhysicalDamageType::Slash,),
DamageMod::Primary(PhysicalDamageType::Blunt,),

View File

@ -4,7 +4,7 @@
//!
use super::equipement_structs::InnerEquipementStats;
use crate::weaponry_structs::SpecialCategory;
use crate::weaponry_structs::SpecialField;
/// Add a new vector to a clone of a inner field
macro_rules! add_to_vec {
@ -66,7 +66,7 @@ impl std::ops::Add for &InnerEquipementStats {
}
}
impl std::ops::Add for SpecialCategory {
impl std::ops::Add for SpecialField {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {

View File

@ -8,7 +8,7 @@ use crate::interfaces::{FilterFunction, FilterFunctionType};
use more_fields::FieldsAsSlice;
use serde::{Deserialize, Serialize};
use super::{DamageType, SpecialCategory, WeaponCategory, equipement_fields::WeaponMacroCategory};
use super::{DamageType, SpecialField, WeaponCategory, equipement_fields::WeaponMacroCategory};
/// The final equipement list
///
@ -109,7 +109,7 @@ pub struct InnerEquipementStats {
/// The initial macro category, in turn combined with other stats it will describe a final category
pub(super) macro_category: Option<WeaponMacroCategory>, // TODO : This initial macro category fill as a final stat feed the final category
pub(super) target: Option<WeaponMacroCategory>, // TODO: This might be incorrect, to check
pub(super) special: SpecialCategory,
pub(super) special: SpecialField,
pub(super) action_cost: i8,
pub(super) reload_cost: Option<i8>, // Shouldn't it be Option ?
pub(super) range: i16, // Shoudln't it be Option ?
@ -186,7 +186,7 @@ impl Default for DatabaseEquipementStats {
damage_type: serde_json::to_string(&None::<DamageType>).unwrap(),
category: serde_json::to_string(&None::<WeaponMacroCategory>).unwrap(),
target: serde_json::to_string(&None::<WeaponCategory>).unwrap(),
special: serde_json::to_string(&SpecialCategory::default()).unwrap(),
special: serde_json::to_string(&SpecialField::default()).unwrap(),
reload_cost: serde_json::to_string(&None::<u8>).unwrap(),
rarity: 0,
cost: 0,

View File

@ -4,6 +4,7 @@
//! This list is imperative to allow several criterias to be looked up one after the other to gather as many points of data as possible
//!
//! It is mandatory that these points of interest link back to the original data by index and not by reference, to allow this operation to be thread safe
// TODO[3]: Consider deletion of this module and the associated view table
#![allow(dead_code)]

View File

@ -34,10 +34,10 @@ pub use equipement_structs::{Equipement, InitialEquipementList};
// All generic fields
// #[allow(unused_imports)]
pub use crate::weaponry_structs::equipement_advanced_repr::RefinedEquipementList;
pub use equipement_advanced_repr::RefinedEquipement;
pub use equipement_fields::PhysicalDamageType;
pub use equipement_fields::{
DamageMod, DamageType, NatureTarget, SpecialCategory, WeaponCategory, WeaponMacroCategory,
DamageMod, DamageType, NatureTarget, SpecialField, WeaponCategory, WeaponMacroCategory,
};
// Likely ? Final Re-Exports
pub use equipement_scenario::CrossRecipeScenario;