summaryrefslogtreecommitdiff
path: root/src/systems/controlinput.rs
blob: 71373f5d9b3f59d1c45d162e38ed844e4bd0dbef (plain)
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

use specs::{
	ReadStorage,
	WriteStorage,
	Write,
	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>,
		Write<'a, Input>,
		WriteStorage<'a, Controller>,
		ReadStorage<'a, Player>
	);
	fn run(&mut self, (entities, mut input, mut controllers, players): Self::SystemData) {
		controllers.clear();
	
		for (player, entity) in (&players, &entities).join() {
			if let Some(control) = input.actions.get(&player.id){
				let _ = controllers.insert(entity, Controller(control.clone()));
			}
		}
		input.actions.clear();
	}
}