From a2269ccb87f433f27f76c153cc41df5e9e3f185d Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Fri, 21 Feb 2025 01:22:54 +0100 Subject: [PATCH] A lot of shitcode to get the first import working --- weaponry/Cargo.toml | 2 + weaponry/databases/weapons.db | Bin 28672 -> 28672 bytes .../{serde_loading.rs => first_import.rs} | 121 +++++++++++------- weaponry/src/database.rs | 9 +- weaponry/src/error.rs | 6 + .../src/weaponry_structs/equipement_fields.rs | 81 +++++++++++- .../equipement_impl_basics.rs | 2 +- .../equipement_impl_database.rs | 26 ++-- .../weaponry_structs/equipement_impl_logic.rs | 6 +- .../weaponry_structs/equipement_impl_math.rs | 7 +- .../weaponry_structs/equipement_structs.rs | 26 ++-- weaponry/src/weaponry_structs/mod.rs | 4 +- 12 files changed, 206 insertions(+), 84 deletions(-) rename weaponry/examples/{serde_loading.rs => first_import.rs} (62%) diff --git a/weaponry/Cargo.toml b/weaponry/Cargo.toml index 56c961e..ae487b4 100644 --- a/weaponry/Cargo.toml +++ b/weaponry/Cargo.toml @@ -15,11 +15,13 @@ serde_rusqlite = "0.37.0" serde_json = { version = "1.0.138", features = ["alloc"] } strum = { version = "0.27.0", features = ["derive"] } thiserror = "2.0.11" +regex = "1.11.1" [dev-dependencies] criterion = { version = "0.5" } regex = "1.11.1" pretty_assertions = "^1.4" +logos = "^0.15" [[bench]] name = "iter_creation" diff --git a/weaponry/databases/weapons.db b/weaponry/databases/weapons.db index 5fea0f35eea85fe0ae67cd0919efb5579bfde3e7..6d0843fc1fb807b939f132659d4bc921cab0bcda 100644 GIT binary patch delta 1002 zcmZ{iUu)A)7{+swv`yA#X(qL38J+2ECr#D1+m#(mcQYvK&}tbaOV4aEO}hLMWlAb| zp?B)=R?rL4t63`e0g88i1;@k>uq*FW7p{deo2!k@ zyrmnvHg4$}Zgpg>joSIqoZ`aIwU}=u+}c;`}W( zOQbW*n_KStE(4UT z3t?FX!3QWj@9wiHfk`pU4c+MB72Q_UE;dZ^Kj>0LtarLtZJWS$0{BJ@;OATz^5IK} z_2KgX=aCPu8VW^EacfXY!JwI3EQ=emb`Q5tBufwPL<7Mgrr_2%Wjdg^YHZ8u_@jks z>TEPskxJ9-V(oSW*lABMVpwp)H3QfzlL?uzCMz9GlhfR~Dw`cpOjApeb5-=W6Pp_} zkiB7nYH->m3!dsQd0jRvEZdPO#lie&N|L0?$v7uuodWU&PcwK7WQ-ga4S!+u_(gyG z2~%f^&hLqJtms#=Kb};AJ4=3!2kdN delta 899 zcmZ{iy>HV%7{>2>j&n|GJ4p$qR3cwOLV}n@FB9iT-wxd>E z(nuiDjgYY$6CV@G21}*<6D&j(J7r=;ymnHOV)dl=d}sUlJFlBmAt#xpFNZo3W$r2QFJVQ{M;Tz@ovBO$P!fVRfKMw6VwM8jG9)1?KoRT z(`7ZiLZPl`vz2@q!Q!CEa!c|#N?=GDwa+$f>0D*rc2obg4+kNut{9;(mWbppB zt8W@?hMTQIm8Vs0y_#Ov%8#q*?Ce1{eI+7hn=jY+u$s%^*XHnxRKtTq`txlpl#~vT z@>SVUZpy#pPjW-PERCguVLaWFx|*0m>N1@UOlcg$DrZ>~~6q&$fzVmd|mka#yidMwhxVJaCdaYP^! m::try_into(&lex.slice()[2..lex.slice().len()-2]).unwrap())] + Tertiary(PhysicalDamageType), + #[regex(r"\[\w+\]", |lex| std::convert::TryInto::::try_into(&lex.slice()[1..lex.slice().len()-1]).unwrap())] + Secondary(PhysicalDamageType), + #[regex(r"\w+", |lex| std::convert::TryInto::::try_into(lex.slice()).unwrap())] + Primary(PhysicalDamageType), +} +// let b = DamageMod::Primary() -// const BASE_DATA: &[[&str; 17]] = &[ -// // {Forme} & {Maniement} & {\damagew} & + & {R.Max} & \arbreakw & \protection & \integrite & $\mathbb{T}$2 & $\mathbb{T}$1 & {Modes} & {Esq.} & {Par.} & {Vit.} & {Disc.} & {Spécial} & {Diff.} \\ -// // % Nom & Type & Dé & + & RM & AB & Pr & In & T2 & T1 & Md & Esq. & Par. & Vit. & Disc. & Spc. & Diff -// ["Griffes", "Tranchantes", "2", "1", "4", "1", "1", "2", "3", "6", "slash", "2", "0", "3", "1", "-", "1"], -// ["Hast", "Hast", "4", "1", "2", "1", "4", "3", "10", "18", "pierce, [slash]", "-1", "-3", "1", "0", "-", "1"], -// ["Épée", "Tranchantes", "3", "1", "3", "1", "3", "4", "12", "15", "slash, [pierce]", "0", "1", "0", "0", "-", "1"], -// ["Marteau", "Contondantes", "5", "1", "1", "1", "4", "3", "11", "18", "blunt", "-1", "-1", "0", "-2", "-", "1"], -// ["Hache", "Tranchantes", "4", "2", "1", "3", "4", "3", "9", "14", "slash", "0", "-1", "1", "0", "-", "1"], -// ["Arbalète", "Distance", "4", "1", "3", "0", "3", "1", "8", "16", "pierce", "-1", "-1", "0", "-1", "2reload, Gls{parmure} 2, 80m", "1"], -// ["Arc", "Distance", "3", "1", "4", "0", "2", "1", "-", "7", "pierce", "0", "0", "0", "0", "1reload, Gls{parmure} 2, 120m", "1"], -// ["Biers", " -", "1", "1", "2", "0", "3", "2", "6", "8", "blunt", "-2", "0", "-1", "-2", "-", "1"], -// ["Armures", " -", " ", " ", " ", " ", "3", "2", "10", "-", "blunt", "-1", "0", "0", "-1", "-", "1"], -// // % "Explosive" , "Exotiques", "3", "1" , "3", "1", "2", "2", "20" , "10" , "slash", "0", "0", "0", "0" , "-" , "ddlvl{5}" -// // % "Flexible", "Exotiques", "3", "1" , "3", "1", "2", "2", "20" , "10" , "slash", "0", "0", "0", "0" , "-" , "ddlvl{2}" -// // % "Exotique", "Exotiques", "3", "1" , "3", "1", "2", "2", "20" , "10" , "slash", "0", "0", "0", "0" , - , "ddlvl{3}" -// ]; -// const BASE_FORME: &[&str] = &[ // "% Nom & Type & Dé & + & RM & AB & Pr & In & T2 & T1 & Md & Esq. & Par. & Vit. & Disc. & Spc. & Diff ", + // "Name & Type & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & mode & 9 & 10 & 11 & 12 & 3reload, & ddlvl{13} ", "Griffes & Tranchantes & 2 & 1 & 4 & 1 & 1 & 2 & 3 & 6 & slash & 2 & 0 & 3 & 1 & - & ddlvl{1} ", "Hast & Hast & 4 & 1 & 2 & 1 & 4 & 3 & 10 & 18 & pierce, [slash] & -1 & -3 & 1 & 0 & - & ddlvl{1} ", "Épée & Tranchantes & 3 & 1 & 3 & 1 & 3 & 4 & 12 & 15 & slash, [pierce] & 0 & 1 & 0 & 0 & - & ddlvl{1} ", @@ -37,8 +33,8 @@ const BASE_FORME: &[&str] = &[ "Hache & Tranchantes & 4 & 2 & 1 & 3 & 4 & 3 & 9 & 14 & slash & 0 & -1 & 1 & 0 & - & ddlvl{1} ", "Arbalète & Distance & 4 & 1 & 3 & 0 & 3 & 1 & 8 & 16 & pierce & -1 & -1 & 0 & -1 & 2reload, Gls{parmure} 2, 80m & ddlvl{1} ", "Arc & Distance & 3 & 1 & 4 & 0 & 2 & 1 & - & 7 & pierce & 0 & 0 & 0 & 0 & 1reload, Gls{parmure} 2, 120m & ddlvl{1} ", - "Boucliers & - & 1 & 1 & 2 & 0 & 3 & 2 & 6 & 8 & blunt & -2 & 0 & -1 & -2 & - & ddlvl{1} ", - "Armures & - & & & & & 3 & 2 & 10 & - & blunt & -1 & 0 & 0 & -1 & - & ddlvl{1} ", + "Boucliers & Boucliers & 1 & 1 & 2 & 0 & 3 & 2 & 6 & 8 & blunt & -2 & 0 & -1 & -2 & - & ddlvl{1} ", + "Armures & Armures & & & & & 3 & 2 & 10 & - & blunt & -1 & 0 & 0 & -1 & - & ddlvl{1} ", // "% Explosive & Exotiques & 3 & 1 & 3 & 1 & 2 & 2 & 20 & 10 & slash & 0 & 0 & 0 & 0 & - & ddlvl{5} ", // "% Flexible & Exotiques & 3 & 1 & 3 & 1 & 2 & 2 & 20 & 10 & slash & 0 & 0 & 0 & 0 & - & ddlvl{2} ", // "% Exotique & Exotiques & 3 & 1 & 3 & 1 & 2 & 2 & 20 & 10 & slash & 0 & 0 & 0 & 0 & - & ddlvl{3} ", @@ -51,23 +47,26 @@ fn main() { let db = EquipementDatabase::new("./databases/weapons.db").unwrap(); db.initialize_empty_table::("Equipements").unwrap(); db.conn.execute("DELETE FROM Equipements", []).unwrap(); - println!("Processed {global_index} ids"); + println!("Added {global_index} ids to the new database"); b.iter().for_each(|v| database_shnn(&db, v)); let v = db.serialize_vec_from_table::("Equipements", None); - println!("{:#?}", v); - + // println!("Initial deserialisation in DatabaseEquipementStats: {:?}", v); + println!("First entry: {:?}", v.as_ref().unwrap()[0]); // Final deserialisation let final_s = v.unwrap().into_iter().map(InnerEquipementStats::try_from).collect::>(); let v = final_s .iter() .scan(0, |status, eq| { if eq.is_ok() { - *status += 1; + *status = 1; + } else { + *status = 0; } Some(*status) }) .sum::(); - println!("{:#?}, {:#?}", final_s, v); + println!("Final data {:#?}", final_s); + println!("Succeded in parsing {:#?} over {}", v, global_index); } #[allow(dead_code)] @@ -79,7 +78,7 @@ struct FoundFields { } fn parse_special_field(fields: &str) -> FoundFields { // "Arbalète & Distance & 4 & 1 & 3 0 & 3 & 1 & 8 & 16 & pierce & -1 & -1 & 0 & -1 & 2reload, Gls{parmure} 2, 80m & ddlvl{1} ", - let re = regex::Regex::new(r"((?\d)reload)?(, )?(Gls\{parmure\} (?\d))?(, )?(?(\d+)m)?").unwrap(); + let re = regex::Regex::new(r"((?\d)reload)?(, )?(Gls\{parmure\} (?\d))?(, )?((?\d+)m)?").unwrap(); re.captures(fields).map_or(FoundFields::default(), |f| FoundFields { reload: f.name("reload").map(|n| n.as_str().parse().unwrap()), range: f.name("range").map(|v| v.as_str().parse().unwrap()), @@ -106,9 +105,14 @@ fn database_shnn(db: &EquipementDatabase, row: T) { .collect::>() .join(", ") ); - // println!("{}", sql); + // println!("Database Request {}", sql); let r = db.conn.execute(sql, to_params_named(&row).unwrap().to_slice().as_slice()); - println!("Loaded {:?} entries into the database", r); + match r { + Ok(_r) => { + // println!("Loaded {:?} entries into the database", _r); + } + Err(e) => println!("Error: {} while processing entry", e), + }; } fn load_base(index: &mut u8) -> Vec { @@ -127,35 +131,39 @@ fn load_base(index: &mut u8) -> Vec { .iter() .map(|row| { let fields = row.split("&").map(|field| field.trim()).collect::>(); - let FoundFields { reload, range, parmor } = parse_special_field(fields[16]); + let FoundFields { reload, range, parmor } = parse_special_field(fields[15]); *index += 1; + // "% Nom & Type & Dé & + & RM & AB & Pr & In & T2 & T1 & Md & Esq. & Par. & Vit. & Disc. & Spc. & Diff ", + // 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 DatabaseEquipementStats { id: *index, meta_category: "Forme".into(), name: fields[0].to_string(), - category: format!("\"{}\"", fields[1]), + category: serde_json::to_string(&parse_to_type(fields[1]).unwrap()).unwrap(), rarity: 0, cost: 0, - difficulty: fields[16].parse().unwrap_or_default(), - tier: 0, + precision: 0, + difficulty: fields[16].parse().unwrap_or_default(), // NOT PARSED YET + // tier: , damage: fields[2].parse().unwrap_or_default(), p_damage: fields[3].parse().unwrap_or_default(), - precision: fields[4].parse().unwrap_or_default(), - rmax: fields[5].parse().unwrap_or_default(), - armor_break: fields[6].parse().unwrap_or_default(), - protection: fields[7].parse().unwrap_or_default(), - integrity: fields[8].parse().unwrap_or_default(), + rmax: fields[4].parse().unwrap_or_default(), + armor_break: fields[5].parse().unwrap_or_default(), + protection: fields[6].parse().unwrap_or_default(), + integrity: fields[7].parse().unwrap_or_default(), - torque_two_handed: fields[10].parse().unwrap_or_default(), + torque_two_handed: fields[8].parse().unwrap_or_default(), torque_one_handed: fields[9].parse().unwrap_or_default(), // The or default is a problem - damage_type: fields[11].parse().unwrap(), + damage_type: serde_json::to_string(&parse_to_damagetype(fields[10])).unwrap(), - dodge: fields[12].parse().unwrap_or_default(), - parry: fields[13].parse().unwrap_or_default(), - speed: fields[14].parse().unwrap_or_default(), - stealth: fields[15].parse().unwrap_or_default(), + dodge: fields[11].parse().unwrap_or_default(), + parry: fields[12].parse().unwrap_or_default(), + speed: fields[13].parse().unwrap_or_default(), + stealth: fields[14].parse().unwrap_or_default(), reload_cost: serde_json::to_string(&reload).unwrap(), range: range.unwrap_or_default(), + armor_pierce: parmor.unwrap_or_default(), + // meta_category: parse_to_type(fields[1]), // target: fields[5].parse().unwrap(), // Armors ? ..Default::default() @@ -163,3 +171,30 @@ fn load_base(index: &mut u8) -> Vec { }) .collect::>() } + +fn parse_to_damagetype(fields: &str) -> DamageType { + DamageType(fields.split(",").map(|v| ModeParser::lexer(v.trim()).next().unwrap().unwrap().into()).collect::>()) +} + +impl From for DamageMod { + fn from(value: ModeParser) -> Self { + match value { + ModeParser::Primary(v) => DamageMod::Primary(v), + ModeParser::Secondary(v) => DamageMod::Secondary(v), + ModeParser::Tertiary(v) => DamageMod::Tertiary(v), + } + } +} + +fn parse_to_type(text: &str) -> Option { + match text { + "Hast" => Some(WeaponMetaCategory::Staves), + "Tranchantes" => Some(WeaponMetaCategory::Slash), + "Contondantes" => Some(WeaponMetaCategory::Blunt), + "Distance" => Some(WeaponMetaCategory::Ranged), + "Boucliers" => Some(WeaponMetaCategory::Shields), + "Armures" => Some(WeaponMetaCategory::Armor), + "Exotiques" => Some(WeaponMetaCategory::Exotic), + _ => None, + } +} diff --git a/weaponry/src/database.rs b/weaponry/src/database.rs index a372c66..aec7348 100644 --- a/weaponry/src/database.rs +++ b/weaponry/src/database.rs @@ -16,10 +16,11 @@ pub fn get_data( where T: DeserializeOwned + more_fields::FieldsAsSlice, { - let mut query_result = conn.prepare(&generate_select_query::(table_name, filter))?; - Ok(serde_rusqlite::from_rows::(query_result.query([])?) - .filter_map(|s| s.ok()) - .collect()) + serde_rusqlite::from_rows::( + conn.prepare(&generate_select_query::(table_name, filter))? + .query([])?, + ) + .collect() } /// Generate a SELECT query with fields generated from a struct. Returns a SQL request as a String diff --git a/weaponry/src/error.rs b/weaponry/src/error.rs index a410c4d..ede0006 100644 --- a/weaponry/src/error.rs +++ b/weaponry/src/error.rs @@ -16,6 +16,12 @@ pub enum FatalEquipementError { #[error("Deserialisation from json failed : {0}")] SerdeJSON(#[from] serde_json::Error), + + #[error("Deserialisation from json failed at line {0} : {1}]")] + SerdeJSONAt(String, serde_json::Error), + + #[error("Couldn't convert into type {0} with data {1}")] + Conversion(String, String), } #[derive(Error, Debug)] diff --git a/weaponry/src/weaponry_structs/equipement_fields.rs b/weaponry/src/weaponry_structs/equipement_fields.rs index e1d9e1b..cf78892 100644 --- a/weaponry/src/weaponry_structs/equipement_fields.rs +++ b/weaponry/src/weaponry_structs/equipement_fields.rs @@ -2,11 +2,13 @@ // File: weaponry/src/weaponry_structs/equipement_fields.rs //! The inner fields used by the super structs -use std::fmt::Display; - use serde::{Deserialize, Serialize}; +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 @@ -26,14 +28,30 @@ pub enum NatureTarget { /// Enum of all different physical weapon damage types #[allow(clippy::missing_docs_in_private_items, missing_docs)] -#[derive(Clone, Debug, Deserialize, Serialize)] -#[cfg_attr(test, derive(PartialEq))] +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] +// #[cfg_attr(test, derive(PartialEq))] pub enum PhysicalDamageType { Blunt, Slash, Pierce, } +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( + std::any::type_name::().to_owned(), + value.to_string(), + )), + } + } +} + /// Weapon damage, combining the base weapon damage type and it's level /// /// Signifying wether the damage is pure or [secondary] or [[tertiary]] @@ -66,9 +84,46 @@ impl Display for DamageType { } } +// impl TryFrom<&str> for DamageType { +// type Error = FatalEquipementError; + +// fn try_from(value: &str) -> Result { +// let re = regex::Regex::new(r"(?\[\[\w+\]\])|(?\[\w+\])|(?\w+)") +// .unwrap(); +// let v = value +// .split(",") +// .map( +// |v| { +// let groups = re.captures(v).unwrap(); +// *groups +// }, // match v.trim() { +// // _ => Ok(DamageMod::Primary(PhysicalDamageType::Blunt)), +// // } +// ) +// .collect::, FatalEquipementError>>(); +// Ok(Self(v?)) +// } +// } +// impl FromSql for DamageType { +// fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult { +// Ok(DamageType(vec![DamageMod::Secondary( +// PhysicalDamageType::Pierce, +// )])) +// } +// } + +impl Add for DamageType { + type Output = Self; + + fn add(self, rhs: Self) -> Self::Output { + Self(self.0.iter().chain(rhs.0.iter()).cloned().collect()) + } +} + +// TODO: Convert into this category at the end, depending on all important factors /// List all weapon categories #[allow(clippy::missing_docs_in_private_items, missing_docs)] -#[derive(Clone, Debug, PartialEq, Display, Deserialize, Serialize)] +#[derive(Clone, Debug, PartialEq, Display, Deserialize, Serialize, strum::EnumString)] // #[cfg_attr(test, derive(PartialEq))] pub enum WeaponCategory { Exotic, @@ -86,6 +141,22 @@ pub enum WeaponCategory { Bow, Crossbow, Cannon, + // Armor, + // Shield, +} + +// TODO: This is the real initial category +/// 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 { + Staves, + Blunt, + Slash, + Ranged, + Armor, + Shields, + Exotic, } #[cfg(test)] diff --git a/weaponry/src/weaponry_structs/equipement_impl_basics.rs b/weaponry/src/weaponry_structs/equipement_impl_basics.rs index 9b7cb66..3d27023 100644 --- a/weaponry/src/weaponry_structs/equipement_impl_basics.rs +++ b/weaponry/src/weaponry_structs/equipement_impl_basics.rs @@ -107,7 +107,7 @@ impl Display for InnerEquipementStats { vec![format!("Prot:{} Int:{}", self.protection, self.integrity)], ); table.add_row(vec![format!( - "T1/T2 {}/{} Dodge:{} Parry:{} Speed:{} Stealth:{} Agility: {}", + "T1/T2 {:?}/{:?} Dodge:{} Parry:{} Speed:{} Stealth:{} Agility: {}", self.torque_one_handed, self.torque_two_handed, self.dodge, diff --git a/weaponry/src/weaponry_structs/equipement_impl_database.rs b/weaponry/src/weaponry_structs/equipement_impl_database.rs index 47afd3f..f06a714 100644 --- a/weaponry/src/weaponry_structs/equipement_impl_database.rs +++ b/weaponry/src/weaponry_structs/equipement_impl_database.rs @@ -73,6 +73,15 @@ impl FixedRecipe for EquipementFixedRecipe { } } +/// Macro converting a value using serde and mapping an in house error +macro_rules! from_serde { + ($value: expr) => { + serde_json::from_str(&$value).map_err(|e| { + FatalEquipementError::SerdeJSONAt(format!("{} line {}", file!(), line!()), e) + }) + }; +} + // #[allow(clippy::useless_conversion)] impl TryFrom for InnerEquipementStats { type Error = FatalEquipementError; @@ -84,7 +93,8 @@ impl TryFrom for InnerEquipementStats { rarity: value.rarity, // Generic case, into(), serde or cast are equivalent cost: value.cost, difficulty: value.difficulty, - tier: value.tier, + // tier: value.tier, + tier: 0, damage: value.damage, p_damage: value.p_damage, precision: value.precision, @@ -92,20 +102,20 @@ impl TryFrom for InnerEquipementStats { armor_break: value.armor_break, armor_pierce: value.armor_pierce, antimaterial: value.antimaterial, - damage_type: serde_json::from_str(&value.damage_type)?, // Serde and derive are godsent + damage_type: from_serde!(&value.damage_type)?, // Serde and derive are godsent protection: value.protection, integrity: value.integrity, - torque_two_handed: value.torque_two_handed, - torque_one_handed: value.torque_one_handed, + torque_two_handed: from_serde!(&value.torque_two_handed)?, + torque_one_handed: from_serde!(&value.torque_one_handed)?, dodge: value.dodge, parry: value.parry, speed: value.speed, stealth: value.stealth, - category: serde_json::from_str(&value.category)?, - target: serde_json::from_str(&value.target)?, - special: serde_json::from_str(&value.special)?, + category: from_serde!(&value.category)?, + target: from_serde!(&value.target)?, + special: from_serde!(&value.special)?, action_cost: value.action_cost, - reload_cost: serde_json::from_str(&value.reload_cost)?, + reload_cost: from_serde!(&value.reload_cost)?, range: value.range, agility_bonus: value.agility_bonus, }) diff --git a/weaponry/src/weaponry_structs/equipement_impl_logic.rs b/weaponry/src/weaponry_structs/equipement_impl_logic.rs index 36cd772..a42b3f9 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, - WeaponCategory, equipement_fields::PhysicalDamageType, + equipement_fields::{PhysicalDamageType, WeaponMetaCategory}, equipement_structs::InnerEquipementStats, }, }; @@ -94,7 +94,7 @@ mod test { integrity: 2, range: 3, agility_bonus: 4, - category: Some(WeaponCategory::Dagger), + category: Some(WeaponMetaCategory::Staves), special: SpecialCategory(vec!["zero".into()]), damage_type: Some(DamageType(vec![DamageMod::Secondary( PhysicalDamageType::Slash, @@ -119,7 +119,7 @@ mod test { agility_bonus: 9, damage: 10, range: 3, - category: Some(WeaponCategory::Dagger), + category: Some(WeaponMetaCategory::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 ac6c4a6..8da15c6 100644 --- a/weaponry/src/weaponry_structs/equipement_impl_math.rs +++ b/weaponry/src/weaponry_structs/equipement_impl_math.rs @@ -22,10 +22,7 @@ macro_rules! add_two_options { (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) - } + (Some(a), Some(b)) => Some(a + b), } }}; } @@ -53,7 +50,7 @@ impl std::ops::Add for &InnerEquipementStats { 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, + torque_one_handed: add_two_options!(self.torque_one_handed, rhs.torque_one_handed), dodge: self.dodge + rhs.dodge, parry: self.parry + rhs.parry, speed: self.speed + rhs.speed, diff --git a/weaponry/src/weaponry_structs/equipement_structs.rs b/weaponry/src/weaponry_structs/equipement_structs.rs index 0fd7c2d..3f5b285 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}; +use super::{DamageType, SpecialCategory, WeaponCategory, equipement_fields::WeaponMetaCategory}; /// The final equipement list /// @@ -73,18 +73,18 @@ pub struct InnerEquipementStats { pub(super) damage_type: Option, pub(super) protection: u8, pub(super) integrity: u8, - pub(super) torque_two_handed: u8, - pub(super) torque_one_handed: u8, + pub(super) torque_two_handed: u8, // Might be option (single claw) + pub(super) torque_one_handed: Option, // Should be option (bows) pub(super) dodge: u8, pub(super) parry: u8, pub(super) speed: u8, pub(super) stealth: u8, - pub(super) category: Option, - pub(super) target: Option, + pub(super) category: Option, + pub(super) target: Option, // TODO: This might be incorrect, to check pub(super) special: SpecialCategory, pub(super) action_cost: u8, - pub(super) reload_cost: Option, - pub(super) range: u8, + pub(super) reload_cost: Option, // Shouldn't it be Option ? + pub(super) range: u8, // Shoudln't it be Option ? pub(super) agility_bonus: u8, } @@ -127,10 +127,8 @@ pub struct DatabaseEquipementStats { pub protection: u8, #[INTEGER] pub integrity: u8, - #[INTEGER] - pub torque_two_handed: u8, - #[INTEGER] - pub torque_one_handed: u8, + pub torque_two_handed: String, + pub torque_one_handed: String, #[INTEGER] pub dodge: u8, #[INTEGER] @@ -158,7 +156,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,8 +173,8 @@ impl Default for DatabaseEquipementStats { antimaterial: 0, protection: 0, integrity: 0, - torque_two_handed: 0, - torque_one_handed: 0, + torque_two_handed: serde_json::to_string(&0).unwrap(), + torque_one_handed: serde_json::to_string(&None::).unwrap(), dodge: 0, parry: 0, speed: 0, diff --git a/weaponry/src/weaponry_structs/mod.rs b/weaponry/src/weaponry_structs/mod.rs index d9203c8..cf3aab5 100644 --- a/weaponry/src/weaponry_structs/mod.rs +++ b/weaponry/src/weaponry_structs/mod.rs @@ -34,4 +34,6 @@ pub use equipement_structs::{Equipement, InitialEquipementList}; // All generic fields // #[allow(unused_imports)] pub use equipement_fields::PhysicalDamageType; -pub use equipement_fields::{DamageMod, DamageType, NatureTarget, SpecialCategory, WeaponCategory}; +pub use equipement_fields::{ + DamageMod, DamageType, NatureTarget, SpecialCategory, WeaponCategory, WeaponMetaCategory, +};