summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/components.rs3
-rw-r--r--src/componentwrapper.rs2
-rw-r--r--src/main.rs2
-rw-r--r--src/systems/view.rs8
-rw-r--r--src/worldmessages.rs6
5 files changed, 14 insertions, 7 deletions
diff --git a/src/components.rs b/src/components.rs
index 5e1c979..45c8340 100644
--- a/src/components.rs
+++ b/src/components.rs
@@ -78,6 +78,7 @@ impl Component for Inventory {
#[derive(Component, Debug, Clone)]
pub struct Item {
- pub ent: Template
+ pub ent: Template,
+ pub name: String
}
diff --git a/src/componentwrapper.rs b/src/componentwrapper.rs
index bcb750d..feb570e 100644
--- a/src/componentwrapper.rs
+++ b/src/componentwrapper.rs
@@ -92,7 +92,7 @@ components!(
Blocking () {Blocking};
Floor () {Floor};
Player (name: String) {Player::new(name)};
- Item (ent: Template) {Item{ent}};
+ Item (ent: Template, name: String) {Item{ent, name}};
Inventory (capacity: Int) {Inventory{items: Vec::new(), capacity: capacity as usize}}
);
diff --git a/src/main.rs b/src/main.rs
index 26ca3e0..1c253ea 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -228,7 +228,7 @@ fn default_assemblages() -> Encyclopedia {
"sprite": ["string", "pebble"],
"height": ["float", 0.4]
}],
- ["Item", {"ent": ["template", "pebble"]}]
+ ["Item", {"ent": ["template", "pebble"], "name": ["string", "pebble"]}]
]
},
"player": {
diff --git a/src/systems/view.rs b/src/systems/view.rs
index a884d35..e0e5650 100644
--- a/src/systems/view.rs
+++ b/src/systems/view.rs
@@ -12,7 +12,7 @@ use specs::{
};
use super::super::pos::Pos;
-use super::super::components::{Visible, Player, Position, New, Moved, Removed};
+use super::super::components::{Visible, Player, Position, Inventory, New, Moved, Removed};
use super::super::resources::{Size, Output, Ground};
use super::super::worldmessages::{WorldMessage, WorldUpdate, FieldMessage};
@@ -24,6 +24,7 @@ impl <'a> System<'a> for View {
type SystemData = (
Entities<'a>,
ReadStorage<'a, Position>,
+ ReadStorage<'a, Inventory>,
ReadStorage<'a, Visible>,
Read<'a, Size>,
ReadStorage<'a, Player>,
@@ -33,7 +34,7 @@ impl <'a> System<'a> for View {
ReadStorage<'a, Removed>,
Read<'a, Ground>
);
- fn run(&mut self, (entities, positions, visible, size, players, mut output, new, moved, removed, ground): Self::SystemData) {
+ fn run(&mut self, (entities, positions, inventories, visible, size, players, mut output, new, moved, removed, ground): Self::SystemData) {
let mut changed = HashSet::new();
for (pos, _new) in (&positions, &new).join() {
@@ -72,6 +73,9 @@ impl <'a> System<'a> for View {
} else if has_changed {
updates.push(changed_msg.clone());
}
+ if let Some(inventory) = inventories.get(ent){
+ updates.push(WorldUpdate::Inventory(inventory.items.iter().map(|item| item.name.clone()).collect()));
+ }
updates.push(WorldUpdate::Pos(pos.pos));
let message = WorldMessage{updates};
output.output.insert(player.name.clone(), message);
diff --git a/src/worldmessages.rs b/src/worldmessages.rs
index cbbc2ec..48719f6 100644
--- a/src/worldmessages.rs
+++ b/src/worldmessages.rs
@@ -20,7 +20,8 @@ impl ToJson for WorldMessage {
pub enum WorldUpdate {
Field(FieldMessage),
Pos(Pos),
- Change(Vec<(Pos, Vec<String>)>)
+ Change(Vec<(Pos, Vec<String>)>),
+ Inventory(Vec<String>)
}
impl ToJson for WorldUpdate {
@@ -28,7 +29,8 @@ impl ToJson for WorldUpdate {
match self {
WorldUpdate::Field(msg) => json!(["field", msg]),
WorldUpdate::Pos(pos) => json!(["playerpos", pos]),
- WorldUpdate::Change(changes) => json!(["changecells", changes])
+ WorldUpdate::Change(changes) => json!(["changecells", changes]),
+ WorldUpdate::Inventory(items) => json!(["inventory", items])
}
}
}