Cleanup requirements for impls
This commit is contained in:
parent
4b4d39257a
commit
603a1cd8b6
|
|
@ -14,22 +14,18 @@ pub trait FromParts {}
|
|||
/// Trait implemented for the final collection of a recipe, allowing it to be combined with parts
|
||||
///
|
||||
/// A recipe list will be combined with a part list to be updated and generate all combinaisons, so on and so forth
|
||||
pub trait RecipeCollection {
|
||||
pub trait RecipeCollection
|
||||
where
|
||||
for<'a> &'a <<Self as RecipeCollection>::Recipes as Combineable>::Inner: std::ops::Add,
|
||||
{
|
||||
/// The type of the inner recipes, this type must be combinable
|
||||
type Recipes: Combineable;
|
||||
|
||||
// /// Combine all current recipies with all the parts given
|
||||
// #[deprecated]
|
||||
// fn combine_all<G>(&mut self, other: G)
|
||||
// where
|
||||
// G: RecipeCollection<Recipes = Self::Recipes> + std::marker::Sync;
|
||||
|
||||
/// Do the parrallel combination all inside
|
||||
fn combine_all_by_blanket<G>(&mut self, other: &G)
|
||||
where
|
||||
G: RecipeCollection<Recipes = Self::Recipes>,
|
||||
{
|
||||
// TODO: Test Add to Self instead
|
||||
self.assign_inner(
|
||||
self.ref_inner()
|
||||
.iter()
|
||||
|
|
@ -46,23 +42,6 @@ pub trait RecipeCollection {
|
|||
);
|
||||
}
|
||||
|
||||
// fn combine_all_by_ref<G>(&mut self, other: G)
|
||||
// where
|
||||
// G: RecipeCollection<Recipes = Self::Recipes> + std::marker::Sync,
|
||||
// {
|
||||
// let mut future_receipes = vec![self.ref_inner().clone(); other.ref_inner().len()];
|
||||
// future_receipes
|
||||
// .par_iter_mut()
|
||||
// .zip(other.ref_inner())
|
||||
// .for_each(move |(a, b)| {
|
||||
// a.par_iter_mut().for_each(move |e| {
|
||||
// e.add_to_self(b);
|
||||
// });
|
||||
// });
|
||||
|
||||
// self.inner = future_receipes.into_par_iter().flatten().collect();
|
||||
// }
|
||||
|
||||
/// Assign the inner value from an owned value, used for blanket implementations
|
||||
fn assign_inner(&mut self, inner: Vec<Self::Recipes>);
|
||||
|
||||
|
|
@ -71,10 +50,6 @@ pub trait RecipeCollection {
|
|||
/// This allows to only clone when needed
|
||||
fn ref_inner(&self) -> &Vec<Self::Recipes>;
|
||||
|
||||
// /// Gives access to a mutable reference of the inner list
|
||||
// #[deprecated]
|
||||
// fn refmut_inner(&mut self) -> &mut Vec<Self::Recipes>;
|
||||
|
||||
// Optional filter ?
|
||||
|
||||
/// Create a collection from a vector
|
||||
|
|
@ -84,30 +59,19 @@ pub trait RecipeCollection {
|
|||
/// Trait that ensure that two elements of a recipe are combinable,
|
||||
///
|
||||
/// Being combinable means it can be coerced into elements that implement add
|
||||
pub trait Combineable {
|
||||
pub trait Combineable
|
||||
where
|
||||
for<'a> &'a <Self as Combineable>::Inner: std::ops::Add,
|
||||
{
|
||||
/// The inner type of the combined elements, this type must implement Add
|
||||
// TODO : Make this help much more readable
|
||||
type Inner: std::ops::Add + std::ops::AddAssign;
|
||||
type Inner;
|
||||
|
||||
/// Give access to a reference of the underlying data to be combined
|
||||
///
|
||||
/// The designed combinaison method is std::ops::Add
|
||||
fn combinable_part(&self) -> &Self::Inner;
|
||||
|
||||
// /// Add an element to self and return a new value
|
||||
// ///
|
||||
// /// This method will clone it's own combinable part
|
||||
// #[deprecated]
|
||||
// fn add_to_other<T>(&self, rhs: T) -> Self
|
||||
// where
|
||||
// T: Combineable<Inner = Self::Inner>;
|
||||
|
||||
/// Add an element to a mutable self
|
||||
// #[deprecated(note = "Mutate in place")]
|
||||
fn add_to_self<T>(&mut self, rhs: &T)
|
||||
where
|
||||
T: Combineable<Inner = Self::Inner>;
|
||||
|
||||
/// Add an element to self and generate a new Self
|
||||
///
|
||||
/// As the signature implies, it will not mutate self not rhs and will generate a new value from the operation
|
||||
|
|
|
|||
|
|
@ -13,13 +13,6 @@ impl Combineable for Equipement {
|
|||
&self.stats
|
||||
}
|
||||
|
||||
fn add_to_self<T>(&mut self, rhs: &T)
|
||||
where
|
||||
T: Combineable<Inner = Self::Inner>,
|
||||
{
|
||||
self.stats += rhs.combinable_part().clone()
|
||||
}
|
||||
|
||||
fn add_ref_to_self<T>(&self, rhs: &T) -> Self
|
||||
where
|
||||
T: Combineable<Inner = Self::Inner>,
|
||||
|
|
@ -110,7 +103,7 @@ mod test {
|
|||
..Default::default()
|
||||
};
|
||||
assert_eq!(
|
||||
i1 + i2,
|
||||
&i1 + &i2,
|
||||
InnerStats {
|
||||
rarity: 1,
|
||||
integrity: 5,
|
||||
|
|
@ -143,8 +136,8 @@ mod test {
|
|||
},
|
||||
);
|
||||
assert_eq!(
|
||||
InnerStats::default()
|
||||
+ InnerStats {
|
||||
&InnerStats::default()
|
||||
+ &InnerStats {
|
||||
damage_type: Some(DamageType(vec![
|
||||
DamageMod::Secondary(PhysicalDamageType::Slash,),
|
||||
DamageMod::Primary(PhysicalDamageType::Blunt,),
|
||||
|
|
|
|||
|
|
@ -6,57 +6,6 @@
|
|||
use super::equipement_structs::InnerStats;
|
||||
use crate::weaponry_structs::SpecialCategory;
|
||||
|
||||
impl std::ops::Add for InnerStats {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self {
|
||||
// TODO: Decide the behaviour of ids, as uuid are useless but this is even more useless
|
||||
id: self.id,
|
||||
name: {
|
||||
let mut b = self.name.clone();
|
||||
b.append(&mut rhs.name.clone());
|
||||
b
|
||||
},
|
||||
rarity: self.rarity + rhs.rarity,
|
||||
cost: self.cost + rhs.cost,
|
||||
difficulty: self.difficulty + rhs.difficulty,
|
||||
tier: self.tier + rhs.tier,
|
||||
damage: self.damage + rhs.damage,
|
||||
p_damage: self.p_damage + rhs.p_damage,
|
||||
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,
|
||||
antimaterial: self.antimaterial + rhs.antimaterial,
|
||||
damage_type: {
|
||||
match (self.damage_type, rhs.damage_type) {
|
||||
(None, None) => None,
|
||||
(None, Some(a)) => Some(a),
|
||||
(Some(a), None) => Some(a),
|
||||
(Some(mut a), Some(mut b)) => {
|
||||
a.0.append(&mut b.0);
|
||||
Some(a)
|
||||
}
|
||||
}
|
||||
},
|
||||
protection: self.protection + rhs.protection,
|
||||
integrity: self.integrity + rhs.integrity,
|
||||
torque_two_handed: self.torque_two_handed + rhs.torque_two_handed,
|
||||
torque_one_handed: self.torque_one_handed + rhs.torque_one_handed,
|
||||
dodge: self.dodge + rhs.dodge,
|
||||
parry: self.parry + rhs.parry,
|
||||
speed: self.speed + rhs.speed,
|
||||
stealth: self.stealth + rhs.stealth,
|
||||
category: self.category.or(rhs.category),
|
||||
special: self.special + rhs.special,
|
||||
action_cost: self.action_cost + rhs.action_cost,
|
||||
reload_cost: self.reload_cost.or(rhs.reload_cost),
|
||||
range: self.range + rhs.range,
|
||||
agility_bonus: self.agility_bonus + rhs.agility_bonus,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl std::ops::Add for &InnerStats {
|
||||
type Output = InnerStats;
|
||||
|
||||
|
|
@ -109,50 +58,6 @@ impl std::ops::Add for &InnerStats {
|
|||
}
|
||||
}
|
||||
|
||||
impl std::ops::AddAssign for InnerStats {
|
||||
fn add_assign(&mut self, rhs: InnerStats) {
|
||||
// self.id;
|
||||
// self.name.push('+');
|
||||
// self.name.push_str(&rhs.name);
|
||||
self.rarity += rhs.rarity;
|
||||
self.cost += rhs.cost;
|
||||
self.difficulty += rhs.difficulty;
|
||||
self.tier += rhs.tier;
|
||||
self.damage += rhs.damage;
|
||||
self.p_damage += rhs.p_damage;
|
||||
self.precision += rhs.precision;
|
||||
self.rmax += rhs.rmax;
|
||||
self.armor_break += rhs.armor_break;
|
||||
self.armor_pierce += rhs.armor_pierce;
|
||||
self.antimaterial += rhs.antimaterial;
|
||||
self.damage_type = {
|
||||
match (self.damage_type.clone(), rhs.damage_type.clone()) {
|
||||
(None, None) => None,
|
||||
(None, Some(a)) => Some(a),
|
||||
(Some(a), None) => Some(a),
|
||||
(Some(mut a), Some(mut b)) => {
|
||||
a.0.append(&mut b.0);
|
||||
Some(a)
|
||||
}
|
||||
}
|
||||
};
|
||||
self.protection += rhs.protection;
|
||||
self.integrity += rhs.integrity;
|
||||
self.torque_two_handed += rhs.torque_two_handed;
|
||||
self.torque_one_handed += rhs.torque_one_handed;
|
||||
self.dodge += rhs.dodge;
|
||||
self.parry += rhs.parry;
|
||||
self.speed += rhs.speed;
|
||||
self.stealth += rhs.stealth;
|
||||
self.category.clone().or(rhs.category.clone()); // Can be further optimized
|
||||
// self.special += rhs.special.clone(); // Can be further optimized
|
||||
self.action_cost += rhs.action_cost;
|
||||
self.reload_cost.or(rhs.reload_cost);
|
||||
self.range += rhs.range;
|
||||
self.agility_bonus += rhs.agility_bonus;
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Add for SpecialCategory {
|
||||
type Output = Self;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue