diff --git a/weaponry/databases/weapons.db b/weaponry/databases/weapons.db index 935c5d5..fe13caa 100644 Binary files a/weaponry/databases/weapons.db and b/weaponry/databases/weapons.db differ diff --git a/weaponry/src/interfaces.rs b/weaponry/src/interfaces.rs index d33eee2..186cca4 100644 --- a/weaponry/src/interfaces.rs +++ b/weaponry/src/interfaces.rs @@ -234,6 +234,12 @@ pub trait Scenario { /// Inner configuration type Config; + // /// The initial element List + // type InitialElementList: RecipeCollection; + + // /// The Inner Database struct to deserialize initially + // type InitialDatabaseStruct; + /// Create a Scenario from a given config fn new_with_config(config: Self::Config) -> 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))]