summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2018-02-23 05:04:55 -0600
committertom barrett <spalf0@gmail.com>2018-02-23 05:04:55 -0600
commitceb9ee22f32d46a6e49229f447c414f3707eb3ac (patch)
tree888b5b9824655d05b26f11848ca5290a7e032485
parent7798ebba1d8762e8b4c6eaf1efcd610fa030375a (diff)
various ways potentially to deserialize?
-rw-r--r--src/astroid.rs3
-rw-r--r--src/connection.rs5
-rw-r--r--src/mass.rs1
-rw-r--r--src/navigation.rs14
-rw-r--r--src/ship.rs6
5 files changed, 26 insertions, 3 deletions
diff --git a/src/astroid.rs b/src/astroid.rs
index dd47123..37460cf 100644
--- a/src/astroid.rs
+++ b/src/astroid.rs
@@ -30,4 +30,7 @@ impl Mass for Astroid {
fn serialize(&self) ->String {
serde_json::to_string(self).unwrap()
}
+
+ fn deserialize(&mut self, data : &str) {
+ }
}
diff --git a/src/connection.rs b/src/connection.rs
index b1a2056..1502d7a 100644
--- a/src/connection.rs
+++ b/src/connection.rs
@@ -88,15 +88,16 @@ impl Connection {
let mut within_range = Vec::new();
for mass in masses.iter() {
- if distance(ship.location(), mass.location()) > ship.range() {
+ if distance(ship.location(), mass.location()) < ship.range() {
within_range.push(mass);
}
}
let mut send = String::new();
for mass in within_range {
send.push_str(&mass.serialize());
- send.push_str("\n");
+ send.push_str(",");
}
+ send.push_str("\n");
match self.stream.write(send.as_bytes()) {
Ok(_result) => (),
Err(_error) => self.open = false,
diff --git a/src/mass.rs b/src/mass.rs
index 955f84d..8c50348 100644
--- a/src/mass.rs
+++ b/src/mass.rs
@@ -6,6 +6,7 @@ pub trait Mass : Any {
fn location(&self) -> (isize, isize, isize);
fn set_location(&mut self, location : (isize, isize, isize));
fn serialize(&self) -> String;
+ fn deserialize(&mut self, data : &str);
}
downcast!(Mass);
diff --git a/src/navigation.rs b/src/navigation.rs
index b3cd9cf..02156d3 100644
--- a/src/navigation.rs
+++ b/src/navigation.rs
@@ -2,9 +2,23 @@ use std::net::TcpStream;
use std::io::BufRead;
use std::io::BufReader;
+extern crate serde_json;
+
+use mass::Mass;
+use ship::Ship;
+
pub fn Navigation(mut stream :TcpStream, mut buff_r : BufReader<TcpStream>){
loop {
let mut data = String::new();
buff_r.read_line(&mut data).unwrap();
+ let string_masses = data.split(",");
+ //let masses : Vec<Box<Mass>> = Vec::new();
+ for string_mass in string_masses {
+ //let mass = Box::new(Ship::new("",(0,0,0)));
+ //mass.deserialize(string_mass);
+
+ //let mass : Box<Mass> = serde_json::from_str(string_mass).unwrap();
+ //masses.push(Box::new(mass));
+ }
}
}
diff --git a/src/ship.rs b/src/ship.rs
index 30a27fb..49da84d 100644
--- a/src/ship.rs
+++ b/src/ship.rs
@@ -19,7 +19,7 @@ impl Mass for Ship {
Ship {
name : String::from(name),
location : location,
- r : 10.0,
+ r : 100.0,
}
}
@@ -38,4 +38,8 @@ impl Mass for Ship {
fn serialize(&self) ->String {
serde_json::to_string(self).unwrap()
}
+
+ fn deserialize(&mut self, data : &str) {
+ //self = serde_json::from_str(data).unwrap();
+ }
}