diff options
| author | troido <troido@protonmail.com> | 2020-02-22 22:00:32 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-02-22 22:00:32 +0100 |
| commit | f4331041e5d906f95063f317852f32f19e6cdf9c (patch) | |
| tree | e855402de7b2dcec81c91d97ab6a7e359689ecc5 | |
| parent | 2b0cc677f4092d94b31e95f3e9961ec6ed91327b (diff) | |
items now have an action enum
| -rw-r--r-- | src/components/item.rs | 18 | ||||
| -rw-r--r-- | src/components/mod.rs (renamed from src/components.rs) | 12 | ||||
| -rw-r--r-- | src/componentwrapper.rs | 4 | ||||
| -rw-r--r-- | src/main.rs | 2 | ||||
| -rw-r--r-- | src/playerstate.rs | 17 | ||||
| -rw-r--r-- | src/resources/mod.rs (renamed from src/resources.rs) | 0 | ||||
| -rw-r--r-- | src/room.rs | 2 |
7 files changed, 39 insertions, 16 deletions
diff --git a/src/components/item.rs b/src/components/item.rs new file mode 100644 index 0000000..76c5c1c --- /dev/null +++ b/src/components/item.rs @@ -0,0 +1,18 @@ + +use specs::{Component, DenseVecStorage}; +use crate::{Template}; + +#[derive(Component, Debug, Clone)] +pub struct Item { + pub ent: Template, + pub name: String, + pub action: ItemAction +} + +#[derive(Debug, Clone)] +pub enum ItemAction { + Eat{health: i64}, + Build(Template), + None +} + diff --git a/src/components.rs b/src/components/mod.rs index 9d387f1..a0ccde4 100644 --- a/src/components.rs +++ b/src/components/mod.rs @@ -1,4 +1,8 @@ +pub mod item; + +pub use item::Item; + use specs::{ DenseVecStorage, VecStorage, @@ -11,7 +15,6 @@ use crate::{Pos, PlayerId, RoomId, Sprite}; use crate::controls::Control; use crate::template::Template; - #[derive(Debug, Clone)] pub struct Position{ pub pos: Pos @@ -76,13 +79,6 @@ impl Component for Inventory { type Storage = FlaggedStorage<Self, HashMapStorage<Self>>; } - -#[derive(Component, Debug, Clone)] -pub struct Item { - pub ent: Template, - pub name: String -} - #[derive(Component, Debug, Clone)] pub struct Health { pub health: i64, diff --git a/src/componentwrapper.rs b/src/componentwrapper.rs index 5b9673f..888903d 100644 --- a/src/componentwrapper.rs +++ b/src/componentwrapper.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use specs::Builder; use crate::{PlayerId, RoomId, Sprite}; -use crate::components::{Visible, Blocking, Player, Floor, Item, Inventory, Health, Serialise, RoomExit}; +use crate::components::{Visible, Blocking, Player, Floor, Item, Inventory, Health, Serialise, RoomExit, item::ItemAction}; use crate::parameter::{Parameter, ParameterType}; @@ -94,7 +94,7 @@ components!( Blocking () {Blocking}; Floor () {Floor}; Player (name: String) {Player::new(PlayerId{name})}; - Item (ent: Template, name: String) {Item{ent, name}}; + Item (ent: Template, name: String) {Item{ent, name, action: ItemAction::None}}; Inventory (capacity: Int) {Inventory{items: Vec::new(), capacity: capacity as usize}}; Health (health: Int, maxhealth: Int) {Health{health, maxhealth}}; Serialise (template: Template) {Serialise{template}}; diff --git a/src/main.rs b/src/main.rs index def2ee7..dbc8728 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,6 +37,8 @@ pub use self::playerid::PlayerId; pub use self::roomid::RoomId; pub use self::util::Result; pub use self::sprite::Sprite; +pub use self::template::Template; +pub use self::encyclopedia::Encyclopedia; use self::gameserver::GameServer; use self::server::unixserver::UnixServer; diff --git a/src/playerstate.rs b/src/playerstate.rs index 150b9eb..36c932c 100644 --- a/src/playerstate.rs +++ b/src/playerstate.rs @@ -9,7 +9,8 @@ use crate::{ components::{Visible, Player, Inventory, Health, Item}, Result, aerr, - Sprite + Sprite, + Encyclopedia }; #[derive(Debug, Clone)] @@ -85,14 +86,20 @@ impl PlayerState { }) } - pub fn construct(&self) -> PreEntity { + pub fn construct(&self, encyclopedia: &Encyclopedia) -> PreEntity { vec