summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2019-02-10 03:55:05 -0600
committertom barrett <spalf0@gmail.com>2019-02-10 03:55:05 -0600
commitf617213b4a48d73acd245580f8551a7c37ce9ad8 (patch)
tree46ab5a696d91d6405ff2d2875a57c403b94edfbd /src/client
parent46fa862e04bc43311ba79ef3db70abf9014b9104 (diff)
added vector math and tractorbeam module
Diffstat (limited to 'src/client')
-rw-r--r--src/client/mod.rs1
-rw-r--r--src/client/navigation.rs11
-rw-r--r--src/client/tractorbeam.rs70
3 files changed, 75 insertions, 7 deletions
diff --git a/src/client/mod.rs b/src/client/mod.rs
index 530e2de..9045e90 100644
--- a/src/client/mod.rs
+++ b/src/client/mod.rs
@@ -4,3 +4,4 @@ pub mod engines;
pub mod mining;
pub mod navigation;
pub mod refinery;
+pub mod tractorbeam;
diff --git a/src/client/navigation.rs b/src/client/navigation.rs
index 0ab25c6..1f2ed06 100644
--- a/src/client/navigation.rs
+++ b/src/client/navigation.rs
@@ -9,7 +9,6 @@ use std::io::{BufRead, BufReader};
use std::net::TcpStream;
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>) {
@@ -38,14 +37,12 @@ pub fn client_navigation(name: String, mut stream: TcpStream, mut buff_r: BufRea
let target_data = get_target_status(&navigation, &mass_name);
write!(
stdout,
- "{}{}) {} ({:.2}, {:.2}, {:.2}) Distance : {:.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),
+ mass.position,
+ mass.position.distance_from(ship.position.clone()),
target_data
)
.unwrap();
@@ -79,6 +76,6 @@ fn get_target_status(navigation: &Navigation, mass_name: &str) -> String {
String::new()
}
}
- _ => String::new(),
+ None => String::new(),
}
}
diff --git a/src/client/tractorbeam.rs b/src/client/tractorbeam.rs
new file mode 100644
index 0000000..e9e60b2
--- /dev/null
+++ b/src/client/tractorbeam.rs
@@ -0,0 +1,70 @@
+extern crate serde_json;
+extern crate termion;
+
+use self::termion::async_stdin;
+use self::termion::raw::IntoRawMode;
+use std::io::{stdout, Read, Write};
+use std::io::{BufRead, BufReader};
+use std::net::TcpStream;
+
+use crate::modules::tractorbeam::TractorbeamStatus;
+use crate::server::tractorbeam::TractorbeamData;
+
+pub fn client_tractorbeam(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: TractorbeamData = serde_json::from_str(&recv.replace("\n", "")).unwrap();
+
+ write!(stdout, "{}", termion::clear::All).unwrap();
+
+ let clear = termion::cursor::Goto(1, 1);
+
+ if data.has_target {
+ match data.status {
+ TractorbeamStatus::None => write!(
+ stdout,
+ "{}Press o to pull, p to push, t to bring to 5m.",
+ clear
+ )
+ .unwrap(),
+ TractorbeamStatus::Push => write!(
+ stdout,
+ "{}Press o to pull, p to stop pushing, t to bring to 5m.",
+ clear
+ )
+ .unwrap(),
+ TractorbeamStatus::Pull => write!(
+ stdout,
+ "{}Press o to stop pulling, p to push, t to bring to 5m.",
+ clear
+ )
+ .unwrap(),
+ TractorbeamStatus::Bring => write!(
+ stdout,
+ "{}Press o to pulling, p to push, t to stop bringing to 5m.",
+ clear
+ )
+ .unwrap(),
+ };
+ } else {
+ write!(stdout, "{}You have no target.", clear).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;
+ }
+ send.push_str("\n");
+ stream.write_all(send.as_bytes()).unwrap();
+ }
+ stdout.flush().unwrap();
+ }
+}