From 37a6531ae48562cfd597e825d854eb5d17874973 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Wed, 15 Jul 2026 19:10:44 +0200 Subject: [PATCH] Merged both tables for resist & bp --- crates/monsters/src/lib.rs | 17 ++------ crates/monsters/src/monster_structs.rs | 55 ++++++++++---------------- 2 files changed, 25 insertions(+), 47 deletions(-) diff --git a/crates/monsters/src/lib.rs b/crates/monsters/src/lib.rs index 56e57cf..08a0ab9 100644 --- a/crates/monsters/src/lib.rs +++ b/crates/monsters/src/lib.rs @@ -25,8 +25,7 @@ use config::monsters::MonsterConfig; use rusqlite::Connection; use crate::monster_structs::{ - CreatureBodyParts, CreatureData, CreatureResistance, CreatureStats, FullMonster, - MonsterAttacks, MonsterSingleAttack, + CreatureBodyPart, CreatureData, CreatureStats, FullMonster, MonsterAttacks, MonsterSingleAttack, }; /// Deserialise a table row (or rows) into the given type and add a nice context message. @@ -72,14 +71,7 @@ fn fetch_all_data(connection: Connection) -> Result, anyhow::Er Some("phase, attack_group, attack_type, name") ); let creature_resistances = fetch_from!( - CreatureResistance, - connection, - creature, - "creature_resistances", - Some("body_part_name") - ); - let creature_body_parts = fetch_from!( - CreatureBodyParts, + CreatureBodyPart, connection, creature, "creature_body_parts", @@ -104,9 +96,8 @@ fn fetch_all_data(connection: Connection) -> Result, anyhow::Er attacks: MonsterAttacks { attacks: creature_attacks, }, - creature_body_parts: todo!(), - resistances: monster_structs::MonsterResistances { - resistances: creature_resistances, + body_parts: monster_structs::CreatureBodyParts { + body_parts: creature_resistances, }, data: creature.clone(), }); diff --git a/crates/monsters/src/monster_structs.rs b/crates/monsters/src/monster_structs.rs index 631a6e0..99d72d4 100644 --- a/crates/monsters/src/monster_structs.rs +++ b/crates/monsters/src/monster_structs.rs @@ -25,14 +25,11 @@ pub struct FullMonster { /// Serialized generic data directly copied from the database table. pub data: CreatureData, - /// Creature body parts and their resists - pub creature_body_parts: CreatureBodyParts, - /// Collection of attacks, wrapped in a helper that exposes useful functions. pub attacks: MonsterAttacks, /// Collection of resistances, wrapped in a helper for convenient iteration. - pub resistances: MonsterResistances, + pub body_parts: CreatureBodyParts, /// Serialized stats directly copied from the database table. pub stats: CreatureStats, @@ -107,9 +104,9 @@ pub struct MonsterAttacks { /// The inner vector contains `MonsterSingleResistance` entries; methods /// on this struct can provide iterators or lookup functions that are /// easier to consume than raw rows. -pub struct MonsterResistances { +pub struct CreatureBodyParts { /// All resistance rows for the monster, as read from the database. - pub resistances: Vec, + pub body_parts: Vec, } /// Represents a single attack entry as deserialized from the database. @@ -164,13 +161,28 @@ pub struct MonsterSingleAttack { } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, FieldsAsSlice)] -pub struct CreatureResistance { - /// The id of the creature that owns these resistances (FOREIGN KEY to `creature_data.id`). +/// All different body parts and their different resists +pub struct CreatureBodyPart { #[INTEGER] pub creature_id: i64, - /// Full name of the body part (e.g. “Head”, “Arm” …). #[TEXT] pub body_part_name: String, + #[INTEGER] + pub threshold_p1: Option, + #[INTEGER] + pub threshold_p2: Option, + #[INTEGER] + pub protection_p1: Option, + #[INTEGER] + pub protection_p2: Option, + #[INTEGER] + pub integrity_p1: Option, + #[INTEGER] + pub integrity_p2: Option, + #[INTEGER] + pub life_points_p1: Option, + #[INTEGER] + pub life_points_p2: Option, #[TEXT] pub slash: Option, #[TEXT] @@ -199,31 +211,6 @@ pub struct CreatureResistance { pub thunder: Option, } -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, FieldsAsSlice)] -/// All different body parts and their different resists -pub struct CreatureBodyParts { - #[INTEGER] - pub creature_id: i64, - #[TEXT] - pub body_part_name: String, - #[INTEGER] - pub threshold_p1: Option, - #[INTEGER] - pub threshold_p2: Option, - #[INTEGER] - pub protection_p1: Option, - #[INTEGER] - pub protection_p2: Option, - #[INTEGER] - pub integrity_p1: Option, - #[INTEGER] - pub integrity_p2: Option, - #[INTEGER] - pub life_points_p1: Option, - #[INTEGER] - pub life_points_p2: Option, -} - #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, FieldsAsSlice)] /// All creature stats pub struct CreatureStats {