From ddb70c1cb3f9936161b139c6bcfd580300ca6308 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Thu, 13 Feb 2025 03:22:58 +0100 Subject: [PATCH] Adds placeholders for refining and views --- weaponry/{ => databases}/weapons.db | Bin weaponry/src/interfaces.rs | 61 ++++++++--- .../equipement_advanced_repr.rs | 99 ++++++++++++++++++ .../equipement_impl_basics.rs | 18 ++-- .../equipement_impl_database.rs | 27 +++++ .../src/weaponry_structs/equipement_tools.rs | 1 + .../src/weaponry_structs/equipement_views.rs | 28 +++++ weaponry/src/weaponry_structs/mod.rs | 2 + 8 files changed, 210 insertions(+), 26 deletions(-) rename weaponry/{ => databases}/weapons.db (100%) create mode 100644 weaponry/src/weaponry_structs/equipement_advanced_repr.rs create mode 100644 weaponry/src/weaponry_structs/equipement_views.rs 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 2252354..1f65804 100644 --- a/weaponry/src/interfaces.rs +++ b/weaponry/src/interfaces.rs @@ -5,20 +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 { - /// Export the object to a Tex string - fn to_tex() -> String; +/// 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; + + /// 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); } -/// This element can be converted to a csv for further analysis -pub trait ToAnalysis { - /// Convert this object into a csv - fn to_csv() -> String; -} +/// 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 /// @@ -111,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_tools.rs b/weaponry/src/weaponry_structs/equipement_tools.rs index 1099749..739aad5 100644 --- a/weaponry/src/weaponry_structs/equipement_tools.rs +++ b/weaponry/src/weaponry_structs/equipement_tools.rs @@ -2,6 +2,7 @@ // 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)] 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 6e3dd86..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; @@ -24,6 +25,7 @@ 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