summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2018-06-27 07:51:47 -0500
committertom barrett <spalf0@gmail.com>2018-06-27 07:51:47 -0500
commitae79327d4f0ee6de0ef6b8e3c51299aebfe3bc25 (patch)
treedb6d4b049d94e41989178566a3dca52ab24b5b1e /src/client
parent25d556ad995a83c0c783f0bf9ca555b17cb0bfb0 (diff)
-added elementry construction module, doesnt do anything other than exist as a mass
Diffstat (limited to 'src/client')
-rw-r--r--src/client/construction.rs51
-rw-r--r--src/client/mod.rs1
2 files changed, 52 insertions, 0 deletions
diff --git a/src/client/construction.rs b/src/client/construction.rs
new file mode 100644
index 0000000..7a316c6
--- /dev/null
+++ b/src/client/construction.rs
@@ -0,0 +1,51 @@
+extern crate termion;
+extern crate serde_json;
+
+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 server::construction::ConstructionData;
+use modules::construction::ConstructionStatus;
+
+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();
+
+ loop {
+ let mut recv = String::new();
+ buff_r.read_line(&mut recv).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);
+
+ 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(),
+ }
+
+ 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();
+ }
+ None => ()
+ }
+
+ stdout.flush().unwrap();
+ }
+}
diff --git a/src/client/mod.rs b/src/client/mod.rs
index 8bb0eca..421a394 100644
--- a/src/client/mod.rs
+++ b/src/client/mod.rs
@@ -3,3 +3,4 @@ pub mod engines;
pub mod refinery;
pub mod dashboard;
pub mod navigation;
+pub mod construction;