1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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});
}
}
_ => {}
}
}
}
}
|