From 01842fc64af485e40513f346927caec20d1edc5f Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Fri, 28 Feb 2025 03:49:35 +0100 Subject: [PATCH] Tries to simplify the impl process --- weaponry/databases/weapons.db | Bin 28672 -> 28672 bytes weaponry/src/interfaces.rs | 38 +++++++ .../equipement_advanced_repr.rs | 2 + .../equipement_advanced_tools.rs | 1 - .../equipement_impl_database.rs | 1 + .../weaponry_structs/equipement_impl_math.rs | 12 ++- .../weaponry_structs/equipement_scenario.rs | 95 +++++++++++++++--- .../weaponry_structs/equipement_structs.rs | 17 ++++ 8 files changed, 151 insertions(+), 15 deletions(-) diff --git a/weaponry/databases/weapons.db b/weaponry/databases/weapons.db index 935c5d509cbbec58b6521ac5954b0a40ed9c5bfb..fe13caa2ed9996a919db8ca7830a14cd56299b62 100644 GIT binary patch delta 679 zcmXw$Pe>F|9LL{#v$ONw?##R$YLa!)9kw8mmNojLhoCIUg0#Za7BwB+(Y1DG)!7wq z>LEN>n7%_4u}aiIs4V6ZNd$E$>S9y`ojlbcq6jo9u-h2Qu6em{8c_u=;@R^h}d zyb@80004=Hp9h?+s)fY|J-4Wg=sIrzf&QlJZYcDTZsV2I%1w+b+!3t+bb(g5T8&1> zCqa7@lx@dckU&T<)*#e%$Q9PJM8~)#Z4Oz-vqK}f(Lv|gqJ{nl9bE|7g-pha4X#*o z&bDG+)e&nn2W-nI*hX*8E;vR$$1P(y#_k%!9vrpI!kCe=cza~HV8y!jdY8_%afGOc zKnQ{SsKuBgU=Km#2&9D2WDeSfU9cR)W}EfU=6nI6(s*|*u|{D#`+P7m-i<&vy-dUE zBefgeh9^{@EGTV?Ccl)YzZu!}q-IU?Zec%QT)r6s{X@2?X-iBsq% zI)eo8T1@!f`Nn;5;l1Dp7z{y98u3W~FUum3Qcg-Dx`sEG#a^APWKuM&@7XV)SWCuq z(*Kszv?{9nLLQT=g3H09fp39gpqjiT zorK~i*pj|TSEZQ$p1)drEapVfH|;AE=7a|H11+K?3c_WWhu(9SKGJ{_X<+r)a@Np$7CA>s>9q?>?2b9+9?MK4 vcE7I;IdyF5a5;P0lVtu>)_r5gA#+j}-CwC4&^M_j3>LD(tj^4{%KqWMd{MaY delta 468 zcmZp8z}WDBae_4OYz77fb|7X0Vy1~2=8Us9CM@CSVdVb}6kuTI|IL@ZSwP?!ze-+d zPEIsXh*g&tBqPAUz`u;&jPEF4HlGmhcHRVD7M_)x1r_>v7$YYy^c7{}00L>z$%kZ2 zC(8(NZDx`E#I*UF{uh46kjby@r6bCi_?Pk<@$KV_=VM{?V))3rl-HH#H_tYnd>$R{ zhuqV-{kWcSP2qCoyvP~LDZ;UW!=C*Xdnr3F+X^-p*1N1dtU65Yj6WGyFqE-eVX0zK zVZOv%!z{tHcA}%i=8F#c{6dk8@(kkAAXhMQGBR>SWi~crW>N~yNi5D# z0{bZzM1s5o1dN+G0)Fy`GN~}AGc03flVg--?P2-FQp~@TznEW{?=lM;P Result where @@ -241,4 +247,36 @@ pub trait Scenario { /// Generate the final list type fn generate_refined_recipes(&self) -> Result; + + // /// Blanket implementation deserialising all element from the database into the initial inner list used by the scenario + // fn inital_list_from_database( + // &self, + // extra_sql_filter: Option, + // ) -> Result + // where + // T: TryFrom + From + Into, + // { + // // TODO: This likely has too high a complexity and should either be a blanket implementation + // // : or require the inner workings to implement methods to easily allow this deserialisation + // Ok(Self::InitialElementList::from_vectored( + // self.get_database() + // .serialize_vec_from_table::( + // &self.get_tablename(), + // Some(&format!("META_CATEGORY LIKE '{}'", name)), + // )? + // .into_iter() + // .map(|v| { + // InnerEquipementStats::try_from(v) + // .map(|w| T::from(w)) + // .map(|v| v.into()) + // }) + // .collect::, FatalEquipementError>>()?, + // )) + // } + + /// Retrieve a reference to the inner database + fn get_database(&self) -> &Self::DatabaseType; + + /// Retrieve A config + fn get_tablename(&self) -> &str; } diff --git a/weaponry/src/weaponry_structs/equipement_advanced_repr.rs b/weaponry/src/weaponry_structs/equipement_advanced_repr.rs index b9cfcf5..42253ea 100644 --- a/weaponry/src/weaponry_structs/equipement_advanced_repr.rs +++ b/weaponry/src/weaponry_structs/equipement_advanced_repr.rs @@ -55,6 +55,8 @@ pub struct RefinedEquipementList { impl RefinedList for RefinedEquipementList {} impl ToTex for RefinedEquipementList { fn to_tex(&self) -> String { + // TODO[!] : Export everything to one tsv + // : This export is only supposed to be the final export of a pseudo recipes book todo!() } } diff --git a/weaponry/src/weaponry_structs/equipement_advanced_tools.rs b/weaponry/src/weaponry_structs/equipement_advanced_tools.rs index ce947ba..b8b6333 100644 --- a/weaponry/src/weaponry_structs/equipement_advanced_tools.rs +++ b/weaponry/src/weaponry_structs/equipement_advanced_tools.rs @@ -21,7 +21,6 @@ use super::equipement_thin_types::Precision; /// - 2 turns safe attacks (5 dice, 50%p) /// - 1 turn highspeed/range hit (7 dice, 80% precision) /// - 4 turns normal damage (7 dice, 90% precision) -// TODO[!] Implementation pub(super) fn get_damage_with_simulation( value: &InnerEquipementStats, actions: Actions, diff --git a/weaponry/src/weaponry_structs/equipement_impl_database.rs b/weaponry/src/weaponry_structs/equipement_impl_database.rs index b4a6c7a..bc0dab3 100644 --- a/weaponry/src/weaponry_structs/equipement_impl_database.rs +++ b/weaponry/src/weaponry_structs/equipement_impl_database.rs @@ -24,6 +24,7 @@ pub struct EquipementDatabase { } impl RecipeDatabase for EquipementDatabase { + // TODO[:] : This element is partly responsible for the difficulty simplifying and generalizing deserialisation fn serialize_vec_from_table( &self, table: &str, diff --git a/weaponry/src/weaponry_structs/equipement_impl_math.rs b/weaponry/src/weaponry_structs/equipement_impl_math.rs index 008d151..ff56227 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::SpecialField; +use crate::weaponry_structs::{SpecialField, WeaponBaseShape}; /// Add a new vector to a clone of a inner field macro_rules! add_to_vec { @@ -55,7 +55,15 @@ impl std::ops::Add for &InnerEquipementStats { precision: self.precision + rhs.precision, rmax: self.rmax + rhs.rmax, armor_break: self.armor_break + rhs.armor_break, - armor_pierce: self.armor_pierce + rhs.armor_pierce, + armor_pierce: { + if self.armor_pierce > 0 + || matches!(self.category_base, Some(WeaponBaseShape::Ranged)) + { + self.armor_pierce + rhs.armor_pierce + } else { + 0 + } + }, antimaterial: self.antimaterial + rhs.antimaterial, damage_type: add_two_options!(self.damage_type, rhs.damage_type), protection: self.protection + rhs.protection, diff --git a/weaponry/src/weaponry_structs/equipement_scenario.rs b/weaponry/src/weaponry_structs/equipement_scenario.rs index 7098313..a9a40ed 100644 --- a/weaponry/src/weaponry_structs/equipement_scenario.rs +++ b/weaponry/src/weaponry_structs/equipement_scenario.rs @@ -40,30 +40,51 @@ pub struct ConfigEquipementScenario { /// A simple cross recipe scenario #[allow(clippy::missing_docs_in_private_items)] pub struct CrossRecipeScenario { - // TODO: Should obv be inside the config database: EquipementDatabase, config: ConfigEquipementScenario, } +/// All recipes +#[allow(clippy::missing_docs_in_private_items, dead_code)] +pub struct RecipesScenario { + database: EquipementDatabase, + config: ConfigEquipementScenario, +} + +/// A scenario exporting all individual elements +#[allow(clippy::missing_docs_in_private_items, dead_code)] +pub struct IndividualElementsScenario { + database: EquipementDatabase, + config: ConfigEquipementScenario, +} + +/// The initial equipement type, to be converted into post deserialisation +type InitialEquipementType = InnerEquipementStats; +/// The initial database typ +type InitialDatabaseType = DatabaseEquipementStats; + impl CrossRecipeScenario { /// Automatically deserialize into an equipement // TODO: Add to trait // TODO: Add an optionnal initial filter ? fn deserde_into_equipement( &self, - name: &str, + sql_filter: Option<&str>, ) -> Result where - T: TryFrom + From + Into, + T: From + Into, // TryFrom + { // TODO: This likely has too high a complexity and should either be a blanket implementation // : or require the inner workings to implement methods to easily allow this deserialisation + // : Most of this complexity comes from the fact that no clear definition of flow is given to + // : the whole implementation + // : Beside many struct "need" to know way too much of the inner workings of the other to funtion + // : A very long and tedious overhall is now needed + // : At the very least, The InitialEquipementList sould be able to initialize itself with only + // : the intermediate representation and nothing more Ok(InitialEquipementList::from_vectored( - self.database - .serialize_vec_from_table::( - &self.config.table_name, - Some(&format!("META_CATEGORY LIKE '{}'", name)), - )? + self.get_database() + .serialize_vec_from_table::(self.get_tablename(), sql_filter)? .into_iter() .map(|v| { InnerEquipementStats::try_from(v) @@ -74,6 +95,33 @@ impl CrossRecipeScenario { )) } + // /// Automatically deserialize into an equipement + // fn better_deserde_into_equipement( + // &self, + // sql_filter: Option<&str>, + // ) -> Result + // where + // IntermediateType: From + Into, // TryFrom + + // { + // let mut items = self + // .get_database() + // .serialize_vec_from_table::(self.get_tablename(), sql_filter)? + // .into_iter(); + // InitialEquipementList::from_iter_with_intermediate::( + // &mut items, + // ); + // // Ok(InitialEquipementList::from_vectored( + // // items + // // .map(|v| { + // // InnerEquipementStats::try_from(v) + // // .map(|w| T::from(w)) + // // .map(|v| v.into()) + // // }) + // // .collect::, FatalEquipementError>>()?, + // // )) + // todo!() + // } + /// Generate all the operations to be processed with the current config // TODO: Defer this to a custom type in the config some sort of OperationSelector fn generate_selected_operation( @@ -81,18 +129,27 @@ impl CrossRecipeScenario { ) -> Result, FatalEquipementError> { let mut operations = Vec::with_capacity(8); if self.config.shape.is_some() { - operations.push(self.deserde_into_equipement::("Shape")?); + operations + .push(self.deserde_into_equipement::(Some("META_CATEGORY LIKE 'Shape'"))?); } if let Some(qt) = self.config.materials { for _ in 0..qt { - operations.push(self.deserde_into_equipement::("Materials")?); + operations.push(self.deserde_into_equipement::(Some( + "META_CATEGORY LIKE 'Materials'", + ))?); } } if self.config.nature.is_some() { - operations.push(self.deserde_into_equipement::("Nature")?); + operations.push( + self.deserde_into_equipement::(Some("META_CATEGORY LIKE 'Nature'"))?, + ); } if self.config.finishing.is_some() { - operations.push(self.deserde_into_equipement::("Finishing")?); + operations.push( + self.deserde_into_equipement::(Some( + "META_CATEGORY LIKE 'Finishing'", + ))?, + ); } if operations.is_empty() { return Err(FatalEquipementError::CLISelection( @@ -104,9 +161,11 @@ impl CrossRecipeScenario { } impl Scenario for CrossRecipeScenario { + // TODO[3]: Could be skipped type DatabaseType = EquipementDatabase; type FinalListType = RefinedEquipementList; type Config = ConfigEquipementScenario; + // type InitialInnerList = InitialEquipementList; fn new_with_config(config: Self::Config) -> Result where @@ -128,4 +187,16 @@ impl Scenario for CrossRecipeScenario { Ok(refined_list.into()) } + + // type InitialElementList; + + // type InitialDatabaseStruct; + + fn get_tablename(&self) -> &str { + &self.config.table_name + } + + fn get_database(&self) -> &Self::DatabaseType { + &self.database + } } diff --git a/weaponry/src/weaponry_structs/equipement_structs.rs b/weaponry/src/weaponry_structs/equipement_structs.rs index 5e70554..affad8a 100644 --- a/weaponry/src/weaponry_structs/equipement_structs.rs +++ b/weaponry/src/weaponry_structs/equipement_structs.rs @@ -25,6 +25,23 @@ pub struct InitialEquipementList { pub(super) inner: Vec, } +// impl InitialEquipementList { +// pub fn from_iter_with_intermediate( +// iterator: &mut dyn Iterator, +// ) -> Self +// where +// IntermediateType: Into, +// IntoEquipementType: Into, +// { +// Self { +// inner: iterator +// .into_iter() +// .map(|element| IntermediateType::from(element.into())) +// .collect(), +// } +// } +// } + /// The final equipement, obtained by combining all parts #[derive(Clone, Debug)] #[cfg_attr(test, derive(PartialEq))]