From 9facac6b9f96e48e583def3c49e74dc5a1542b0a Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Wed, 12 Feb 2025 00:36:49 +0100 Subject: [PATCH] Work on the Generic impls --- weaponry/src/interfaces.rs | 4 +- .../weaponry_structs/equipement_into_impls.rs | 30 ++++++++++ .../weaponry_structs/equipement_structs.rs | 56 +++++++++++++------ weaponry/src/weaponry_structs/mod.rs | 1 + 4 files changed, 73 insertions(+), 18 deletions(-) create mode 100644 weaponry/src/weaponry_structs/equipement_into_impls.rs diff --git a/weaponry/src/interfaces.rs b/weaponry/src/interfaces.rs index f7b169e..d72a4cc 100644 --- a/weaponry/src/interfaces.rs +++ b/weaponry/src/interfaces.rs @@ -21,7 +21,9 @@ where /// The type of the inner recipes, this type must be combinable type Recipes: Combineable; - /// Do the parrallel combination all inside + /// A blanket implementation giving all combinaisons of recipes with another RecipeCollection + /// + /// This method doesn't make use of parallel iterators as the workload is way faster than would be the memory dispatch fn combine_all_by_blanket(&mut self, other: &G) where G: RecipeCollection, diff --git a/weaponry/src/weaponry_structs/equipement_into_impls.rs b/weaponry/src/weaponry_structs/equipement_into_impls.rs new file mode 100644 index 0000000..3aae092 --- /dev/null +++ b/weaponry/src/weaponry_structs/equipement_into_impls.rs @@ -0,0 +1,30 @@ +// Workspace: weaponry +// File: weaponry/src/weaponry_structs/equipement_into_impls.rs +//! Implementations to transform all Specialized equipement into a generic Equipement +//! A specific implementation could be preferable, but this simplicity might allow for easier developpement + +use super::{ + Equipement, + equipement_structs::{EqFinishing, EqMaterial, EqNature, EqShape}, +}; + +impl From for Equipement { + fn from(val: EqShape) -> Self { + Self { stats: val.stats } + } +} +impl From for Equipement { + fn from(val: EqMaterial) -> Self { + Self { stats: val.stats } + } +} +impl From for Equipement { + fn from(val: EqNature) -> Self { + Self { stats: val.stats } + } +} +impl From for Equipement { + fn from(val: EqFinishing) -> Self { + Self { stats: val.stats } + } +} diff --git a/weaponry/src/weaponry_structs/equipement_structs.rs b/weaponry/src/weaponry_structs/equipement_structs.rs index 33624e3..856ff94 100644 --- a/weaponry/src/weaponry_structs/equipement_structs.rs +++ b/weaponry/src/weaponry_structs/equipement_structs.rs @@ -59,21 +59,6 @@ pub struct InnerStats { pub(super) agility_bonus: u8, } -// /// A type representing a weapon reload potential -// #[derive(Clone, Default)] -// #[cfg_attr(test, derive(Debug, PartialEq))] -// pub struct OptionnalReloadType(Option); - -// /// Optionnal Weapon -// #[derive(Clone, Default)] -// #[cfg_attr(test, derive(Debug, PartialEq))] -// pub struct OptionnalWeaponCategory(Option); - -// /// Optionnal damage type -// #[derive(Clone, Default)] -// #[cfg_attr(test, derive(Debug, PartialEq))] -// pub struct OptionnalDamageType(Option); - /// Shape of the equipement, first mandatory part of an equipement pub struct EqShape { /// The inner stats of the part @@ -92,6 +77,8 @@ pub struct EqMaterial { pub struct EqNature { /// The inner stats of the part pub(super) stats: InnerStats, + // TODO: Be sure to take this into account + #[allow(dead_code)] /// Which kind of target this nature applies to pub(super) target: NatureTarget, } @@ -106,7 +93,11 @@ pub struct EqFinishing { mod test { // use super::*; - use super::{Equipement, InnerStats}; + use crate::{interfaces::RecipeCollection, weaponry_structs::NatureTarget}; + + use super::{ + EqFinishing, EqMaterial, EqNature, EqShape, Equipement, FinalEquipementList, InnerStats, + }; fn list_equip() -> Vec { (0..10) @@ -130,7 +121,38 @@ mod test { } #[test] - fn test_creating_all_equipements() {} + fn test_creating_all_equipements() { + let shape = vec![ + EqShape { + stats: InnerStats::default(), + } + .into(), + ]; + let nature = vec![ + EqNature { + stats: InnerStats::default(), + target: NatureTarget::Armor, + } + .into(), + ]; + let material = vec![ + EqMaterial { + stats: InnerStats::default(), + } + .into(), + ]; + let finishing = vec![ + EqFinishing { + stats: InnerStats::default(), + } + .into(), + ]; + + let mut leq = FinalEquipementList::from_vectored(shape); + leq.combine_all_by_blanket(&FinalEquipementList::from_vectored(nature)); + leq.combine_all_by_blanket(&FinalEquipementList::from_vectored(material)); + leq.combine_all_by_blanket(&FinalEquipementList::from_vectored(finishing)); + } #[ignore] #[test] diff --git a/weaponry/src/weaponry_structs/mod.rs b/weaponry/src/weaponry_structs/mod.rs index 228a565..6f34bd1 100644 --- a/weaponry/src/weaponry_structs/mod.rs +++ b/weaponry/src/weaponry_structs/mod.rs @@ -20,6 +20,7 @@ mod equipement_impl_database; mod equipement_impl_io; mod equipement_impl_logic; mod equipement_impl_math; +mod equipement_into_impls; pub mod equipement_structs; // Republishes the most used symbols