A lot of shitcode to get the first import working
This commit is contained in:
parent
5738f0fd74
commit
a2269ccb87
|
|
@ -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"
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -3,33 +3,29 @@
|
|||
//! Example of a typical workload
|
||||
//!
|
||||
|
||||
use logos::Logos;
|
||||
use more_fields::FieldsAsSlice;
|
||||
use serde::Serialize;
|
||||
use serde_rusqlite::to_params_named;
|
||||
use weaponry::interfaces::RecipeDatabase;
|
||||
use weaponry::weaponry_structs::WeaponCategory;
|
||||
use weaponry::weaponry_structs::equipement_impl_database::EquipementDatabase;
|
||||
use weaponry::weaponry_structs::equipement_structs::{DatabaseEquipementStats, InnerEquipementStats};
|
||||
use weaponry::weaponry_structs::{DamageMod, DamageType, PhysicalDamageType, WeaponMetaCategory};
|
||||
|
||||
#[derive(Logos, Debug, PartialEq)]
|
||||
enum ModeParser {
|
||||
#[regex(r"\[\[\w+\]\]", |lex| std::convert::TryInto::<PhysicalDamageType>::try_into(&lex.slice()[2..lex.slice().len()-2]).unwrap())]
|
||||
Tertiary(PhysicalDamageType),
|
||||
#[regex(r"\[\w+\]", |lex| std::convert::TryInto::<PhysicalDamageType>::try_into(&lex.slice()[1..lex.slice().len()-1]).unwrap())]
|
||||
Secondary(PhysicalDamageType),
|
||||
#[regex(r"\w+", |lex| std::convert::TryInto::<PhysicalDamageType>::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::<DatabaseEquipementStats>("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::<DatabaseEquipementStats>("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::<Vec<_>>();
|
||||
let v = final_s
|
||||
.iter()
|
||||
.scan(0, |status, eq| {
|
||||
if eq.is_ok() {
|
||||
*status += 1;
|
||||
*status = 1;
|
||||
} else {
|
||||
*status = 0;
|
||||
}
|
||||
Some(*status)
|
||||
})
|
||||
.sum::<i32>();
|
||||
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"((?<reload>\d)reload)?(, )?(Gls\{parmure\} (?<parmure>\d))?(, )?(?<range>(\d+)m)?").unwrap();
|
||||
let re = regex::Regex::new(r"((?<reload>\d)reload)?(, )?(Gls\{parmure\} (?<parmure>\d))?(, )?((?<range>\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<T: Serialize>(db: &EquipementDatabase, row: T) {
|
|||
.collect::<Vec<_>>()
|
||||
.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<DatabaseEquipementStats> {
|
||||
|
|
@ -127,35 +131,39 @@ fn load_base(index: &mut u8) -> Vec<DatabaseEquipementStats> {
|
|||
.iter()
|
||||
.map(|row| {
|
||||
let fields = row.split("&").map(|field| field.trim()).collect::<Vec<_>>();
|
||||
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<DatabaseEquipementStats> {
|
|||
})
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
fn parse_to_damagetype(fields: &str) -> DamageType {
|
||||
DamageType(fields.split(",").map(|v| ModeParser::lexer(v.trim()).next().unwrap().unwrap().into()).collect::<Vec<_>>())
|
||||
}
|
||||
|
||||
impl From<ModeParser> 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<WeaponMetaCategory> {
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
|
@ -16,10 +16,11 @@ pub fn get_data<T>(
|
|||
where
|
||||
T: DeserializeOwned + more_fields::FieldsAsSlice,
|
||||
{
|
||||
let mut query_result = conn.prepare(&generate_select_query::<T>(table_name, filter))?;
|
||||
Ok(serde_rusqlite::from_rows::<T>(query_result.query([])?)
|
||||
.filter_map(|s| s.ok())
|
||||
.collect())
|
||||
serde_rusqlite::from_rows::<T>(
|
||||
conn.prepare(&generate_select_query::<T>(table_name, filter))?
|
||||
.query([])?,
|
||||
)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Generate a SELECT query with fields generated from a struct. Returns a SQL request as a String
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -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<Self, Self::Error> {
|
||||
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::<Self>().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<Self, Self::Error> {
|
||||
// let re = regex::Regex::new(r"(?<tertiary>\[\[\w+\]\])|(?<secondary>\[\w+\])|(?<pure>\w+)")
|
||||
// .unwrap();
|
||||
// let v = value
|
||||
// .split(",")
|
||||
// .map(
|
||||
// |v| {
|
||||
// let groups = re.captures(v).unwrap();
|
||||
// *groups
|
||||
// }, // match v.trim() {
|
||||
// // _ => Ok(DamageMod::Primary(PhysicalDamageType::Blunt)),
|
||||
// // }
|
||||
// )
|
||||
// .collect::<Result<Vec<DamageMod>, FatalEquipementError>>();
|
||||
// Ok(Self(v?))
|
||||
// }
|
||||
// }
|
||||
// impl FromSql for DamageType {
|
||||
// fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult<Self> {
|
||||
// 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)]
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<DatabaseEquipementStats> for InnerEquipementStats {
|
||||
type Error = FatalEquipementError;
|
||||
|
|
@ -84,7 +93,8 @@ impl TryFrom<DatabaseEquipementStats> 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<DatabaseEquipementStats> 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,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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,),
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<DamageType>,
|
||||
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<u8>, // Should be option (bows)
|
||||
pub(super) dodge: u8,
|
||||
pub(super) parry: u8,
|
||||
pub(super) speed: u8,
|
||||
pub(super) stealth: u8,
|
||||
pub(super) category: Option<WeaponCategory>,
|
||||
pub(super) target: Option<WeaponCategory>,
|
||||
pub(super) category: Option<WeaponMetaCategory>,
|
||||
pub(super) target: Option<WeaponMetaCategory>, // TODO: This might be incorrect, to check
|
||||
pub(super) special: SpecialCategory,
|
||||
pub(super) action_cost: u8,
|
||||
pub(super) reload_cost: Option<u8>,
|
||||
pub(super) range: u8,
|
||||
pub(super) reload_cost: Option<u8>, // 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::<DamageType>).unwrap(),
|
||||
category: serde_json::to_string(&None::<WeaponCategory>).unwrap(),
|
||||
category: serde_json::to_string(&None::<WeaponMetaCategory>).unwrap(),
|
||||
target: serde_json::to_string(&None::<WeaponCategory>).unwrap(),
|
||||
special: serde_json::to_string(&SpecialCategory::default()).unwrap(),
|
||||
reload_cost: serde_json::to_string(&None::<u8>).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::<u8>).unwrap(),
|
||||
dodge: 0,
|
||||
parry: 0,
|
||||
speed: 0,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue