diff options
author | tom barrett <spalf0@gmail.com> | 2018-03-19 05:06:50 -0500 |
---|---|---|
committer | tom barrett <spalf0@gmail.com> | 2018-03-19 05:06:50 -0500 |
commit | c297e871b7ce8935dd3bb1c65ecae37000d9a331 (patch) | |
tree | d6371df117020da5381acec1024c4fcb35060c76 /src/ship.rs | |
parent | 7a4403d2a26250c82b6f089de3b56e076c69e39a (diff) |
-pass module information in a serializable way
Diffstat (limited to 'src/ship.rs')
-rw-r--r-- | src/ship.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/ship.rs b/src/ship.rs index c33dc6c..e226936 100644 --- a/src/ship.rs +++ b/src/ship.rs @@ -1,3 +1,4 @@ +use module::Module; use mass::{Mass, Type}; extern crate serde_json; @@ -9,10 +10,17 @@ pub struct Ship { mass_type : Type, r : f64, target : Option<usize>, + modules : Vec<Module>, } impl Ship { pub fn new(name : &str, position : (f64, f64, f64)) -> Ship { + let mut modules = Vec::new(); + + modules.push(Module::Navigation); + modules.push(Module::Engines); + modules.push(Module::Dashboard); + Ship { name : String::from(name), position : position, @@ -20,6 +28,7 @@ impl Ship { mass_type : Type::Ship, r : 100.0, target : None, + modules : modules, } } @@ -64,6 +73,18 @@ impl Ship { pub fn recv_target(&self) -> Option<usize> { self.target } + + pub fn get_modules(&self) -> String { + let mut data = String::new(); + + for module in self.modules.iter() { + data.push_str(&serde_json::to_string(&module).unwrap()); + data.push_str(";"); + } + data.push_str("\n"); + + data + } } impl Mass for Ship { |