Lay the groundwork for the database intermediate object representation

This commit is contained in:
Dandaedre 2025-02-18 23:50:22 +01:00
parent 3af43de27e
commit 8bb6d09b15
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
4 changed files with 70 additions and 7 deletions

Binary file not shown.

View File

@ -0,0 +1,27 @@
// Workspace: weaponry
// File: examples/typical_wl_recipe.rs
//! Example of a typical workload
//!
use serde_rusqlite::to_params;
use weaponry::interfaces::RecipeDatabase;
use weaponry::weaponry_structs::equipement_impl_database::EquipementDatabase;
use weaponry::weaponry_structs::equipement_structs::InnerEquipementStats;
fn main() {
let db = EquipementDatabase::new("./databases/weapons.db").unwrap();
db.initialize_empty_table::<InnerEquipementStats>("Eq_test")
.unwrap();
let v = db.serialize_vec_from_table::<InnerEquipementStats>("InnerStats", None);
db.conn
.execute(
"INSERT INTO example (id, name) VALUES (?,?)",
to_params(InnerEquipementStats::random_new()).unwrap(),
)
.unwrap();
// let mut r = db.conn.prepare("SELECT * FROM InnerStats").unwrap();
// let mut v = r.query([]).unwrap();
// println!("{:?}:\n {:#?}", db, r);
println!("{:?}", v);
}

View File

@ -13,6 +13,7 @@ use rusqlite::Connection;
use serde::de::DeserializeOwned;
/// Struct for database connection.
#[derive(Debug)]
pub struct EquipementDatabase {
/// Connection parameter for rusqlite
pub conn: rusqlite::Connection,

View File

@ -52,15 +52,50 @@ impl<T> FilterFunction<T> {
Self(Box::new(Rc::new(filter)))
}
}
/// The inner statistics of the equipement, used across all parts and final weapon
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
#[derive(Clone, Default, FieldsAsSlice, Debug, Deserialize, Serialize)]
#[cfg_attr(test, derive(PartialEq))]
pub struct InnerEquipementStats {
#[INTEGER]
pub id: Vec<u8>,
pub name: Vec<String>,
pub(super) rarity: u8,
pub(super) cost: u8,
pub(super) difficulty: u8,
pub(super) tier: u8,
pub(super) damage: u8,
pub(super) p_damage: u8,
pub(super) precision: i8,
pub(super) rmax: u8,
pub(super) armor_break: u8,
pub(super) armor_pierce: u8,
pub(super) antimaterial: u8,
pub(super) damage_type: Option<DamageType>,
pub(super) protection: u8,
pub(super) integrity: u8,
pub(super) torque_two_handed: u8,
pub(super) torque_one_handed: u8,
pub(super) dodge: u8,
pub(super) parry: u8,
pub(super) speed: u8,
pub(super) stealth: u8,
pub(super) category: Option<WeaponCategory>,
pub(super) target: Option<WeaponCategory>,
pub(super) special: SpecialCategory,
pub(super) action_cost: u8,
pub(super) reload_cost: Option<u8>,
pub(super) range: u8,
pub(super) agility_bonus: u8,
}
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
#[derive(Clone, Default, FieldsAsSlice, Debug, Deserialize, Serialize)]
#[cfg_attr(test, derive(PartialEq))]
pub struct DatabaseEquipementStats {
#[INTEGER]
pub id: u8,
pub meta_category: String,
pub name: String,
#[INTEGER]
pub(super) rarity: u8,
#[INTEGER]
@ -83,7 +118,7 @@ pub struct InnerEquipementStats {
pub(super) armor_pierce: u8,
#[INTEGER]
pub(super) antimaterial: u8,
pub(super) damage_type: Option<DamageType>,
pub(super) damage_type: String,
#[INTEGER]
pub(super) protection: u8,
#[INTEGER]
@ -100,12 +135,12 @@ pub struct InnerEquipementStats {
pub(super) speed: u8,
#[INTEGER]
pub(super) stealth: u8,
pub(super) category: Option<WeaponCategory>,
pub(super) target: Option<WeaponCategory>,
pub(super) special: SpecialCategory,
pub(super) category: String,
pub(super) target: String,
pub(super) special: String,
#[INTEGER]
pub(super) action_cost: u8,
pub(super) reload_cost: Option<u8>,
pub(super) reload_cost: String,
#[INTEGER]
pub(super) range: u8,
#[INTEGER]