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
|
use specs::{
ReadStorage,
System,
Join,
Write
};
use crate::{
ComponentWrapper,
components::{
Position,
Build,
Trigger,
TriggerBox,
OwnTime
},
resources::{NewEntities},
};
pub struct Building;
impl <'a> System<'a> for Building{
type SystemData = (
ReadStorage<'a, Position>,
Write<'a, NewEntities>,
ReadStorage<'a, TriggerBox>,
ReadStorage<'a, Build>,
ReadStorage<'a, OwnTime>
);
fn run(&mut self, (positions, mut new, triggerboxes, builds, own_times): Self::SystemData) {
for (position, triggerbox, build, own_time) in (&positions, &triggerboxes, &builds, (&own_times).maybe()).join(){
for message in triggerbox.messages.iter() {
match message {
Trigger::Build | Trigger::Change => {
// todo: better error handling
let mut preent = new.encyclopedia.construct(&build.obj).unwrap();
if let Some(time) = own_time {
preent.push(ComponentWrapper::OwnTime(time.clone()));
}
new.to_build.push((position.pos, preent));
}
_ => {}
}
}
}
}
}
|