diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/navigation.rs | 96 |
1 files changed, 51 insertions, 45 deletions
diff --git a/src/client/navigation.rs b/src/client/navigation.rs index 171d050..59b6987 100644 --- a/src/client/navigation.rs +++ b/src/client/navigation.rs @@ -1,5 +1,4 @@ extern crate termion; -//extern crate itertools; extern crate serde_json; use std::net::TcpStream; @@ -11,6 +10,7 @@ use self::termion::raw::IntoRawMode; use math::distance; use mass::{Mass, MassType}; +use module::ModuleType; pub fn client_navigation(name : String, mut stream : TcpStream, mut buff_r : BufReader<TcpStream>){ let stdout = stdout(); @@ -27,55 +27,61 @@ pub fn client_navigation(name : String, mut stream : TcpStream, mut buff_r : Buf termion::cursor::Goto(1,1)).unwrap(); let ship = within_range.remove(&name).unwrap(); - let targeting = match ship.mass_type { - MassType::Ship{ref targeting, ..} => Some(targeting.clone()), - _ => None, - }.unwrap(); - for (i, (mass_name, mass)) in within_range.iter().enumerate() { + match ship.mass_type { + MassType::Ship{ref modules, ..} => { + match modules.get("Navigation").unwrap().module_type { + ModuleType::Navigation{ref status, ref target_name, ..} => { + for (i, (mass_name, mass)) in within_range.iter().enumerate() { + let target_data = match target_name.clone() { + Some(target_name) => { + if &target_name == mass_name { + serde_json::to_string(status).unwrap() + } + else { + String::new() + } + } + None => String::new(), + }; - let target_data = match targeting.target.clone() { - Some(target_name) => { - if &target_name == mass_name { - serde_json::to_string(&targeting.status).unwrap() - } - else { - String::new() - } - } - None => String::new(), - }; - - write!(stdout, "{}{}) {} ({:.2}, {:.2}, {:.2}) Distance : {:.2} {}", - termion::cursor::Goto(1, 2 + i as u16), - i, - mass_name, - mass.position.0, - mass.position.1, - mass.position.2, - distance(mass.position, ship.position), - target_data - ).unwrap(); - } + write!(stdout, "{}{}) {} ({:.2}, {:.2}, {:.2}) Distance : {:.2} {}", + termion::cursor::Goto(1, 2 + i as u16), + i, + mass_name, + mass.position.0, + mass.position.1, + mass.position.2, + distance(mass.position, ship.position), + target_data + ).unwrap(); + } - match stdin.next() { - Some(c) => { - let c = c.unwrap() as char; - if c == 'q' { - break; + match stdin.next() { + Some(c) => { + let c = c.unwrap() as char; + if c == 'q' { + break; + } + else { + let i = c.to_digit(10).unwrap() as usize; + if i < within_range.len() { + let mut send = String::new(); + send.push_str(within_range.iter().nth(i).unwrap().0); + send.push_str("\n"); + stream.write(send.as_bytes()).unwrap(); + } + } + } + None => () + } + }, + _ => (), } - else { - let i = c.to_digit(10).unwrap() as usize; - if i < within_range.len() { - let mut send = String::new(); - send.push_str(within_range.iter().nth(i).unwrap().0); - send.push_str("\n"); - stream.write(send.as_bytes()).unwrap(); - } - } - } - None => () + }, + _ => (), } + stdout.flush().unwrap(); } } |