diff options
author | tom barrett <spalf0@gmail.com> | 2018-02-28 10:05:22 -0600 |
---|---|---|
committer | tom barrett <spalf0@gmail.com> | 2018-02-28 10:05:22 -0600 |
commit | 3d0efb20ac17ae18c495ffbb1b7d28b22851cb28 (patch) | |
tree | 1a6180f77e8298636a35865bec585ac08bf06387 /src | |
parent | 1edbee505f2f026ab78603fcb0a38f3acbd0dad1 (diff) |
-got rid of erased-serde, set up navigation better
Diffstat (limited to 'src')
-rw-r--r-- | src/astroid.rs | 6 | ||||
-rw-r--r-- | src/connection.rs | 9 | ||||
-rw-r--r-- | src/dashboard.rs | 1 | ||||
-rw-r--r-- | src/engines.rs | 1 | ||||
-rw-r--r-- | src/lib.rs | 1 | ||||
-rw-r--r-- | src/navigation.rs | 50 | ||||
-rw-r--r-- | src/ship.rs | 4 |
7 files changed, 29 insertions, 43 deletions
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) { @@ -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 } |