diff --git a/weaponry/src/interfaces.rs b/weaponry/src/interfaces.rs index 82a781b..7b0733a 100644 --- a/weaponry/src/interfaces.rs +++ b/weaponry/src/interfaces.rs @@ -217,13 +217,18 @@ pub trait Scenario { /// Inner configuration type Config; - /// Load all database into intermediate representation - fn load_from_database() -> Result + /// Create a Scenario from a given config + fn new_with_config(config: Self::Config) -> Result where - Self: std::marker::Sized; + Self: Sized; - /// Configure the scenario to the user's needs - fn configure_scenario(&mut self, config: Self::Config) -> Result<(), FatalEquipementError>; + // /// 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<(), FatalEquipementError>; // 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_scenario.rs b/weaponry/src/weaponry_structs/equipement_scenario.rs index f0116f6..3c8ed18 100644 --- a/weaponry/src/weaponry_structs/equipement_scenario.rs +++ b/weaponry/src/weaponry_structs/equipement_scenario.rs @@ -9,7 +9,10 @@ #![allow(dead_code)] -use crate::interfaces::{RecipeDatabase, Scenario, ViewTable}; +use crate::{ + error::{EquipementError, FatalEquipementError}, + interfaces::{RecipeDatabase, Scenario, ViewTable}, +}; use super::equipement_advanced_repr::RefinedEquipementList; @@ -30,13 +33,13 @@ impl RecipeDatabase for DatabaseMock { table: &str, fields: &[&str], query: &str, - ) -> std::result::Result, crate::error::FatalEquipementError> { + ) -> std::result::Result, FatalEquipementError> { let _ = table; let _ = query; todo!() } - fn new(origin: &str) -> Result + fn new(origin: &str) -> Result where Self: std::marker::Sized, { @@ -44,7 +47,7 @@ impl RecipeDatabase for DatabaseMock { todo!() } - fn initialize_empty_table(table: &str) -> Result<(), crate::error::EquipementError> { + fn initialize_empty_table(table: &str) -> Result<(), EquipementError> { let _ = table; todo!() } @@ -79,22 +82,19 @@ impl Scenario for CrossRecipeScenario { type FinalListType = RefinedEquipementList; type Config = ConfigMock; - fn load_from_database() -> Result + fn new_with_config(config: Self::Config) -> Result where - Self: std::marker::Sized, + Self: Sized, { - todo!() - } - - fn configure_scenario( - &mut self, - config: Self::Config, - ) -> Result<(), crate::error::FatalEquipementError> { - self.config = config; - Ok(()) + Ok(Self { + // TODO: Correct this relative path abomination + database: Self::DatabaseType::new("./databases/weapons.db")?, + config, + }) } fn generate_refined_recipes(&self) -> Self::FinalListType { + let _all_parts = &self.database; todo!() } diff --git a/weaponry/src/weaponry_structs/equipement_structs.rs b/weaponry/src/weaponry_structs/equipement_structs.rs index b97835c..1bb9c4d 100644 --- a/weaponry/src/weaponry_structs/equipement_structs.rs +++ b/weaponry/src/weaponry_structs/equipement_structs.rs @@ -2,7 +2,7 @@ // File: weaponry/src/weaponry_structs/equipement_structs.rs //! Base equipement structures -use std::rc::Rc; +use std::{collections::HashMap, rc::Rc, sync::LazyLock}; use serde::{Deserialize, Serialize}; use struct_field_names_as_array::FieldNamesAsArray; @@ -90,6 +90,49 @@ pub struct InnerEquipementStats { pub(super) agility_bonus: u8, } +#[allow(dead_code)] +/// A manually implemented hashmap of all values +// TODO: ADD A PROC MACRO TO AUTO_DERIVE THIS +static INNER_EQ_HASHMAP: LazyLock> = LazyLock::new(|| { + HashMap::from([ + ("id".to_string(), "TEXT".to_string()), + ("name".to_string(), "TEXT".to_string()), + ("rarity".to_string(), "TEXT".to_string()), + ("cost".to_string(), "TEXT".to_string()), + ("difficulty".to_string(), "TEXT".to_string()), + ("tier".to_string(), "TEXT".to_string()), + ("damage".to_string(), "TEXT".to_string()), + ("p_damage".to_string(), "TEXT".to_string()), + ("precision".to_string(), "TEXT".to_string()), + ("rmax".to_string(), "TEXT".to_string()), + ("armor_break".to_string(), "TEXT".to_string()), + ("armor_pierce".to_string(), "TEXT".to_string()), + ("antimaterial".to_string(), "TEXT".to_string()), + ("damage_type".to_string(), "TEXT".to_string()), + ("protection".to_string(), "TEXT".to_string()), + ("integrity".to_string(), "TEXT".to_string()), + ( + "torque_two_handed".to_string(), + "torque_two_handed".to_string(), + ), + ( + "torque_one_handed".to_string(), + "torque_one_handed".to_string(), + ), + ("dodge".to_string(), "TEXT".to_string()), + ("parry".to_string(), "TEXT".to_string()), + ("speed".to_string(), "TEXT".to_string()), + ("stealth".to_string(), "TEXT".to_string()), + ("category".to_string(), "TEXT".to_string()), + ("target".to_string(), "TEXT".to_string()), + ("special".to_string(), "TEXT".to_string()), + ("action_cost".to_string(), "TEXT".to_string()), + ("reload_cost".to_string(), "TEXT".to_string()), + ("range".to_string(), "TEXT".to_string()), + ("agility_bonus".to_string(), "TEXT".to_string()), + ]) +}); + #[doc(hidden)] macro_rules! r { () => { @@ -147,7 +190,9 @@ mod test { EqFinishing, EqMaterial, EqNature, EqShape, Equipement, InitialEquipementList, InnerEquipementStats, }; - use crate::interfaces::RecipeCollection; + use crate::{ + interfaces::RecipeCollection, weaponry_structs::equipement_structs::INNER_EQ_HASHMAP, + }; fn list_equip() -> Vec { (0..10) @@ -185,4 +230,11 @@ mod test { fn test_default_behaviour() { unimplemented!() } + + #[test] + fn test_const_fields() { + let c = &INNER_EQ_HASHMAP; + assert!(!c.keys().len() > 0); + assert!(!c.values().len() > 0); + } }