From 8a2114da74d191467f45b764a962317f7462920a Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sun, 23 Feb 2025 06:53:00 +0100 Subject: [PATCH] More cleanup on the scenarii impls --- .ignore | 1 + weaponry/helpers/workflow.md | 23 ------------------- weaponry/src/interfaces.rs | 9 ++++++-- .../equipement_advanced_repr.rs | 16 ++++++++----- .../weaponry_structs/equipement_scenario.rs | 2 +- 5 files changed, 19 insertions(+), 32 deletions(-) delete mode 100644 weaponry/helpers/workflow.md diff --git a/.ignore b/.ignore index 8e062ad..523ea06 100644 --- a/.ignore +++ b/.ignore @@ -1 +1,2 @@ *.drawio +*.db diff --git a/weaponry/helpers/workflow.md b/weaponry/helpers/workflow.md deleted file mode 100644 index e253452..0000000 --- a/weaponry/helpers/workflow.md +++ /dev/null @@ -1,23 +0,0 @@ -# TO-Impl List - - Initial Object Representation - - Final Object Representation - - -# Workflow - A B C -Database -> -> -> Balancing data - -> Exported data - -# Description - - A : Use structs defines in weaponry_structs - : impl From for all weapon parts - - B : Every part can be converted to a weapon(ish) - : Use the correct solver to add all parts - - C1 : Use the traits to generate the tex data - - -# Strategy -Since the structs will become more than just weapons but will become craft afterwards, polymorphism is the key - -The creation algorithm will pick a Strategy depending on the user's choice and build a final weapon depending on it -The creation will implement an iterator to go with itertools / rayon ? diff --git a/weaponry/src/interfaces.rs b/weaponry/src/interfaces.rs index 44b93ee..9847d68 100644 --- a/weaponry/src/interfaces.rs +++ b/weaponry/src/interfaces.rs @@ -160,10 +160,15 @@ pub trait ToAnalysis { where T: FnMut(&Self::InnerData, &Self::InnerData) -> std::cmp::Ordering; + /// Apply a filter to the inner data + /// + /// Careful this filter will consume the original data to avoir reallocating + fn inner_filter(self, closure: T) -> Self + where + T: FnMut(&Self::InnerData) -> bool; + /// Write as html fn write_html(&self, path: &str) -> Result<(), FatalEquipementError>; - - // TODO: Add sorting methods as no analysis can be done without filtering and sorting } /// A generic database+connection, handling all the deserialization of the inner types diff --git a/weaponry/src/weaponry_structs/equipement_advanced_repr.rs b/weaponry/src/weaponry_structs/equipement_advanced_repr.rs index 5e73461..ea8cf36 100644 --- a/weaponry/src/weaponry_structs/equipement_advanced_repr.rs +++ b/weaponry/src/weaponry_structs/equipement_advanced_repr.rs @@ -85,6 +85,15 @@ impl ToAnalysis for RefinedEquipementList { self.inner.sort_by(closure) } + fn inner_filter(self, closure: T) -> Self + where + T: FnMut(&RefinedEquipement) -> bool, + { + Self { + inner: self.inner.into_iter().filter(closure).collect::>(), + } + } + // TODO[3]: Consider wether the naming should be a parameter, // or a config should be given or if the scenario should be fed again the Refined and ... fn write_html(&self, save_path: &str) -> Result<(), FatalEquipementError> { @@ -93,10 +102,6 @@ impl ToAnalysis for RefinedEquipementList { let initial_chart: Chart = initial_chart("Damage for all cross-gen products"); - // TODO[!]: Add sorting - // data.inner - // .sort_by(|a, b| a.advanced.dps_safe.total_cmp(&b.advanced.dps_safe)); - add_field_to_chart!( self, initial_chart, @@ -133,8 +138,7 @@ impl From for RefinedEquipementList { } } -// #[cfg(test)] -// Used in exemples +// #[cfg(test)] // Used in exemples impl Default for RefinedEquipementList { fn default() -> Self { let eq = InitialEquipementList::from_vectored(vec![Equipement::default(); 10]); diff --git a/weaponry/src/weaponry_structs/equipement_scenario.rs b/weaponry/src/weaponry_structs/equipement_scenario.rs index 4e180cb..7098313 100644 --- a/weaponry/src/weaponry_structs/equipement_scenario.rs +++ b/weaponry/src/weaponry_structs/equipement_scenario.rs @@ -48,7 +48,7 @@ pub struct CrossRecipeScenario { impl CrossRecipeScenario { /// Automatically deserialize into an equipement // TODO: Add to trait - // TODO: Add an optionnal filter + // TODO: Add an optionnal initial filter ? fn deserde_into_equipement( &self, name: &str,