diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/mining.rs | 10 | ||||
-rw-r--r-- | src/client/navigation.rs | 88 |
2 files changed, 43 insertions, 55 deletions
diff --git a/src/client/mining.rs b/src/client/mining.rs index 44e7c30..5cb1240 100644 --- a/src/client/mining.rs +++ b/src/client/mining.rs @@ -7,13 +7,7 @@ use std::io::{BufReader, BufRead}; use std::io::{stdout, Read, Write}; use self::termion::raw::IntoRawMode; -#[derive(Serialize, Deserialize, Debug, Clone)] -struct ServerData { - has_astroid_target : bool, - is_within_range : bool, - mining_range : f64, - mining_status : bool, -} +use server::mining::MiningData; pub fn client_mining(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>) { let stdout = stdout(); @@ -23,7 +17,7 @@ pub fn client_mining(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>) loop { let mut recv = String::new(); buff_r.read_line(&mut recv).unwrap(); - let data : ServerData = serde_json::from_str(&recv.replace("\n", "")).unwrap(); + let data : MiningData = serde_json::from_str(&recv.replace("\n", "")).unwrap(); write!(stdout, "{}", termion::clear::All).unwrap(); diff --git a/src/client/navigation.rs b/src/client/navigation.rs index 59b6987..eb9a2c4 100644 --- a/src/client/navigation.rs +++ b/src/client/navigation.rs @@ -28,58 +28,52 @@ pub fn client_navigation(name : String, mut stream : TcpStream, mut buff_r : Buf let ship = within_range.remove(&name).unwrap(); - 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(), - }; - - 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(); + if let MassType::Ship{ref modules, ..} = ship.mass_type { + if let ModuleType::Navigation{ref status, ref target_name, ..} = modules.get("Navigation").unwrap().module_type { + 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(), + }; - 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(); - } - } + 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; + } + 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 => () } - }, - _ => (), + } + None => () } - }, - _ => (), + } } stdout.flush().unwrap(); |