diff --git a/.ignore b/.ignore new file mode 100644 index 0000000..8e062ad --- /dev/null +++ b/.ignore @@ -0,0 +1 @@ +*.drawio diff --git a/weaponry/databases/weapons.db b/weaponry/databases/weapons.db index d0343f1..7e68296 100644 Binary files a/weaponry/databases/weapons.db and b/weaponry/databases/weapons.db differ diff --git a/weaponry/examples/test_serialisation_wl.rs b/weaponry/examples/test_serialisation_wl.rs index abd1d3f..d5d9ad0 100644 --- a/weaponry/examples/test_serialisation_wl.rs +++ b/weaponry/examples/test_serialisation_wl.rs @@ -26,6 +26,7 @@ fn main() { // }) // .sum::(); let f = intermediate_deserialisation.iter().fold((0, 0), |val, res| (val.0 + res.is_ok() as usize, val.1 + 1_usize)); - println!("Final data {:#?}", intermediate_deserialisation); + // println!("Final data {:#?}", intermediate_deserialisation); + println!("Failed to parse: {:#?}", intermediate_deserialisation.into_iter().filter_map(|v| v.err()).collect::>()); println!("Succeded in parsing {}/{}", f.0, f.1); } diff --git a/weaponry/src/error.rs b/weaponry/src/error.rs index dff152a..808b9d8 100644 --- a/weaponry/src/error.rs +++ b/weaponry/src/error.rs @@ -20,10 +20,14 @@ pub enum FatalEquipementError { #[error("Deserialisation from json failed : {0}")] SerdeJSON(#[from] serde_json::Error), - #[error("Deserialisation from json failed at line {line} : {error}]")] + #[error( + "Deserialisation from json failed at line {line} on file {file} while trying to parse the value: {parsed_value}: {error}]" + )] SerdeJSONAt { line: String, + file: String, error: serde_json::Error, + parsed_value: String, }, #[error("Couldn't convert into type {origin_type} with data {data}")] diff --git a/weaponry/src/weaponry_structs/equipement_fields.rs b/weaponry/src/weaponry_structs/equipement_fields.rs index dd6efeb..cd52da0 100644 --- a/weaponry/src/weaponry_structs/equipement_fields.rs +++ b/weaponry/src/weaponry_structs/equipement_fields.rs @@ -7,8 +7,6 @@ use std::fmt::Display; use std::ops::Add; use strum::Display; -use crate::error::FatalEquipementError; - #[derive(Clone, Default, Debug, Deserialize, Serialize)] #[cfg_attr(test, derive(PartialEq))] /// The special category, a vec of string, for display purposes only @@ -36,21 +34,21 @@ pub enum PhysicalDamageType { Pierce, } -impl TryFrom<&str> for PhysicalDamageType { - type Error = FatalEquipementError; +// impl TryFrom<&str> for PhysicalDamageType { +// type Error = FatalEquipementError; - fn try_from(value: &str) -> Result { - match value.to_ascii_lowercase().as_str() { - "blunt" => Ok(Self::Blunt), - "slash" => Ok(Self::Slash), - "pierce" => Ok(Self::Pierce), - _ => Err(FatalEquipementError::Conversion { - origin_type: std::any::type_name::().to_owned(), - data: value.to_string(), - }), - } - } -} +// fn try_from(value: &str) -> Result { +// match value.to_ascii_lowercase().as_str() { +// "blunt" => Ok(Self::Blunt), +// "slash" => Ok(Self::Slash), +// "pierce" => Ok(Self::Pierce), +// _ => Err(FatalEquipementError::Conversion { +// origin_type: std::any::type_name::().to_owned(), +// data: value.to_string(), +// }), +// } +// } +// } /// Weapon damage, combining the base weapon damage type and it's level /// @@ -149,7 +147,7 @@ pub enum WeaponCategory { /// The list of initial weapon meta categories #[allow(clippy::missing_docs_in_private_items, missing_docs)] #[derive(Clone, Debug, PartialEq, Display, Deserialize, Serialize, strum::EnumString)] -pub enum WeaponMetaCategory { +pub enum WeaponMacroCategory { Staves, Blunt, Slash, @@ -157,6 +155,9 @@ pub enum WeaponMetaCategory { Armor, Shields, Exotic, + /// A custom none category, used to forbid a part to be cast upon of from + // TODO: Check the soundness of this implementation + None, } #[cfg(test)] diff --git a/weaponry/src/weaponry_structs/equipement_impl_basics.rs b/weaponry/src/weaponry_structs/equipement_impl_basics.rs index 3d27023..509ea8e 100644 --- a/weaponry/src/weaponry_structs/equipement_impl_basics.rs +++ b/weaponry/src/weaponry_structs/equipement_impl_basics.rs @@ -42,7 +42,10 @@ impl From for Equipement { // TODO : Checks that this is exactly desired behavious // :Also check for Cross Weapon/Armor contamination // Checks that the nature is compatible with the previous iteration - filter_function: FilterFunction::new(&|sel, lhs| match (&sel.target, &lhs.category) { + filter_function: FilterFunction::new(&|sel, lhs| match ( + &sel.target, + &lhs.macro_category, + ) { (Some(a), Some(b)) => a == b, (None, None) => true, _ => false, @@ -83,7 +86,7 @@ impl Display for InnerEquipementStats { self.cost, self.difficulty, self.tier, - self.category + self.macro_category .clone() .map_or_else(|| "ΓΈ".to_string(), |v| v.to_string()) )]); diff --git a/weaponry/src/weaponry_structs/equipement_impl_database.rs b/weaponry/src/weaponry_structs/equipement_impl_database.rs index 9541279..58611ac 100644 --- a/weaponry/src/weaponry_structs/equipement_impl_database.rs +++ b/weaponry/src/weaponry_structs/equipement_impl_database.rs @@ -77,7 +77,9 @@ impl FixedRecipe for EquipementFixedRecipe { macro_rules! from_serde { ($value: expr) => { serde_json::from_str(&$value).map_err(|error| FatalEquipementError::SerdeJSONAt { - line: format!("{} line {}", file!(), line!()), + line: line!().to_string(), + file: file!().to_string(), + parsed_value: $value.to_string(), error, }) }; @@ -112,7 +114,7 @@ impl TryFrom for InnerEquipementStats { parry: value.parry, speed: value.speed, stealth: value.stealth, - category: from_serde!(&value.category)?, + macro_category: from_serde!(&value.category)?, target: from_serde!(&value.target)?, special: from_serde!(&value.special)?, action_cost: value.action_cost, diff --git a/weaponry/src/weaponry_structs/equipement_impl_logic.rs b/weaponry/src/weaponry_structs/equipement_impl_logic.rs index a7f5d6a..ae5370c 100644 --- a/weaponry/src/weaponry_structs/equipement_impl_logic.rs +++ b/weaponry/src/weaponry_structs/equipement_impl_logic.rs @@ -53,7 +53,7 @@ mod test { interfaces::RecipeCollection, weaponry_structs::{ DamageMod, DamageType, Equipement, InitialEquipementList, SpecialCategory, - equipement_fields::{PhysicalDamageType, WeaponMetaCategory}, + equipement_fields::{PhysicalDamageType, WeaponMacroCategory}, equipement_structs::InnerEquipementStats, }, }; @@ -93,8 +93,8 @@ mod test { rarity: 1, integrity: 2, range: 3, - agility_bonus: 4, - category: Some(WeaponMetaCategory::Staves), + agility_bonus: 4., + macro_category: Some(WeaponMacroCategory::Staves), special: SpecialCategory(vec!["zero".into()]), damage_type: Some(DamageType(vec![DamageMod::Secondary( PhysicalDamageType::Slash, @@ -103,7 +103,7 @@ mod test { }; let i2 = InnerEquipementStats { integrity: 3, - agility_bonus: 5, + agility_bonus: 5., damage: 10, damage_type: Some(DamageType(vec![DamageMod::Primary( PhysicalDamageType::Blunt, @@ -116,10 +116,10 @@ mod test { InnerEquipementStats { rarity: 1, integrity: 5, - agility_bonus: 9, + agility_bonus: 9., damage: 10, range: 3, - category: Some(WeaponMetaCategory::Staves), + macro_category: Some(WeaponMacroCategory::Staves), special: SpecialCategory(vec!["zero".into(), "one".into(), "two".into()]), damage_type: Some(DamageType(vec![ DamageMod::Secondary(PhysicalDamageType::Slash,), diff --git a/weaponry/src/weaponry_structs/equipement_impl_math.rs b/weaponry/src/weaponry_structs/equipement_impl_math.rs index 8a677e8..e6e376d 100644 --- a/weaponry/src/weaponry_structs/equipement_impl_math.rs +++ b/weaponry/src/weaponry_structs/equipement_impl_math.rs @@ -55,9 +55,9 @@ impl std::ops::Add for &InnerEquipementStats { parry: self.parry + rhs.parry, speed: self.speed + rhs.speed, stealth: self.stealth + rhs.stealth, - category: self.category.clone().or(rhs.category.clone()), // Can be further optimized - target: self.target.clone().or(rhs.target.clone()), // Can be further optimized - special: self.special.clone() + rhs.special.clone(), // Can be further optimized + macro_category: self.macro_category.clone().or(rhs.macro_category.clone()), // Can be further optimized + target: self.target.clone().or(rhs.target.clone()), // Can be further optimized + special: self.special.clone() + rhs.special.clone(), // Can be further optimized action_cost: self.action_cost + rhs.action_cost, reload_cost: self.reload_cost.or(rhs.reload_cost), range: self.range + rhs.range, diff --git a/weaponry/src/weaponry_structs/equipement_structs.rs b/weaponry/src/weaponry_structs/equipement_structs.rs index d74ddfd..e0899ef 100644 --- a/weaponry/src/weaponry_structs/equipement_structs.rs +++ b/weaponry/src/weaponry_structs/equipement_structs.rs @@ -8,7 +8,7 @@ use crate::interfaces::{FilterFunction, FilterFunctionType}; use more_fields::FieldsAsSlice; use serde::{Deserialize, Serialize}; -use super::{DamageType, SpecialCategory, WeaponCategory, equipement_fields::WeaponMetaCategory}; +use super::{DamageType, SpecialCategory, WeaponCategory, equipement_fields::WeaponMacroCategory}; /// The final equipement list /// @@ -75,17 +75,18 @@ pub struct InnerEquipementStats { pub(super) integrity: i8, pub(super) torque_two_handed: Option, // Might be option (single claw) pub(super) torque_one_handed: Option, // Should be option (bows) - pub(super) dodge: i8, + pub(super) dodge: f32, // I could also use a custom HalfValue pub(super) parry: i8, pub(super) speed: i8, pub(super) stealth: i8, - pub(super) category: Option, - pub(super) target: Option, // TODO: This might be incorrect, to check + /// The initial macro category, in turn combined with other stats it will describe a final category + pub(super) macro_category: Option, // TODO : This initial macro category fill as a final stat feed the final category + pub(super) target: Option, // TODO: This might be incorrect, to check pub(super) special: SpecialCategory, pub(super) action_cost: i8, pub(super) reload_cost: Option, // Shouldn't it be Option ? pub(super) range: i8, // Shoudln't it be Option ? - pub(super) agility_bonus: i8, + pub(super) agility_bonus: f32, // Also convert this one to HalfValue } // TODO: This implementation of default is painfull @@ -129,8 +130,8 @@ pub struct DatabaseEquipementStats { pub integrity: i8, pub torque_two_handed: String, pub torque_one_handed: String, - #[INTEGER] - pub dodge: i8, + #[REAL] + pub dodge: f32, #[INTEGER] pub parry: i8, #[INTEGER] @@ -145,8 +146,8 @@ pub struct DatabaseEquipementStats { pub reload_cost: String, #[INTEGER] pub range: i8, - #[INTEGER] - pub agility_bonus: i8, + #[REAL] + pub agility_bonus: f32, } impl Default for DatabaseEquipementStats { @@ -156,7 +157,7 @@ impl Default for DatabaseEquipementStats { meta_category: "EqShape".to_string(), name: String::new(), damage_type: serde_json::to_string(&None::).unwrap(), - category: serde_json::to_string(&None::).unwrap(), + category: serde_json::to_string(&None::).unwrap(), target: serde_json::to_string(&None::).unwrap(), special: serde_json::to_string(&SpecialCategory::default()).unwrap(), reload_cost: serde_json::to_string(&None::).unwrap(), @@ -175,12 +176,12 @@ impl Default for DatabaseEquipementStats { integrity: 0, torque_two_handed: serde_json::to_string(&0).unwrap(), torque_one_handed: serde_json::to_string(&None::).unwrap(), - dodge: 0, + dodge: 0., parry: 0, speed: 0, stealth: 0, range: 0, - agility_bonus: 0, + agility_bonus: 0., action_cost: 0, } } diff --git a/weaponry/src/weaponry_structs/mod.rs b/weaponry/src/weaponry_structs/mod.rs index cf3aab5..e4ab206 100644 --- a/weaponry/src/weaponry_structs/mod.rs +++ b/weaponry/src/weaponry_structs/mod.rs @@ -35,5 +35,5 @@ pub use equipement_structs::{Equipement, InitialEquipementList}; // #[allow(unused_imports)] pub use equipement_fields::PhysicalDamageType; pub use equipement_fields::{ - DamageMod, DamageType, NatureTarget, SpecialCategory, WeaponCategory, WeaponMetaCategory, + DamageMod, DamageType, NatureTarget, SpecialCategory, WeaponCategory, WeaponMacroCategory, };