From cb6c7ebc2ab5771c729837b42851006336b2d7d3 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sun, 23 Feb 2025 21:50:57 +0100 Subject: [PATCH] Silly bug on one macro, filter corrected and macroified --- weaponry/examples/usage_scenario.rs | 5 +- weaponry/src/export.rs | 24 +- weaponry/src/interfaces.rs | 3 + .../equipement_advanced_repr.rs | 15 +- .../src/weaponry_structs/equipement_fields.rs | 263 ++++++++++-------- .../weaponry_structs/equipement_impl_logic.rs | 8 +- .../weaponry_structs/equipement_impl_math.rs | 4 +- .../weaponry_structs/equipement_structs.rs | 6 +- .../src/weaponry_structs/equipement_views.rs | 1 + weaponry/src/weaponry_structs/mod.rs | 4 +- 10 files changed, 195 insertions(+), 138 deletions(-) diff --git a/weaponry/examples/usage_scenario.rs b/weaponry/examples/usage_scenario.rs index 62fa6a2..fd8b2f0 100644 --- a/weaponry/examples/usage_scenario.rs +++ b/weaponry/examples/usage_scenario.rs @@ -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(); diff --git a/weaponry/src/export.rs b/weaponry/src/export.rs index dea3e48..f0cd10d 100644 --- a/weaponry/src/export.rs +++ b/weaponry/src/export.rs @@ -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() diff --git a/weaponry/src/interfaces.rs b/weaponry/src/interfaces.rs index 9847d68..d33eee2 100644 --- a/weaponry/src/interfaces.rs +++ b/weaponry/src/interfaces.rs @@ -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(&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(self, closure: T) -> Self where T: FnMut(&Self::InnerData) -> bool; diff --git a/weaponry/src/weaponry_structs/equipement_advanced_repr.rs b/weaponry/src/weaponry_structs/equipement_advanced_repr.rs index ad6fd1a..6558dd6 100644 --- a/weaponry/src/weaponry_structs/equipement_advanced_repr.rs +++ b/weaponry/src/weaponry_structs/equipement_advanced_repr.rs @@ -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, ) } ); diff --git a/weaponry/src/weaponry_structs/equipement_fields.rs b/weaponry/src/weaponry_structs/equipement_fields.rs index 7e00926..1f6be28 100644 --- a/weaponry/src/weaponry_structs/equipement_fields.rs +++ b/weaponry/src/weaponry_structs/equipement_fields.rs @@ -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); +pub struct SpecialField(pub Vec); +// 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 { -// 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::().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 { -// let re = regex::Regex::new(r"(?\[\[\w+\]\])|(?\[\w+\])|(?\w+)") -// .unwrap(); -// let v = value -// .split(",") -// .map( -// |v| { -// let groups = re.captures(v).unwrap(); -// *groups -// }, // match v.trim() { -// // _ => Ok(DamageMod::Primary(PhysicalDamageType::Blunt)), -// // } -// ) -// .collect::, FatalEquipementError>>(); -// Ok(Self(v?)) -// } -// } -// impl FromSql for DamageType { -// fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult { -// 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 -#[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 +#[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, +} diff --git a/weaponry/src/weaponry_structs/equipement_impl_logic.rs b/weaponry/src/weaponry_structs/equipement_impl_logic.rs index ae5370c..c3da801 100644 --- a/weaponry/src/weaponry_structs/equipement_impl_logic.rs +++ b/weaponry/src/weaponry_structs/equipement_impl_logic.rs @@ -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,), diff --git a/weaponry/src/weaponry_structs/equipement_impl_math.rs b/weaponry/src/weaponry_structs/equipement_impl_math.rs index e6e376d..ab587fb 100644 --- a/weaponry/src/weaponry_structs/equipement_impl_math.rs +++ b/weaponry/src/weaponry_structs/equipement_impl_math.rs @@ -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 { diff --git a/weaponry/src/weaponry_structs/equipement_structs.rs b/weaponry/src/weaponry_structs/equipement_structs.rs index 15ceb05..e1fe186 100644 --- a/weaponry/src/weaponry_structs/equipement_structs.rs +++ b/weaponry/src/weaponry_structs/equipement_structs.rs @@ -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, // TODO : This initial macro category fill as a final stat feed the final category pub(super) target: Option, // 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, // 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::).unwrap(), category: serde_json::to_string(&None::).unwrap(), target: serde_json::to_string(&None::).unwrap(), - special: serde_json::to_string(&SpecialCategory::default()).unwrap(), + special: serde_json::to_string(&SpecialField::default()).unwrap(), reload_cost: serde_json::to_string(&None::).unwrap(), rarity: 0, cost: 0, diff --git a/weaponry/src/weaponry_structs/equipement_views.rs b/weaponry/src/weaponry_structs/equipement_views.rs index f217e98..a5c4ec4 100644 --- a/weaponry/src/weaponry_structs/equipement_views.rs +++ b/weaponry/src/weaponry_structs/equipement_views.rs @@ -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)] diff --git a/weaponry/src/weaponry_structs/mod.rs b/weaponry/src/weaponry_structs/mod.rs index 5a09399..278d1d3 100644 --- a/weaponry/src/weaponry_structs/mod.rs +++ b/weaponry/src/weaponry_structs/mod.rs @@ -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;