From 3af43de27eaa07099ecae5695bd9772641cc5051 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Tue, 18 Feb 2025 22:59:42 +0100 Subject: [PATCH] Implements a part of the scenarios --- weaponry/src/interfaces.rs | 4 +- .../weaponry_structs/equipement_scenario.rs | 51 +++++++++++++++---- .../src/weaponry_structs/equipement_views.rs | 2 +- 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/weaponry/src/interfaces.rs b/weaponry/src/interfaces.rs index a949259..8168595 100644 --- a/weaponry/src/interfaces.rs +++ b/weaponry/src/interfaces.rs @@ -29,7 +29,7 @@ pub trait ViewTable { fn index_of_interest_points(&self) -> Vec; /// Interrogate the FinalRepresentation to find interesting elements - fn find_points_of_interest(&self, representation: &Self::InterestElementList); + fn find_points_of_interest(representation: &Self::InterestElementList) -> Self; // 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); } @@ -241,7 +241,7 @@ pub trait Scenario { // fn refine_recipes(&self); /// Generate the final list type - fn generate_refined_recipes(&self) -> Self::FinalListType; + fn generate_refined_recipes(&self) -> Result; /// Gather the selected view tables /// All the inner generation is done gradually and populate all section to finally generate the views diff --git a/weaponry/src/weaponry_structs/equipement_scenario.rs b/weaponry/src/weaponry_structs/equipement_scenario.rs index f651d3c..af7098c 100644 --- a/weaponry/src/weaponry_structs/equipement_scenario.rs +++ b/weaponry/src/weaponry_structs/equipement_scenario.rs @@ -9,10 +9,13 @@ #![allow(dead_code)] +use crate::weaponry_structs::Equipement; +use crate::weaponry_structs::InitialEquipementList; +use crate::weaponry_structs::equipement_structs::InnerEquipementStats; use crate::{ error::{EquipementError, FatalEquipementError}, - interfaces::{RecipeDatabase, Scenario, ViewTable}, - weaponry_structs::equipement_structs::InnerEquipementStats, + interfaces::{RecipeCollection, RecipeDatabase, Scenario, ViewTable}, + weaponry_structs::equipement_structs::{EqFinishing, EqMaterial, EqNature, EqShape}, }; use super::equipement_advanced_repr::RefinedEquipementList; @@ -54,7 +57,7 @@ impl ViewTable for ViewtableMock { todo!() } - fn find_points_of_interest(&self, representation: &Self::InterestElementList) { + fn find_points_of_interest(representation: &Self::InterestElementList) -> Self { let _ = representation; todo!() } @@ -67,6 +70,22 @@ pub struct CrossRecipeScenario { config: ConfigMock, } +/// Automatically deserialize into an equipement +// TODO: This macro only exists because no blanket implementation or function does this *relatively* easy step +macro_rules! deserde_into_equipement { + ( $db:expr, $name:expr, $type:ident) => { + InitialEquipementList::from_vectored( + $db.serialize_vec_from_table::( + "Equipement", + Some(&format!("CATEGORY == {}", $name)), + )? + .into_iter() + .map(|eq| $type { stats: eq }.into()) + .collect::>(), + ) + }; +} + impl Scenario for CrossRecipeScenario { type DatabaseType = DatabaseMock; type ViewTableType = ViewtableMock; @@ -84,15 +103,27 @@ impl Scenario for CrossRecipeScenario { }) } - fn generate_refined_recipes(&self) -> Self::FinalListType { - let _all_parts = &self - .database - .serialize_vec_from_table::("bob", Some("CATEGOTY == 'Bobitty'")); - todo!() + fn generate_refined_recipes(&self) -> Result { + // TODO: Depending on config, a different filter might be given here + let eq_shape = deserde_into_equipement!(self.database, "Shape", EqShape); + let eq_material = deserde_into_equipement!(self.database, "Material", EqMaterial); + let eq_nature = deserde_into_equipement!(self.database, "Nature", EqNature); + let eq_finishing = deserde_into_equipement!(self.database, "Finishing", EqFinishing); + + // No op, just clarity + // TODO: Depending on config this step might differ + let mut f_list = eq_shape; + f_list.combine_all(&eq_material); + f_list.combine_all(&eq_nature); + f_list.combine_all(&eq_finishing); + + // This oneline is neat + Ok(f_list.into()) } fn generate_view_tables(&self, equipement_list: Self::FinalListType) -> Self::ViewTableType { - let _ = equipement_list; - todo!() + // TODO: Change this depending on the config ? or maybe a scenario is inerently tied to a viewtable ? + // The polymorphism will depend on many factors not yet known :( + Self::ViewTableType::find_points_of_interest(&equipement_list) } } diff --git a/weaponry/src/weaponry_structs/equipement_views.rs b/weaponry/src/weaponry_structs/equipement_views.rs index f1162c7..f217e98 100644 --- a/weaponry/src/weaponry_structs/equipement_views.rs +++ b/weaponry/src/weaponry_structs/equipement_views.rs @@ -21,7 +21,7 @@ impl ViewTable for EquipementFullView { todo!() } - fn find_points_of_interest(&self, representation: &Self::InterestElementList) { + fn find_points_of_interest(representation: &Self::InterestElementList) -> Self { let _ = representation; todo!() }