Reorganise components a little

This commit is contained in:
Timothy Warren 2022-01-05 11:05:15 -05:00
parent da99923a1e
commit 6e29b31978
3 changed files with 92 additions and 74 deletions

View File

@ -1,3 +1,6 @@
mod enums;
mod simple;
use std::collections::HashMap; use std::collections::HashMap;
use ::rltk::{Point, RGB}; use ::rltk::{Point, RGB};
@ -6,6 +9,8 @@ use ::specs::error::NoError;
use ::specs::prelude::*; use ::specs::prelude::*;
use ::specs::saveload::{ConvertSaveload, Marker}; use ::specs::saveload::{ConvertSaveload, Marker};
use ::specs_derive::*; use ::specs_derive::*;
pub use enums::*;
pub use simple::*;
use crate::gamesystem::attr_bonus; use crate::gamesystem::attr_bonus;
@ -41,9 +46,6 @@ pub struct Renderable {
pub render_order: i32, pub render_order: i32,
} }
#[derive(Component, Debug, Clone, Serialize, Deserialize, Default)]
pub struct Player {}
#[derive(Component, ConvertSaveload, Clone)] #[derive(Component, ConvertSaveload, Clone)]
pub struct Viewshed { pub struct Viewshed {
pub visible_tiles: Vec<Point>, pub visible_tiles: Vec<Point>,
@ -61,9 +63,6 @@ impl Default for Viewshed {
} }
} }
#[derive(Component, Debug, Serialize, Deserialize, Clone, Default)]
pub struct Monster {}
#[derive(Component, Debug, ConvertSaveload, Clone)] #[derive(Component, Debug, ConvertSaveload, Clone)]
pub struct Name { pub struct Name {
pub name: String, pub name: String,
@ -77,9 +76,6 @@ impl Name {
} }
} }
#[derive(Component, Debug, Serialize, Deserialize, Clone, Default)]
pub struct BlocksTile {}
#[derive(Component, Debug, ConvertSaveload, Clone)] #[derive(Component, Debug, ConvertSaveload, Clone)]
pub struct WantsToMelee { pub struct WantsToMelee {
pub target: Entity, 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)] #[derive(Component, Debug, ConvertSaveload, Clone)]
pub struct Ranged { pub struct Ranged {
pub range: i32, pub range: i32,
@ -161,17 +151,6 @@ pub struct WantsToRemoveItem {
pub item: Entity, pub item: Entity,
} }
#[derive(PartialEq, Copy, Clone, Serialize, Deserialize)]
pub enum EquipmentSlot {
Melee,
Shield,
Head,
Torso,
Legs,
Feet,
Hands,
}
#[derive(Component, Serialize, Deserialize, Clone)] #[derive(Component, Serialize, Deserialize, Clone)]
pub struct Equippable { pub struct Equippable {
pub slot: EquipmentSlot, pub slot: EquipmentSlot,
@ -183,12 +162,6 @@ pub struct Equipped {
pub slot: EquipmentSlot, pub slot: EquipmentSlot,
} }
#[derive(PartialEq, Copy, Clone, Serialize, Deserialize)]
pub enum WeaponAttribute {
Might,
Quickness,
}
#[derive(Component, ConvertSaveload, Clone)] #[derive(Component, ConvertSaveload, Clone)]
pub struct MeleeWeapon { pub struct MeleeWeapon {
pub attribute: WeaponAttribute, pub attribute: WeaponAttribute,
@ -209,52 +182,17 @@ pub struct ParticleLifetime {
pub lifetime_ms: f32, pub lifetime_ms: f32,
} }
#[derive(Serialize, Deserialize, Copy, Clone, PartialEq)]
pub enum HungerState {
WellFed,
Normal,
Hungry,
Starving,
}
#[derive(Component, Serialize, Deserialize, Clone)] #[derive(Component, Serialize, Deserialize, Clone)]
pub struct HungerClock { pub struct HungerClock {
pub state: HungerState, pub state: HungerState,
pub duration: i32, 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)] #[derive(Component, Debug, Serialize, Deserialize, Clone)]
pub struct Door { pub struct Door {
pub open: bool, 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)] #[derive(Component, Debug, Serialize, Deserialize, Clone)]
pub struct Quips { pub struct Quips {
pub available: Vec<String>, pub available: Vec<String>,
@ -285,13 +223,6 @@ pub struct Attributes {
pub intelligence: Attribute, pub intelligence: Attribute,
} }
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, Hash)]
pub enum Skill {
Melee,
Defense,
Magic,
}
#[derive(Component, Debug, Default, Serialize, Deserialize, Clone)] #[derive(Component, Debug, Default, Serialize, Deserialize, Clone)]
pub struct Skills { pub struct Skills {
pub skills: HashMap<Skill, i32>, pub skills: HashMap<Skill, i32>,

36
src/components/enums.rs Normal file
View File

@ -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,
}

51
src/components/simple.rs Normal file
View File

@ -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 {}