diff options
Diffstat (limited to 'src/systems.rs')
| -rw-r--r-- | src/systems.rs | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/src/systems.rs b/src/systems.rs index 4988434..ac19b45 100644 --- a/src/systems.rs +++ b/src/systems.rs @@ -1,4 +1,6 @@ +use std::collections::{HashMap, HashSet}; + use specs::{ ReadStorage, WriteStorage, @@ -13,17 +15,25 @@ use super::components::{ Position, Visible, Controller, - Blocking + Blocking, + Played }; -use super::controls::Control; +use super::controls::{ + Control, + Action +}; use super::resources::{ TopView, Size, - Floor + Floor, + Input, + NewEntities }; +use super::assemblages::Player; + pub struct MakeFloor; impl <'a> System<'a> for MakeFloor { @@ -76,6 +86,31 @@ impl <'a> System<'a> for Move { } +pub struct ControlInput; +impl <'a> System<'a> for ControlInput { + type SystemData = (Entities<'a>, Read<'a, Input>, WriteStorage<'a, Controller>, ReadStorage<'a, Played>, Write<'a, NewEntities>); + fn run(&mut self, (entities, input, mut controllers, players, mut new): Self::SystemData) { + let mut playercontrols: HashMap<&str, Control> = HashMap::new(); + let mut leaving = HashSet::new(); + for action in &input.actions { + match action { + Action::Join(name) => {new.assemblages.push((Position{x:10, y:10}, Box::new(Player::new(&name))));} + Action::Leave(name) => {leaving.insert(name);} + Action::Input(name, control) => {playercontrols.insert(name, control.clone());} + } + } + for (player, entity) in (&players, &entities).join() { + if let Some(control) = playercontrols.get(player.name.as_str()){ + let _ = controllers.insert(entity, Controller(control.clone())); + } + if leaving.contains(&player.name) { + let _ = entities.delete(entity); + } + } + } +} + + pub struct ClearControllers; impl <'a> System<'a> for ClearControllers { type SystemData = (Entities<'a>, WriteStorage<'a, Controller>); |
