summaryrefslogtreecommitdiff
path: root/src/playerstate.rs
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-02-22 22:00:32 +0100
committertroido <troido@protonmail.com>2020-02-22 22:00:32 +0100
commitf4331041e5d906f95063f317852f32f19e6cdf9c (patch)
treee855402de7b2dcec81c91d97ab6a7e359689ecc5 /src/playerstate.rs
parent2b0cc677f4092d94b31e95f3e9961ec6ed91327b (diff)
items now have an action enum
Diffstat (limited to 'src/playerstate.rs')
-rw-r--r--src/playerstate.rs17
1 files changed, 12 insertions, 5 deletions
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![
ComponentWrapper::Visible(Visible{sprite: Sprite{name: "player".to_string()}, height: 1.0, name: self.id.name.clone()}),
ComponentWrapper::Player(Player::new(self.id.clone())),
ComponentWrapper::Inventory(Inventory{
- items: self.inventory.iter().map(
- |template| Item{ent: template.clone(), name: template.name.clone()}
- ).collect(),
+ items: self.inventory.iter().map( |template| {
+ let item_ent = encyclopedia.construct(template).unwrap();
+ for component in item_ent {
+ if let ComponentWrapper::Item(item) = component {
+ return item;
+ }
+ }
+ panic!("Item in inventory does not have item component")
+ }).collect(),
capacity: self.inventory_capacity
}),
ComponentWrapper::Health(Health{health: self.health, maxhealth: self.maximum_health})