summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2019-02-03 05:45:35 -0600
committertom barrett <spalf0@gmail.com>2019-02-03 05:45:35 -0600
commit46fa862e04bc43311ba79ef3db70abf9014b9104 (patch)
tree3507873ec788af1f1e0885bbb676dbb4a373d48e /src/client
parent828f0d83dcb258a8e5efd55a7775592c6e5f77bc (diff)
bringing to 2018
Diffstat (limited to 'src/client')
-rw-r--r--src/client/construction.rs57
-rw-r--r--src/client/dashboard.rs28
-rw-r--r--src/client/engines.rs38
-rw-r--r--src/client/mining.rs52
-rw-r--r--src/client/mod.rs8
-rw-r--r--src/client/navigation.rs71
-rw-r--r--src/client/refinery.rs39
7 files changed, 169 insertions, 124 deletions
diff --git a/src/client/construction.rs b/src/client/construction.rs
index 7a316c6..b034b77 100644
--- a/src/client/construction.rs
+++ b/src/client/construction.rs
@@ -1,16 +1,16 @@
-extern crate termion;
extern crate serde_json;
+extern crate termion;
-use std::net::TcpStream;
use self::termion::async_stdin;
-use std::io::{BufReader, BufRead};
-use std::io::{stdout, Read, Write};
use self::termion::raw::IntoRawMode;
+use std::io::{stdout, Read, Write};
+use std::io::{BufRead, BufReader};
+use std::net::TcpStream;
-use server::construction::ConstructionData;
-use modules::construction::ConstructionStatus;
+use crate::modules::construction::ConstructionStatus;
+use crate::server::construction::ConstructionData;
-pub fn client_construction(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>) {
+pub fn client_construction(mut stream: TcpStream, mut buff_r: BufReader<TcpStream>) {
let stdout = stdout();
let mut stdout = stdout.lock().into_raw_mode().unwrap();
let mut stdin = async_stdin().bytes();
@@ -18,32 +18,37 @@ pub fn client_construction(mut stream : TcpStream, mut buff_r : BufReader<TcpStr
loop {
let mut recv = String::new();
buff_r.read_line(&mut recv).unwrap();
- let data : ConstructionData = serde_json::from_str(&recv.replace("\n", "")).unwrap();
+ let data: ConstructionData = serde_json::from_str(&recv.replace("\n", "")).unwrap();
write!(stdout, "{}", termion::clear::All).unwrap();
- let clear = termion::cursor::Goto(1,1);
+ let clear = termion::cursor::Goto(1, 1);
- match data.has_refined {
- true => match data.status {
- ConstructionStatus::None => write!(stdout, "{}Press c to create a refinery.", clear).unwrap(),
- _ => write!(stdout, "{}Press c to cancel..", clear).unwrap(),
- },
- false => write!(stdout, "{}You need 5 refined minerals to create a refinery.", clear).unwrap(),
+ if data.has_refined {
+ match data.status {
+ ConstructionStatus::None => {
+ write!(stdout, "{}Press c to create a refinery.", clear).unwrap()
+ }
+ _ => write!(stdout, "{}Press c to cancel..", clear).unwrap(),
+ }
+ } else {
+ write!(
+ stdout,
+ "{}You need 5 refined minerals to create a refinery.",
+ clear
+ )
+ .unwrap();
}
- match stdin.next() {
- Some(c) => {
- let c = c.unwrap();
- let mut send = String::new();
- send.push(c as char);
- if send.as_bytes() == b"q" {
- break;
- }
- send.push_str("\n");
- stream.write(send.as_bytes()).unwrap();
+ if let Some(c) = stdin.next() {
+ let c = c.unwrap();
+ let mut send = String::new();
+ send.push(c as char);
+ if send.as_bytes() == b"q" {
+ break;
}
- None => ()
+ send.push_str("\n");
+ stream.write_all(send.as_bytes()).unwrap();
}
stdout.flush().unwrap();
diff --git a/src/client/dashboard.rs b/src/client/dashboard.rs
index 5815ee2..ec1fd4b 100644
--- a/src/client/dashboard.rs
+++ b/src/client/dashboard.rs
@@ -1,14 +1,14 @@
-extern crate termion;
extern crate serde_json;
+extern crate termion;
-use std::net::TcpStream;
-use std::io::{BufRead, BufReader, stdout, Write, Read};
-use self::termion::raw::IntoRawMode;
use self::termion::async_stdin;
+use self::termion::raw::IntoRawMode;
+use std::io::{stdout, BufRead, BufReader, Read, Write};
+use std::net::TcpStream;
-use mass::Mass;
+use crate::mass::Mass;
-pub fn client_dashboard(mut buff_r : BufReader<TcpStream>) {
+pub fn client_dashboard(mut buff_r: BufReader<TcpStream>) {
let stdout = stdout();
let mut stdout = stdout.lock().into_raw_mode().unwrap();
let mut stdin = async_stdin().bytes();
@@ -16,15 +16,19 @@ pub fn client_dashboard(mut buff_r : BufReader<TcpStream>) {
loop {
let mut recv = String::new();
buff_r.read_line(&mut recv).unwrap();
- let ship : Mass = serde_json::from_str(&recv).unwrap();
+ let ship: Mass = serde_json::from_str(&recv).unwrap();
- write!(stdout, "{}{}{:?}",
- termion::clear::All,
- termion::cursor::Goto(1,1),
- ship).unwrap();
+ write!(
+ stdout,
+ "{}{}{:?}",
+ termion::clear::All,
+ termion::cursor::Goto(1, 1),
+ ship
+ )
+ .unwrap();
if let Some(c) = stdin.next() {
- let c = c.unwrap() as char;
+ let c = c.unwrap() as char;
if c == 'q' {
break;
}
diff --git a/src/client/engines.rs b/src/client/engines.rs
index 9b2d314..8f83998 100644
--- a/src/client/engines.rs
+++ b/src/client/engines.rs
@@ -1,15 +1,15 @@
-extern crate termion;
extern crate serde_json;
+extern crate termion;
-use std::thread::sleep;
-use std::time::Duration;
-use std::net::TcpStream;
use self::termion::async_stdin;
-use std::io::{BufRead, BufReader};
-use std::io::{Read, Write, stdout};
use self::termion::raw::IntoRawMode;
+use std::io::{stdout, Read, Write};
+use std::io::{BufRead, BufReader};
+use std::net::TcpStream;
+use std::thread::sleep;
+use std::time::Duration;
-pub fn client_engines(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>) {
+pub fn client_engines(mut stream: TcpStream, mut buff_r: BufReader<TcpStream>) {
let stdout = stdout();
let mut stdout = stdout.lock().into_raw_mode().unwrap();
let mut stdin = async_stdin().bytes();
@@ -19,15 +19,31 @@ pub fn client_engines(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>)
buff_r.read_line(&mut recv).unwrap();
let has_target = serde_json::from_str(&recv.replace("\n", "")).unwrap();
- write!(stdout, "{}{}use numpad to freely move\n", termion::clear::All, termion::cursor::Goto(1, 1)).unwrap();
+ writeln!(
+ stdout,
+ "{}{}use numpad to freely move",
+ termion::clear::All,
+ termion::cursor::Goto(1, 1)
+ )
+ .unwrap();
write!(stdout, "{}+ : speedup", termion::cursor::Goto(1, 2)).unwrap();
write!(stdout, "{}- : slowdown", termion::cursor::Goto(1, 3)).unwrap();
write!(stdout, "{}s : stop", termion::cursor::Goto(1, 4)).unwrap();
write!(stdout, "{}q : quit", termion::cursor::Goto(1, 5)).unwrap();
if has_target {
- write!(stdout, "{}c : mimic targets velocity vector", termion::cursor::Goto(1, 6)).unwrap();
- write!(stdout, "{}t : accelerate torwards target", termion::cursor::Goto(1, 7)).unwrap();
+ write!(
+ stdout,
+ "{}c : mimic targets velocity vector",
+ termion::cursor::Goto(1, 6)
+ )
+ .unwrap();
+ write!(
+ stdout,
+ "{}t : accelerate torwards target",
+ termion::cursor::Goto(1, 7)
+ )
+ .unwrap();
}
if let Some(c) = stdin.next() {
@@ -38,7 +54,7 @@ pub fn client_engines(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>)
break;
}
send.push_str("\n");
- stream.write(send.as_bytes()).unwrap();
+ stream.write_all(send.as_bytes()).unwrap();
}
stdout.flush().unwrap();
diff --git a/src/client/mining.rs b/src/client/mining.rs
index 221f7ce..5515f3a 100644
--- a/src/client/mining.rs
+++ b/src/client/mining.rs
@@ -1,16 +1,16 @@
-extern crate termion;
extern crate serde_json;
+extern crate termion;
-use std::net::TcpStream;
use self::termion::async_stdin;
-use std::io::{BufReader, BufRead};
-use std::io::{stdout, Read, Write};
use self::termion::raw::IntoRawMode;
+use std::io::{stdout, Read, Write};
+use std::io::{BufRead, BufReader};
+use std::net::TcpStream;
-use server::mining::MiningData;
-use modules::mining::MiningStatus;
+use crate::modules::mining::MiningStatus;
+use crate::server::mining::MiningData;
-pub fn client_mining(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>) {
+pub fn client_mining(mut stream: TcpStream, mut buff_r: BufReader<TcpStream>) {
let stdout = stdout();
let mut stdout = stdout.lock().into_raw_mode().unwrap();
let mut stdin = async_stdin().bytes();
@@ -18,24 +18,34 @@ 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 : MiningData = 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();
- let clear = termion::cursor::Goto(1,1);
+ let clear = termion::cursor::Goto(1, 1);
- match data.has_astroid_target {
- true => match data.is_within_range {
- true => match data.astroid_has_minerals {
- true => match data.status {
- MiningStatus::None => write!(stdout, "{}Press F to begin mining.", clear).unwrap(),
- _ => write!(stdout, "{}Press F to stop mining.", clear).unwrap(),
- },
- false => write!(stdout, "{}Astroid has ran out of minerals.", clear).unwrap(),
+ if data.has_astroid_target {
+ if data.is_within_range {
+ if data.astroid_has_minerals {
+ match data.status {
+ MiningStatus::None => {
+ write!(stdout, "{}Press F to begin mining.", clear).unwrap()
+ }
+ _ => write!(stdout, "{}Press F to stop mining.", clear).unwrap(),
+ };
+ } else {
+ write!(stdout, "{}Astroid has ran out of minerals.", clear).unwrap();
}
- false => write!(stdout, "{}Astroid must be within range of {}.", clear, data.range).unwrap(),
- },
- false => write!(stdout, "{}Ship has no astroid targeted.", clear).unwrap(),
+ } else {
+ write!(
+ stdout,
+ "{}Astroid must be within range of {}.",
+ clear, data.range
+ )
+ .unwrap();
+ }
+ } else {
+ write!(stdout, "{}Ship has no astroid targeted.", clear).unwrap();
}
if let Some(c) = stdin.next() {
@@ -46,7 +56,7 @@ pub fn client_mining(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>)
break;
}
send.push_str("\n");
- stream.write(send.as_bytes()).unwrap();
+ stream.write_all(send.as_bytes()).unwrap();
}
stdout.flush().unwrap();
diff --git a/src/client/mod.rs b/src/client/mod.rs
index 421a394..530e2de 100644
--- a/src/client/mod.rs
+++ b/src/client/mod.rs
@@ -1,6 +1,6 @@
-pub mod mining;
-pub mod engines;
-pub mod refinery;
+pub mod construction;
pub mod dashboard;
+pub mod engines;
+pub mod mining;
pub mod navigation;
-pub mod construction;
+pub mod refinery;
diff --git a/src/client/navigation.rs b/src/client/navigation.rs
index 34e1b7a..0ab25c6 100644
--- a/src/client/navigation.rs
+++ b/src/client/navigation.rs
@@ -1,18 +1,18 @@
-extern crate termion;
extern crate serde_json;
+extern crate termion;
-use std::net::TcpStream;
-use std::collections::BTreeMap;
use self::termion::async_stdin;
-use std::io::{BufRead, BufReader};
-use std::io::{stdout, Read, Write};
use self::termion::raw::IntoRawMode;
+use std::collections::BTreeMap;
+use std::io::{stdout, Read, Write};
+use std::io::{BufRead, BufReader};
+use std::net::TcpStream;
-use math::distance;
-use mass::{Mass, MassType};
-use modules::navigation::Navigation;
+use crate::mass::{Mass, MassType};
+use crate::math::distance;
+use crate::modules::navigation::Navigation;
-pub fn client_navigation(name : String, mut stream : TcpStream, mut buff_r : BufReader<TcpStream>){
+pub fn client_navigation(name: String, mut stream: TcpStream, mut buff_r: BufReader<TcpStream>) {
let stdout = stdout();
let mut stdout = stdout.lock().into_raw_mode().unwrap();
let mut stdin = async_stdin().bytes();
@@ -20,42 +20,48 @@ pub fn client_navigation(name : String, mut stream : TcpStream, mut buff_r : Buf
loop {
let mut recv = String::new();
buff_r.read_line(&mut recv).unwrap();
- let mut within_range : BTreeMap<String, Mass> = serde_json::from_str(&recv).unwrap();
+ let mut within_range: BTreeMap<String, Mass> = serde_json::from_str(&recv).unwrap();
- write!(stdout, "{}{}Targets:",
- termion::clear::All,
- termion::cursor::Goto(1,1)).unwrap();
+ write!(
+ stdout,
+ "{}{}Targets:",
+ termion::clear::All,
+ termion::cursor::Goto(1, 1)
+ )
+ .unwrap();
let ship = within_range.remove(&name).unwrap();
- if let MassType::Ship{ref navigation, ..} = ship.mass_type {
+ if let MassType::Ship { ref navigation, .. } = ship.mass_type {
let navigation = navigation.clone().unwrap();
for (i, (mass_name, mass)) in within_range.iter().enumerate() {
let target_data = get_target_status(&navigation, &mass_name);
- 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();
}
if let Some(c) = stdin.next() {
let c = c.unwrap() as char;
if c == 'q' {
break;
- }
- else {
+ } 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();
+ stream.write_all(send.as_bytes()).unwrap();
}
}
}
@@ -64,14 +70,15 @@ pub fn client_navigation(name : String, mut stream : TcpStream, mut buff_r : Buf
}
}
-fn get_target_status(navigation : &Navigation, mass_name : &String) -> String {
+fn get_target_status(navigation: &Navigation, mass_name: &str) -> String {
match navigation.target_name.clone() {
Some(name) => {
- match &name == mass_name {
- true => serde_json::to_string(&navigation.status).unwrap(),
- false => String::new()
+ if name == mass_name {
+ serde_json::to_string(&navigation.status).unwrap()
+ } else {
+ String::new()
}
- },
+ }
_ => String::new(),
}
}
diff --git a/src/client/refinery.rs b/src/client/refinery.rs
index 013172d..caceda7 100644
--- a/src/client/refinery.rs
+++ b/src/client/refinery.rs
@@ -1,16 +1,16 @@
-extern crate termion;
extern crate serde_json;
+extern crate termion;
-use std::net::TcpStream;
use self::termion::async_stdin;
-use std::io::{BufRead, BufReader};
-use std::io::{stdout, Read, Write};
use self::termion::raw::IntoRawMode;
+use std::io::{stdout, Read, Write};
+use std::io::{BufRead, BufReader};
+use std::net::TcpStream;
-use server::refinery::RefineryData;
-use modules::refinery::RefineryStatus;
+use crate::modules::refinery::RefineryStatus;
+use crate::server::refinery::RefineryData;
-pub fn client_refinery(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>) {
+pub fn client_refinery(mut stream: TcpStream, mut buff_r: BufReader<TcpStream>) {
let stdout = stdout();
let mut stdout = stdout.lock().into_raw_mode().unwrap();
let mut stdin = async_stdin().bytes();
@@ -18,21 +18,24 @@ pub fn client_refinery(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>
loop {
let mut recv = String::new();
buff_r.read_line(&mut recv).unwrap();
- let data : RefineryData = serde_json::from_str(&recv.replace("\n", "")).unwrap();
+ let data: RefineryData = serde_json::from_str(&recv.replace("\n", "")).unwrap();
write!(stdout, "{}", termion::clear::All).unwrap();
- let clear = termion::cursor::Goto(1,1);
-
- match data.has_minerals {
- true => match data.status {
- RefineryStatus::None => write!(stdout, "{}Press R to begin refining.", clear).unwrap(),
- _ => write!(stdout, "{}Press R to stop refining.", clear).unwrap(),
- },
- false => write!(stdout, "{}You have no refinable minerals.", clear).unwrap(),
+ let clear = termion::cursor::Goto(1, 1);
+
+ if data.has_minerals {
+ match data.status {
+ RefineryStatus::None => {
+ write!(stdout, "{}Press R to begin refining.", clear).unwrap()
+ }
+ _ => write!(stdout, "{}Press R to stop refining.", clear).unwrap(),
+ };
+ } else {
+ write!(stdout, "{}You have no refinable minerals.", clear).unwrap();
}
- if let Some(c) = stdin.next() {
+ if let Some(c) = stdin.next() {
let c = c.unwrap();
let mut send = String::new();
send.push(c as char);
@@ -40,7 +43,7 @@ pub fn client_refinery(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>
break;
}
send.push_str("\n");
- stream.write(send.as_bytes()).unwrap();
+ stream.write_all(send.as_bytes()).unwrap();
}
stdout.flush().unwrap();