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
|
use specs::{
ReadStorage,
WriteStorage,
Read,
Entities,
System,
Join
};
use crate::components::{Controller, Player};
use crate::resources::{Input};
pub struct ControlInput;
impl <'a> System<'a> for ControlInput {
type SystemData = (
Entities<'a>,
Read<'a, Input>,
WriteStorage<'a, Controller>,
ReadStorage<'a, Player>
);
fn run(&mut self, (entities, input, mut controllers, players): Self::SystemData) {
{
let mut ents = Vec::new();
for (ent, _controller) in (&*entities, &controllers).join() {
ents.push(ent);
}
for ent in ents {
controllers.remove(ent);
}
}
for (player, entity) in (&players, &entities).join() {
if let Some(control) = input.actions.get(&player.id){
let _ = controllers.insert(entity, Controller(control.clone()));
}
}
}
}
|