Adds a basic (and very lame) static field type representation

This commit is contained in:
Dandaedre 2025-02-17 23:43:20 +01:00
parent ece331b2b2
commit d8d976dcdc
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
3 changed files with 79 additions and 22 deletions

View File

@ -217,13 +217,18 @@ pub trait Scenario {
/// Inner configuration
type Config;
/// Load all database into intermediate representation
fn load_from_database() -> Result<Self, FatalEquipementError>
/// Create a Scenario from a given config
fn new_with_config(config: Self::Config) -> Result<Self, EquipementError>
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<Self, FatalEquipementError>
// 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

View File

@ -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<Vec<T>, crate::error::FatalEquipementError> {
) -> std::result::Result<Vec<T>, FatalEquipementError> {
let _ = table;
let _ = query;
todo!()
}
fn new(origin: &str) -> Result<Self, crate::error::FatalEquipementError>
fn new(origin: &str) -> Result<Self, FatalEquipementError>
where
Self: std::marker::Sized,
{
@ -44,7 +47,7 @@ impl RecipeDatabase for DatabaseMock {
todo!()
}
fn initialize_empty_table<T>(table: &str) -> Result<(), crate::error::EquipementError> {
fn initialize_empty_table<T>(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<Self, crate::error::FatalEquipementError>
fn new_with_config(config: Self::Config) -> Result<Self, EquipementError>
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!()
}

View File

@ -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<HashMap<String, String>> = 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<Equipement> {
(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);
}
}