From c297e871b7ce8935dd3bb1c65ecae37000d9a331 Mon Sep 17 00:00:00 2001 From: tom barrett Date: Mon, 19 Mar 2018 05:06:50 -0500 Subject: -pass module information in a serializable way --- src/ship.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/ship.rs') 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, + modules : Vec, } 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 { 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 { -- cgit v1.2.3