diff options
| author | troido <troido@protonmail.com> | 2020-02-16 23:25:04 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-02-16 23:25:04 +0100 |
| commit | c9a11aec577a0927afb4e97f3041b492621ce666 (patch) | |
| tree | d27ab608da72a7b17741a76da37886bd85878b8c /src/systems | |
| parent | 10bf24f99efb87b586590b8785ac8fe337db96e5 (diff) | |
added playerid to avoid stringly typing
Diffstat (limited to 'src/systems')
| -rw-r--r-- | src/systems/controlinput.rs | 16 | ||||
| -rw-r--r-- | src/systems/view.rs | 4 |
2 files changed, 10 insertions, 10 deletions
diff --git a/src/systems/controlinput.rs b/src/systems/controlinput.rs index 608de06..e9b1103 100644 --- a/src/systems/controlinput.rs +++ b/src/systems/controlinput.rs @@ -11,10 +11,10 @@ use specs::{ Join }; +use crate::{PlayerId, hashmap}; use crate::components::{Controller, Player, Removed}; use crate::controls::{Control, Action}; use crate::resources::{Input, NewEntities, Spawn}; -use crate::hashmap; use crate::template::Template; use crate::parameter::Parameter; @@ -41,25 +41,25 @@ impl <'a> System<'a> for ControlInput { } } - let mut playercontrols: HashMap<&str, Control> = HashMap::new(); + let mut playercontrols: HashMap<&PlayerId, Control> = HashMap::new(); let mut leaving = HashSet::new(); for action in &input.actions { match action { - Action::Join(name) => { + Action::Join(player) => { new.templates.push(( spawn.pos, - Template::new("player", hashmap!("name".to_string() => Parameter::String(name.to_string()))) + Template::new("player", hashmap!("name".to_string() => Parameter::String(player.name.clone()))).unsaved() )); } - Action::Leave(name) => {leaving.insert(name);} - Action::Input(name, control) => {playercontrols.insert(name, control.clone());} + Action::Leave(player) => {leaving.insert(player);} + Action::Input(player, control) => {playercontrols.insert(player, control.clone());} } } for (player, entity) in (&players, &entities).join() { - if let Some(control) = playercontrols.get(player.name.as_str()){ + if let Some(control) = playercontrols.get(&player.id){ let _ = controllers.insert(entity, Controller(control.clone())); } - if leaving.contains(&player.name) { + if leaving.contains(&player.id) { let _ = removed.insert(entity, Removed); } } diff --git a/src/systems/view.rs b/src/systems/view.rs index 2bc971e..c452b2f 100644 --- a/src/systems/view.rs +++ b/src/systems/view.rs @@ -11,7 +11,7 @@ use specs::{ Entity }; -use crate::pos::Pos; +use crate::Pos; use crate::components::{Visible, Player, Position, Inventory, New, Moved, Removed, Health}; use crate::resources::{Size, Output, Ground}; use crate::worldmessages::{WorldMessage, WorldUpdate, FieldMessage}; @@ -82,7 +82,7 @@ impl <'a> System<'a> for View { } updates.push(WorldUpdate::Pos(pos.pos)); let message = WorldMessage{updates}; - output.output.insert(player.name.clone(), message); + output.output.insert(player.id.clone(), message); } } } |
