From 6e29b31978546574de6cfb06a0ae31491e19c6a2 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 5 Jan 2022 11:05:15 -0500 Subject: [PATCH] Reorganise components a little --- src/components.rs | 79 +++------------------------------------- src/components/enums.rs | 36 ++++++++++++++++++ src/components/simple.rs | 51 ++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 74 deletions(-) create mode 100644 src/components/enums.rs create mode 100644 src/components/simple.rs diff --git a/src/components.rs b/src/components.rs index 38a47d8..e721036 100644 --- a/src/components.rs +++ b/src/components.rs @@ -1,3 +1,6 @@ +mod enums; +mod simple; + use std::collections::HashMap; use ::rltk::{Point, RGB}; @@ -6,6 +9,8 @@ use ::specs::error::NoError; use ::specs::prelude::*; use ::specs::saveload::{ConvertSaveload, Marker}; use ::specs_derive::*; +pub use enums::*; +pub use simple::*; use crate::gamesystem::attr_bonus; @@ -41,9 +46,6 @@ pub struct Renderable { pub render_order: i32, } -#[derive(Component, Debug, Clone, Serialize, Deserialize, Default)] -pub struct Player {} - #[derive(Component, ConvertSaveload, Clone)] pub struct Viewshed { pub visible_tiles: Vec, @@ -61,9 +63,6 @@ impl Default for Viewshed { } } -#[derive(Component, Debug, Serialize, Deserialize, Clone, Default)] -pub struct Monster {} - #[derive(Component, Debug, ConvertSaveload, Clone)] pub struct Name { pub name: String, @@ -77,9 +76,6 @@ impl Name { } } -#[derive(Component, Debug, Serialize, Deserialize, Clone, Default)] -pub struct BlocksTile {} - #[derive(Component, Debug, ConvertSaveload, Clone)] pub struct WantsToMelee { pub target: Entity, @@ -103,12 +99,6 @@ impl SufferDamage { } } -#[derive(Component, Debug, Serialize, Deserialize, Clone, Default)] -pub struct Item {} - -#[derive(Component, Debug, Serialize, Deserialize, Clone, Default)] -pub struct Consumable {} - #[derive(Component, Debug, ConvertSaveload, Clone)] pub struct Ranged { pub range: i32, @@ -161,17 +151,6 @@ pub struct WantsToRemoveItem { pub item: Entity, } -#[derive(PartialEq, Copy, Clone, Serialize, Deserialize)] -pub enum EquipmentSlot { - Melee, - Shield, - Head, - Torso, - Legs, - Feet, - Hands, -} - #[derive(Component, Serialize, Deserialize, Clone)] pub struct Equippable { pub slot: EquipmentSlot, @@ -183,12 +162,6 @@ pub struct Equipped { pub slot: EquipmentSlot, } -#[derive(PartialEq, Copy, Clone, Serialize, Deserialize)] -pub enum WeaponAttribute { - Might, - Quickness, -} - #[derive(Component, ConvertSaveload, Clone)] pub struct MeleeWeapon { pub attribute: WeaponAttribute, @@ -209,52 +182,17 @@ pub struct ParticleLifetime { pub lifetime_ms: f32, } -#[derive(Serialize, Deserialize, Copy, Clone, PartialEq)] -pub enum HungerState { - WellFed, - Normal, - Hungry, - Starving, -} - #[derive(Component, Serialize, Deserialize, Clone)] pub struct HungerClock { pub state: HungerState, pub duration: i32, } -#[derive(Component, Debug, Serialize, Deserialize, Clone)] -pub struct ProvidesFood {} - -#[derive(Component, Debug, Serialize, Deserialize, Clone)] -pub struct MagicMapper {} - -#[derive(Component, Debug, Serialize, Deserialize, Clone)] -pub struct Hidden {} - -#[derive(Component, Debug, Serialize, Deserialize, Clone)] -pub struct EntryTrigger {} - -#[derive(Component, Debug, Serialize, Deserialize, Clone)] -pub struct EntityMoved {} - -#[derive(Component, Debug, Serialize, Deserialize, Clone)] -pub struct SingleActivation {} - -#[derive(Component, Debug, Serialize, Deserialize, Clone)] -pub struct BlocksVisibility {} - #[derive(Component, Debug, Serialize, Deserialize, Clone)] pub struct Door { pub open: bool, } -#[derive(Component, Debug, Serialize, Deserialize, Clone)] -pub struct Bystander {} - -#[derive(Component, Debug, Serialize, Deserialize, Clone)] -pub struct Vendor {} - #[derive(Component, Debug, Serialize, Deserialize, Clone)] pub struct Quips { pub available: Vec, @@ -285,13 +223,6 @@ pub struct Attributes { pub intelligence: Attribute, } -#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, Hash)] -pub enum Skill { - Melee, - Defense, - Magic, -} - #[derive(Component, Debug, Default, Serialize, Deserialize, Clone)] pub struct Skills { pub skills: HashMap, diff --git a/src/components/enums.rs b/src/components/enums.rs new file mode 100644 index 0000000..aaf4d74 --- /dev/null +++ b/src/components/enums.rs @@ -0,0 +1,36 @@ +use ::serde::{Deserialize, Serialize}; + +// ----------------------------------------------------------------------- +// Enums for Components +// ----------------------------------------------------------------------- +#[derive(PartialEq, Copy, Clone, Serialize, Deserialize)] +pub enum EquipmentSlot { + Melee, + Shield, + Head, + Torso, + Legs, + Feet, + Hands, +} + +#[derive(Serialize, Deserialize, Copy, Clone, PartialEq)] +pub enum HungerState { + WellFed, + Normal, + Hungry, + Starving, +} + +#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, Hash)] +pub enum Skill { + Melee, + Defense, + Magic, +} + +#[derive(PartialEq, Copy, Clone, Serialize, Deserialize)] +pub enum WeaponAttribute { + Might, + Quickness, +} diff --git a/src/components/simple.rs b/src/components/simple.rs new file mode 100644 index 0000000..a805160 --- /dev/null +++ b/src/components/simple.rs @@ -0,0 +1,51 @@ +use ::serde::{Deserialize, Serialize}; +use ::specs::prelude::*; +use ::specs_derive::*; + +#[derive(Component, Debug, Serialize, Deserialize, Clone)] +pub struct Player {} + +#[derive(Component, Debug, Serialize, Deserialize, Clone)] +pub struct Monster {} + +#[derive(Component, Debug, Serialize, Deserialize, Clone)] +pub struct Item {} + +#[derive(Component, Debug, Serialize, Deserialize, Clone)] +pub struct Consumable {} + +#[derive(Component, Debug, Serialize, Deserialize, Clone)] +pub struct BlocksTile {} + +#[derive(Component, Debug, Serialize, Deserialize, Clone)] +pub struct ProvidesFood {} + +#[derive(Component, Debug, Serialize, Deserialize, Clone)] +pub struct MagicMapper {} + +#[derive(Component, Debug, Serialize, Deserialize, Clone)] +pub struct Hidden {} + +#[derive(Component, Debug, Serialize, Deserialize, Clone)] +pub struct EntryTrigger {} + +#[derive(Component, Debug, Serialize, Deserialize, Clone)] +pub struct EntityMoved {} + +#[derive(Component, Debug, Serialize, Deserialize, Clone)] +pub struct SingleActivation {} + +#[derive(Component, Debug, Serialize, Deserialize, Clone)] +pub struct BlocksVisibility {} + +#[derive(Component, Debug, Serialize, Deserialize, Clone)] +pub struct Bystander {} + +#[derive(Component, Debug, Serialize, Deserialize, Clone)] +pub struct Vendor {} + +#[derive(Component, Debug, Serialize, Deserialize, Clone)] +pub struct Carnivore {} + +#[derive(Component, Debug, Serialize, Deserialize, Clone)] +pub struct Herbivore {}