summaryrefslogtreecommitdiff
path: root/src/client/construction.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/construction.rs')
-rw-r--r--src/client/construction.rs57
1 files changed, 31 insertions, 26 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();