summaryrefslogtreecommitdiff
path: root/src/systems.rs
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-01-29 00:13:03 +0100
committertroido <troido@protonmail.com>2020-01-29 00:13:03 +0100
commit88f275bc427033b7981e0dc2fc5cb4b711fd5fb1 (patch)
treebbac6dc2a928cd121d3c45d0506aad9c32afe169 /src/systems.rs
parentb3356eabcea09f599ad99c1332450e4d9570161b (diff)
refactored control
Diffstat (limited to 'src/systems.rs')
-rw-r--r--src/systems.rs32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/systems.rs b/src/systems.rs
index 322ad23..d00abc8 100644
--- a/src/systems.rs
+++ b/src/systems.rs
@@ -3,6 +3,7 @@ use specs::{
ReadStorage,
WriteStorage,
Write,
+ Entities,
System,
Join
};
@@ -47,17 +48,30 @@ impl <'a> System<'a> for Move {
type SystemData = (WriteStorage<'a, Controller>, WriteStorage<'a, Position>);
fn run(&mut self, (mut controller, mut pos): Self::SystemData) {
for (controller, pos) in (&mut controller, &mut pos).join(){
- if let Some(control) = &controller.0 {
- match control {
- Control::Move(direction) => {
- let (dx, dy) = direction.to_position();
- pos.x += dx;
- pos.y += dy;
- }
- _ => {}
+ match &controller.0 {
+ Control::Move(direction) => {
+ let (dx, dy) = direction.to_position();
+ pos.x += dx;
+ pos.y += dy;
}
- controller.0 = None
+ _ => {}
}
}
}
}
+
+
+pub struct ClearControllers;
+impl <'a> System<'a> for ClearControllers {
+ type SystemData = (Entities<'a>, WriteStorage<'a, Controller>);
+ fn run(&mut self, (entities, mut controllers): Self::SystemData) {
+ let mut ents = Vec::new();
+ for (ent, _controller) in (&*entities, &controllers).join() {
+ ents.push(ent);
+ }
+ for ent in ents {
+ controllers.remove(ent);
+ }
+ }
+}
+