summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2018-02-28 10:05:22 -0600
committertom barrett <spalf0@gmail.com>2018-02-28 10:05:22 -0600
commit3d0efb20ac17ae18c495ffbb1b7d28b22851cb28 (patch)
tree1a6180f77e8298636a35865bec585ac08bf06387
parent1edbee505f2f026ab78603fcb0a38f3acbd0dad1 (diff)
-got rid of erased-serde, set up navigation better
-rw-r--r--Cargo.lock10
-rw-r--r--Cargo.toml1
-rw-r--r--src/astroid.rs6
-rw-r--r--src/connection.rs9
-rw-r--r--src/dashboard.rs1
-rw-r--r--src/engines.rs1
-rw-r--r--src/lib.rs1
-rw-r--r--src/navigation.rs50
-rw-r--r--src/ship.rs4
9 files changed, 29 insertions, 54 deletions
diff --git a/Cargo.lock b/Cargo.lock
index ab9d1b9..ef5b2dd 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -14,14 +14,6 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
-name = "erased-serde"
-version = "0.3.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
name = "fuchsia-zircon"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -126,7 +118,6 @@ name = "space"
version = "0.1.0"
dependencies = [
"downcast 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "erased-serde 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -190,7 +181,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf"
"checksum downcast 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "242756f88358d71447a37780b71b1cb180a276bd214765ee2d81dfe7c90e59bb"
"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab"
-"checksum erased-serde 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c564e32677839f1c551664c478e079c9b128a1a2d223180bffb2ddfabeded0be"
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
"checksum itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8324a32baf01e2ae060e9de58ed0bc2320c9a2833491ee36cd3b4c414de4db8c"
diff --git a/Cargo.toml b/Cargo.toml
index 69c08e8..baefb5f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,7 +6,6 @@ authors = ["tom barrett <spalf0@gmail.com>"]
[dependencies]
serde = "1.0"
serde_derive = "1.0"
-erased-serde = "0.3"
serde_json = "1.0"
termion = "1.5.1"
downcast = "0.8"
diff --git a/src/astroid.rs b/src/astroid.rs
index ab00e6e..1e7c99c 100644
--- a/src/astroid.rs
+++ b/src/astroid.rs
@@ -1,8 +1,10 @@
-use mass::{Mass, Type};
-extern crate rand;
use self::rand::distributions::Range;
use astroid::rand::distributions::Sample;
+
+extern crate rand;
extern crate serde_json;
+
+use mass::{Mass, Type};
use astroid::rand::Rng;
#[derive(Serialize, Deserialize, Debug)]
diff --git a/src/connection.rs b/src/connection.rs
index 2f51920..3ca3b08 100644
--- a/src/connection.rs
+++ b/src/connection.rs
@@ -3,18 +3,13 @@ use std::io::BufReader;
use std::net::TcpStream;
extern crate serde_json;
-extern crate erased_serde;
-
-use erased_serde::Deserializer;
use ship::Ship;
use mass::Mass;
-use astroid::Astroid;
-use module::{Module, from_primitive};
-use math::distance;
-use dashboard::server_dashboard;
use engines::server_engines;
+use dashboard::server_dashboard;
use navigation::server_navigation;
+use module::{Module, from_primitive};
pub struct Connection {
index : usize,
diff --git a/src/dashboard.rs b/src/dashboard.rs
index 99d5331..bfad542 100644
--- a/src/dashboard.rs
+++ b/src/dashboard.rs
@@ -6,7 +6,6 @@ use std::io::Write;
extern crate serde_json;
use ship::Ship;
-use mass::Mass;
pub fn client_dashboard(mut buff_r : BufReader<TcpStream>) {
loop {
diff --git a/src/engines.rs b/src/engines.rs
index 64d80bc..9d8841d 100644
--- a/src/engines.rs
+++ b/src/engines.rs
@@ -7,7 +7,6 @@ use std::time::Duration;
use std::io::BufReader;
use std::io::BufRead;
-use ship::Ship;
use mass::Mass;
pub fn client_engines(mut stream : TcpStream) {
diff --git a/src/lib.rs b/src/lib.rs
index 29b3616..b7a3305 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,4 +1,3 @@
-extern crate erased_serde;
#[macro_use]
extern crate serde_derive;
#[macro_use]
diff --git a/src/navigation.rs b/src/navigation.rs
index 430ebc0..e55b65a 100644
--- a/src/navigation.rs
+++ b/src/navigation.rs
@@ -1,15 +1,12 @@
use std::net::TcpStream;
use std::io::{BufRead, BufReader};
-use std::io::{stdout, Read, Write, stdin};
+use std::io::{stdout, Read, Write};
use termion::raw::IntoRawMode;
use termion::async_stdin;
-extern crate erased_serde;
extern crate serde_json;
extern crate termion;
-use erased_serde::Deserializer;
-
use mass::Mass;
use ship::Ship;
use math::distance;
@@ -26,29 +23,15 @@ pub fn client_navigation(name : String, mut stream : TcpStream, mut buff_r : Buf
let string_masses = data.split(";");
let mut masses : Vec<Box<Mass>> = Vec::new();
- let mut ship : Option<Ship> = None;
for string_mass in string_masses {
if string_mass.len() == 1 {
break;
}
- let json = &mut serde_json::de::Deserializer::from_slice(string_mass.as_bytes());
- let mut deserialized : Box<Deserializer> = Box::new(Deserializer::erase(json));
-
- if string_mass.contains("Ship") {
- let mass : Ship = erased_serde::deserialize(&mut deserialized).unwrap();
- if mass.name() == &name {
- ship = Some(mass);
- }
- else {
- masses.push(Box::new(mass));
- }
- }
- else {
- let mass : Astroid = erased_serde::deserialize(&mut deserialized).unwrap();
- masses.push(Box::new(mass));
- }
+ masses.push(build_mass(string_mass));
}
+ let ship = masses.iter().find(|ship| ship.name() == &name);
+
write!(stdout, "{}{}Targets:",
termion::clear::All,
termion::cursor::Goto(1,1)).unwrap();
@@ -109,19 +92,24 @@ pub fn server_navigation(masses : &mut Vec<Box<Mass>>, index : usize, mut stream
Err(_error) => return false,
}
- /*
let mut string_mass = String::new();
buff_r.read_line(&mut string_mass).unwrap();
if string_mass.len() > 0 {
- let json = &mut serde_json::de::Deserializer::from_slice(string_mass.as_bytes());
- let mut deserialized : Box<Deserializer> = Box::new(Deserializer::erase(json));
- if string_mass.contains("Ship") {
- let mass : Ship = erased_serde::deserialize(&mut deserialized).unwrap();
- }
- else {
- let mass : Astroid = erased_serde::deserialize(&mut deserialized).unwrap();
- }
+ let target = build_mass(&string_mass);
+ //ship.give_target(masses.iter().position(|mass|
+ // mass.name() == target.name()));
}
- */
+
true
}
+
+fn build_mass(string_mass : &str) -> Box<Mass> {
+ let mut mass = Astroid::new();
+ if string_mass.contains("Ship") {
+ let mass : Ship = serde_json::from_str(&string_mass).unwrap();
+ }
+ else {
+ let mass : Astroid = serde_json::from_str(&string_mass).unwrap();
+ }
+ Box::new(mass)
+}
diff --git a/src/ship.rs b/src/ship.rs
index 16a3d01..08b4d93 100644
--- a/src/ship.rs
+++ b/src/ship.rs
@@ -23,6 +23,10 @@ impl Ship {
}
}
+ pub fn give_target(&mut self, target : Option<usize>) {
+ self.target = target;
+ }
+
pub fn range(&self) -> f64 {
self.r
}