diff --git a/weaponry/weapons.db b/weaponry/databases/weapons.db similarity index 100% rename from weaponry/weapons.db rename to weaponry/databases/weapons.db diff --git a/weaponry/src/interfaces.rs b/weaponry/src/interfaces.rs index c54f718..1f65804 100644 --- a/weaponry/src/interfaces.rs +++ b/weaponry/src/interfaces.rs @@ -5,14 +5,39 @@ //! handling of the whole crafting process when the times comes #![allow(dead_code)] -// use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; use std::rc::Rc; -/// This element can be converted to tex -pub trait ToTex {} +/// Trait representing a view table +/// +/// These table exist to allow to link several point of interest to a RecipeCollection +/// Please note that while FinalRepresentations and ViewTable are two separate traits, +/// they are always tied together as a view table will alway take specific assumptions +/// on the data present inside therefore not allowing many variations on the underlying +/// implementation of the representation +pub trait ViewTable { + /// The inner type of element that one would be peeking into + /// + /// Usually the final representation of an Item + type InterestElement: RefinedList; -/// Specify this element can be made from parts (Unsure, maybe a way to ensure Add is presend ?) -pub trait FromParts {} + /// Give a list of interesting element indicises to further analyse + fn index_of_interest_points(&self) -> Vec; + + /// Interrogate the FinalRepresentation to find interesting elements + fn find_points_of_interest(&self, representation: &Self::InterestElement); + // An alternative, non Self::Typed way of doing since there is only one usage for now + // fn find_points_of_interest(&self, representation: &impl FinalRepresentation); +} + +/// Trait implemented by any struct holding the final representation of a RecipeCollection +/// +/// This trait is rather placeholder, reminding the user to give only objects that are indeed +/// final representations and contains all important fields calculated +/// +/// While it is possible to enforce from_recipe_collection, doing so would require the viewtable +/// lock itseld to a particular recipe. +/// While it is the case as of now, matters are not yet set in stone +pub trait RefinedList {} /// Trait implemented for the final collection of a recipe, allowing it to be combined with parts /// @@ -105,11 +130,23 @@ pub(super) type FilterType = Box>>; /// A generic Filtering function pub(crate) struct FilterFunction(pub(super) FilterType); -// impl FilterFunction { -// fn new_from_closure(m: &FilterFunctionType) -> Self { -// FilterFunction(Box::new(Rc::new(m))) -// } -// } +/// This element can be converted to tex +pub trait ToTex { + /// Export the object to a Tex string + fn to_tex(&self) -> String; +} + +/// This element can be converted to a csv for further analysis +pub trait ToAnalysis { + /// Convert this object into a csv + fn to_csv(&self) -> String; +} + +/// Garanties that a struct can be generated from a database +pub trait DbSerializable { + /// Serialize the object from a database + fn from_database() -> Self; +} // /// A blanket implementation giving all combinaisons of recipes with another RecipeCollection // /// diff --git a/weaponry/src/weaponry_structs/equipement_advanced_repr.rs b/weaponry/src/weaponry_structs/equipement_advanced_repr.rs new file mode 100644 index 0000000..3c71da0 --- /dev/null +++ b/weaponry/src/weaponry_structs/equipement_advanced_repr.rs @@ -0,0 +1,99 @@ +// Workspace: weaponry +// File: weaponry/src/weaponry_structs/equipement_advanced_repr.rs +//! Give an advanced representation of the equipement, infering more fields (such a dpt, max_dps etc...) +//! +//! The generation of this fields is primordial to allow post filtering and visualisation +//! +//! Note that while ALL fields and representation will likely be backed into a megablob, +//! nothing prevents us to implement the trait for other objects and avoid massive computation +//! of all the fields even when the user will not be interested in them +#![allow(dead_code)] + +use crate::interfaces::RefinedList; + +use super::equipement_structs::InnerStats; + +/// The final representation of the equipement inplementing all the fields needed for processing +pub struct RefinedEquipement { + /// The original inner stats + /// + /// This structs takes ownership of the inner data + inner: InnerStats, + + /// Advanced stats + advanced: AdvancedStats, +} + +pub struct RefinedEquipementList(Vec); + +// Just a checkmark +impl RefinedList for RefinedEquipementList {} + +/// The list of advanced stats infered from an Equipement +#[allow(missing_docs, clippy::missing_docs_in_private_items)] +pub struct AdvancedStats { + damage_per_turn: f64, + damage_per_action: f64, + armor_break_per_turn: f64, + armor_break_per_action: f64, + damage_matrix: DamageMatrix, + /// Armor break factoring in the damage output: While a weapon might have high AB, not having any damage will seriously hinder that AB + expected_armor_break_per_turn: f64, + // All other criterias are already in the inner as raw criterias +} + +/// A damage matrix, crossing damage conditions (high dice to low dice) with precision (high precision to low precision) +/// +/// This simulation does only calculate a very limited preset of damage values +struct DamageMatrix { + /// The inner damage matrix + damage_matrix: Vec, +} +impl DamageMatrix { + /// Get the damage value from given condition + pub fn get_damage(&self, precision: Precision, dices: DiceNumber) -> f64 { + self.damage_matrix[precision.index() + 3 * dices.index()] + } + /// Calculate the damage simulation from a given InnerStats + pub fn calculate_damage(inner: &InnerStats) -> Self { + let _ = inner; + todo!() + } +} + +/// The precision infered for a damage calculation event +pub enum Precision { + High = 9, + Medium = 6, + Low = 3, +} + +/// The number of dices rolled for a damage simulation +pub enum DiceNumber { + High = 7, + Medium = 5, + Low = 3, +} + +impl Precision { + #[inline] + /// Associate an index to the different values + fn index(&self) -> usize { + match self { + Precision::High => 0, + Precision::Medium => 1, + Precision::Low => 2, + } + } +} +impl DiceNumber { + #[inline] + /// Associate an index to the different values + fn index(&self) -> usize { + match self { + DiceNumber::High => 0, + DiceNumber::Medium => 1, + DiceNumber::Low => 2, + } + } +} diff --git a/weaponry/src/weaponry_structs/equipement_impl_basics.rs b/weaponry/src/weaponry_structs/equipement_impl_basics.rs index fc7f57d..252833a 100644 --- a/weaponry/src/weaponry_structs/equipement_impl_basics.rs +++ b/weaponry/src/weaponry_structs/equipement_impl_basics.rs @@ -35,17 +35,13 @@ impl From for Equipement { fn from(val: EqNature) -> Self { Self { stats: val.stats, - // filter_function: FilterFunction(default_filter_for_equipement()), - filter_function: FilterFunction::new(&|sel, lhs| { - match (&sel.target, &lhs.category) { - (Some(a), Some(b)) => a == b, - (None, None) => true, - _ => false, - } - // if let Some(targ) = &sel.target { - // &lhs.category - // } - // & default_filter()(sel, lhs) + // 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) { + (Some(a), Some(b)) => a == b, + (None, None) => true, + _ => false, }), } } diff --git a/weaponry/src/weaponry_structs/equipement_impl_database.rs b/weaponry/src/weaponry_structs/equipement_impl_database.rs index d300254..8ab55b2 100644 --- a/weaponry/src/weaponry_structs/equipement_impl_database.rs +++ b/weaponry/src/weaponry_structs/equipement_impl_database.rs @@ -1,3 +1,30 @@ // Workspace: weaponry // File: weaponry/src/weaponry_structs/equipement_impl_database.rs //! All database specific implementations + +use crate::interfaces::DbSerializable; + +use super::equipement_structs::{EqFinishing, EqMaterial, EqNature, EqShape}; + +//TODO: Fred, make these and I'm happy + +impl DbSerializable for EqShape { + fn from_database() -> Self { + todo!() + } +} +impl DbSerializable for EqMaterial { + fn from_database() -> Self { + todo!() + } +} +impl DbSerializable for EqNature { + fn from_database() -> Self { + todo!() + } +} +impl DbSerializable for EqFinishing { + fn from_database() -> Self { + todo!() + } +} diff --git a/weaponry/src/weaponry_structs/equipement_impl_math.rs b/weaponry/src/weaponry_structs/equipement_impl_math.rs index 7951a98..1f7c501 100644 --- a/weaponry/src/weaponry_structs/equipement_impl_math.rs +++ b/weaponry/src/weaponry_structs/equipement_impl_math.rs @@ -15,6 +15,21 @@ macro_rules! add_to_vec { }}; } +/// Adds either of the vectors or merge them +macro_rules! add_two_options { + ($self: expr, $rhs: expr) => {{ + match ($self.clone(), $rhs.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) + } + } + }}; +} + impl std::ops::Add for &InnerStats { type Output = InnerStats; @@ -34,17 +49,7 @@ impl std::ops::Add for &InnerStats { 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.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) - } - } - }, + damage_type: add_two_options!(self.damage_type, rhs.damage_type), protection: self.protection + rhs.protection, integrity: self.integrity + rhs.integrity, torque_two_handed: self.torque_two_handed + rhs.torque_two_handed, diff --git a/weaponry/src/weaponry_structs/equipement_tools.rs b/weaponry/src/weaponry_structs/equipement_tools.rs new file mode 100644 index 0000000..739aad5 --- /dev/null +++ b/weaponry/src/weaponry_structs/equipement_tools.rs @@ -0,0 +1,16 @@ +// Workspace: weaponry +// File: weaponry/src/weaponry_structs/equipement_tools.rs +//! Tools user facing, implement all that a end user would need +//! +//! This file implements all the functions the main runner will eventually launch + +#![allow(dead_code)] + +/// Tooling utility +fn load_database() {} + +/// Export the data generated to tex +fn export_to_tex() {} + +/// Export the data generated to csv +fn export_to_csv() {} diff --git a/weaponry/src/weaponry_structs/equipement_views.rs b/weaponry/src/weaponry_structs/equipement_views.rs new file mode 100644 index 0000000..3339038 --- /dev/null +++ b/weaponry/src/weaponry_structs/equipement_views.rs @@ -0,0 +1,28 @@ +// Workspace: weaponry +// File: weaponry/src/weaponry_structs/equipement_views.rs +//! Implement the view trait to allow for a list of "Points of Interest" to be created +//! This list is imperative to allow several criterias to be looked up one after the other to gather as many points of data as possible +//! +//! It is mandatory that these points of interest link back to the original data by index and not by reference, to allow this operation to be thread safe + +#![allow(dead_code)] + +use crate::interfaces::ViewTable; + +use super::equipement_advanced_repr::RefinedEquipementList; + +/// A rather full view of an equipement, this multi field allow for a great amount of different operations but incurrs a rather hefty calculation price +struct EquipementFullView {} + +impl ViewTable for EquipementFullView { + type InterestElement = RefinedEquipementList; + + fn index_of_interest_points(&self) -> Vec { + todo!() + } + + fn find_points_of_interest(&self, representation: &Self::InterestElement) { + let _ = representation; + todo!() + } +} diff --git a/weaponry/src/weaponry_structs/mod.rs b/weaponry/src/weaponry_structs/mod.rs index 9bcb277..12fb55a 100644 --- a/weaponry/src/weaponry_structs/mod.rs +++ b/weaponry/src/weaponry_structs/mod.rs @@ -15,6 +15,7 @@ // #[global_allocator] // static GLOBAL: Jemalloc = Jemalloc; +mod equipement_advanced_repr; mod equipement_fields; mod equipement_impl_advanced; mod equipement_impl_basics; @@ -23,6 +24,8 @@ mod equipement_impl_io; mod equipement_impl_logic; mod equipement_impl_math; pub mod equipement_structs; +pub mod equipement_tools; +mod equipement_views; // Republishes the most used symbols // All generic structs