summaryrefslogtreecommitdiff
path: root/src/systems
diff options
context:
space:
mode:
Diffstat (limited to 'src/systems')
-rw-r--r--src/systems/describe.rs50
-rw-r--r--src/systems/mod.rs4
2 files changed, 53 insertions, 1 deletions
diff --git a/src/systems/describe.rs b/src/systems/describe.rs
new file mode 100644
index 0000000..7ebb34f
--- /dev/null
+++ b/src/systems/describe.rs
@@ -0,0 +1,50 @@
+
+use specs::{
+ ReadStorage,
+ WriteStorage,
+ System,
+ Join,
+ Read
+};
+
+use crate::components::{
+ Controller,
+ Position,
+ Description,
+ Visible,
+ Ear,
+ ear::Notification,
+};
+
+use crate::controls::{Control};
+use crate::resources::{Ground};
+
+
+
+pub struct Describe;
+impl <'a> System<'a> for Describe {
+ type SystemData = (
+ ReadStorage<'a, Controller>,
+ ReadStorage<'a, Position>,
+ ReadStorage<'a, Visible>,
+ ReadStorage<'a, Description>,
+ Read<'a, Ground>,
+ WriteStorage<'a, Ear>,
+ );
+
+ fn run(&mut self, (controllers, positions, visibles, descriptions, ground, mut ears): Self::SystemData) {
+ for (controller, position, ear) in (&controllers, &positions, &mut ears).join(){
+ match &controller.control {
+ Control::Describe(direction) => {
+ for entity in ground.by_height(&(position.pos + direction.to_position()), &visibles) {
+ let name = visibles.get(entity).unwrap().name.clone();
+ let description = descriptions.get(entity).map(|d| d.description.clone()).unwrap_or("".to_string());
+ ear.sounds.push(Notification::Describe{name, description});
+ }
+ }
+ _ => {}
+ }
+ }
+ }
+
+}
diff --git a/src/systems/mod.rs b/src/systems/mod.rs
index 598feaa..66258a4 100644
--- a/src/systems/mod.rs
+++ b/src/systems/mod.rs
@@ -24,6 +24,7 @@ mod building;
mod spawntrigger;
mod replace;
mod spawncheck;
+mod describe;
pub use self::{
controlinput::ControlInput,
@@ -50,5 +51,6 @@ pub use self::{
building::Building,
spawntrigger::SpawnTrigger,
replace::Replace,
- spawncheck::SpawnCheck
+ spawncheck::SpawnCheck,
+ describe::Describe
};