From a5d44b82e47c8c96cde7f08d66a745cd528ec679 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Mon, 17 Feb 2025 18:59:37 +0100 Subject: [PATCH] Add basic database implementation and some Scenario skeleton --- weaponry/src/interfaces.rs | 26 +++++- .../equipement_impl_database.rs | 46 +++++----- .../weaponry_structs/equipement_scenario.rs | 85 +++++++++++++++++++ .../src/weaponry_structs/equipement_views.rs | 4 +- weaponry/src/weaponry_structs/mod.rs | 1 + 5 files changed, 133 insertions(+), 29 deletions(-) create mode 100644 weaponry/src/weaponry_structs/equipement_scenario.rs diff --git a/weaponry/src/interfaces.rs b/weaponry/src/interfaces.rs index f642d20..58e512a 100644 --- a/weaponry/src/interfaces.rs +++ b/weaponry/src/interfaces.rs @@ -20,13 +20,13 @@ pub trait ViewTable { /// The inner type of element that one would be peeking into /// /// Usually the final representation of an Item - type InterestElement: RefinedList; + type InterestElementList: 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); + fn find_points_of_interest(&self, representation: &Self::InterestElementList); // 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); } @@ -148,13 +148,26 @@ pub trait ToCSV { } /// Garanties that a struct can be generated from a database +#[deprecated] pub trait DbSerializable { /// Serialize the object from a database fn from_database() -> Self; } +/// A generic database+connection, handling all the deserialization of the inner types +pub trait RecipeDatabase { + /// Serialize a vector of objects of the given type in the specified table of the underlying database + fn serialize_vec_from_table(table: &str) -> Result; + + /// Serialize a specified vector of objects of the given type with an additionnal restriction + fn serialize_vec_from_table_with_query( + table: &str, + query: &str, + ) -> Result; +} + /// Trait implemented by any struct aiming to be a public recipe -pub trait FixedRecipe: DbSerializable { +pub trait FixedRecipe { /// Struct representing the database type, most likely a string type Database; /// Struct representing the keylist type, most likely a usize @@ -179,18 +192,23 @@ pub trait Reportable { /// The inner working while somehow abstracted are very tied together and tied to the impl pub trait Scenario { /// The inner database type - type DatabaseType; //: Database; + type DatabaseType: RecipeDatabase; /// The type of viewtable that must be returned by the scenario // Could also use dyn dispatch but since all of it is so tied down... type ViewTableType: ViewTable; /// The type of the final recipe list type FinalListType: RefinedList; + /// Inner configuration + type Config; /// Load all database into intermediate representation fn load_from_database() -> Result where Self: std::marker::Sized; + /// Configure the scenario to the user's needs + fn configure_scenario(&mut self, config: Self::Config) -> Result<(), EquipementError>; + // All these steps should be implemented but not required // enforcing them helps writing new impls more easily but is not really nice in any way // diff --git a/weaponry/src/weaponry_structs/equipement_impl_database.rs b/weaponry/src/weaponry_structs/equipement_impl_database.rs index 8ab55b2..271decd 100644 --- a/weaponry/src/weaponry_structs/equipement_impl_database.rs +++ b/weaponry/src/weaponry_structs/equipement_impl_database.rs @@ -2,29 +2,29 @@ // File: weaponry/src/weaponry_structs/equipement_impl_database.rs //! All database specific implementations -use crate::interfaces::DbSerializable; +// use crate::interfaces::DbSerializable; -use super::equipement_structs::{EqFinishing, EqMaterial, EqNature, EqShape}; +// use super::equipement_structs::{EqFinishing, EqMaterial, EqNature, EqShape}; -//TODO: Fred, make these and I'm happy +// //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!() - } -} +// 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_scenario.rs b/weaponry/src/weaponry_structs/equipement_scenario.rs new file mode 100644 index 0000000..da91630 --- /dev/null +++ b/weaponry/src/weaponry_structs/equipement_scenario.rs @@ -0,0 +1,85 @@ +// Workspace: weaponry +// File: weaponry/src/weaponry_structs/equipement_scenario.rs +//! Implementations of a full scenario, +//! +//! These implementation must take care of everything from database retrieval to view exporting, +//! however all they mostly do is glue together all the parts designed in the interface, +//! and therefore mostly serves as a TO-DO list +//! + +#![allow(dead_code)] + +use crate::interfaces::{RecipeDatabase, Scenario, ViewTable}; + +use super::equipement_advanced_repr::RefinedEquipementList; + +/// Mock of the existing database +pub struct DatabaseMock {} +impl RecipeDatabase for DatabaseMock { + fn serialize_vec_from_table(table: &str) -> Result { + let _ = table; + todo!() + } + + fn serialize_vec_from_table_with_query( + table: &str, + query: &str, + ) -> Result { + let _ = table; + let _ = query; + todo!() + } +} +/// Mock config +pub struct ConfigMock {} +/// Mock Viewtable +pub struct ViewtableMock {} +impl ViewTable for ViewtableMock { + type InterestElementList = RefinedEquipementList; + + fn index_of_interest_points(&self) -> Vec { + todo!() + } + + fn find_points_of_interest(&self, representation: &Self::InterestElementList) { + let _ = representation; + todo!() + } +} + +/// A simple cross recipe scenario +#[allow(clippy::missing_docs_in_private_items)] +pub struct CrossRecipeScenario { + database: DatabaseMock, + config: ConfigMock, +} + +impl Scenario for CrossRecipeScenario { + type DatabaseType = DatabaseMock; + type ViewTableType = ViewtableMock; + type FinalListType = RefinedEquipementList; + type Config = ConfigMock; + + fn load_from_database() -> Result + where + Self: std::marker::Sized, + { + todo!() + } + + fn configure_scenario( + &mut self, + config: Self::Config, + ) -> Result<(), crate::error::EquipementError> { + self.config = config; + Ok(()) + } + + fn generate_refined_recipes(&self) -> Self::FinalListType { + todo!() + } + + fn generate_view_tables(&self) -> Self::ViewTableType { + todo!() + } +} diff --git a/weaponry/src/weaponry_structs/equipement_views.rs b/weaponry/src/weaponry_structs/equipement_views.rs index 3339038..f1162c7 100644 --- a/weaponry/src/weaponry_structs/equipement_views.rs +++ b/weaponry/src/weaponry_structs/equipement_views.rs @@ -15,13 +15,13 @@ use super::equipement_advanced_repr::RefinedEquipementList; struct EquipementFullView {} impl ViewTable for EquipementFullView { - type InterestElement = RefinedEquipementList; + type InterestElementList = RefinedEquipementList; fn index_of_interest_points(&self) -> Vec { todo!() } - fn find_points_of_interest(&self, representation: &Self::InterestElement) { + fn find_points_of_interest(&self, representation: &Self::InterestElementList) { let _ = representation; todo!() } diff --git a/weaponry/src/weaponry_structs/mod.rs b/weaponry/src/weaponry_structs/mod.rs index 7040c4f..f702895 100644 --- a/weaponry/src/weaponry_structs/mod.rs +++ b/weaponry/src/weaponry_structs/mod.rs @@ -23,6 +23,7 @@ mod equipement_impl_database; mod equipement_impl_io; mod equipement_impl_logic; mod equipement_impl_math; +mod equipement_scenario; pub mod equipement_structs; pub mod equipement_tools; mod equipement_views;