diff options
author | tom barrett <spalf0@gmail.com> | 2018-06-26 04:49:31 -0500 |
---|---|---|
committer | tom barrett <spalf0@gmail.com> | 2018-06-26 04:49:31 -0500 |
commit | 25d556ad995a83c0c783f0bf9ca555b17cb0bfb0 (patch) | |
tree | dd18a8c287e3a397ee3ab8281643ee4a48ce9125 /src/modules | |
parent | 2d01ede909281e8c412924ba524b7406c2d760ee (diff) |
-moved to enum states for mining and refinery, added mining module knowing if astroid has no minerals
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/mining.rs | 57 | ||||
-rw-r--r-- | src/modules/mod.rs | 4 | ||||
-rw-r--r-- | src/modules/refinery.rs | 35 |
3 files changed, 57 insertions, 39 deletions
diff --git a/src/modules/mining.rs b/src/modules/mining.rs index 7f11f05..4a1a37f 100644 --- a/src/modules/mining.rs +++ b/src/modules/mining.rs @@ -1,55 +1,64 @@ use std::time::SystemTime; +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +pub enum MiningStatus { + None, + Mining, + Mined, +} + #[derive(Serialize, Deserialize, Debug, Clone)] pub struct Mining { pub range : f64, - pub status : bool, + pub status : MiningStatus, time : u64, start : Option<SystemTime>, - pub ready : bool, } - impl Mining { pub fn new() -> Mining { Mining { range : 10.0, - status : false, + status : MiningStatus::None, time : 5, start : None, - ready : false, } } - pub fn toggle(&mut self) { - self.status = !self.status; - self.start = match self.status { - true => Some(SystemTime::now()), - false => None, - }; - } - - pub fn off(&mut self) { - self.status = false; - } - - pub fn take(&mut self) { - self.ready = false; - } - pub fn process(&mut self) { match self.start.clone() { Some(timer) => { if timer.elapsed().unwrap().as_secs() > self.time { + self.status = MiningStatus::Mined; self.start = Some(SystemTime::now()); - self.ready = true; } } _ => (), } - if !self.status { + if self.status == MiningStatus::None { self.start = None; - self.ready = false; } } + + pub fn toggle(&mut self) { + self.status = match self.status { + MiningStatus::None => { + self.start = Some(SystemTime::now()); + MiningStatus::Mining + } + _ => { + self.start = None; + MiningStatus::None + } + }; + } + + pub fn off(&mut self) { + self.status = MiningStatus::None; + } + + pub fn take(&mut self) { + self.status = MiningStatus::Mining; + } + } diff --git a/src/modules/mod.rs b/src/modules/mod.rs index 61e8133..18cba81 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -1,6 +1,6 @@ +pub mod types; pub mod mining; pub mod engines; +pub mod refinery; pub mod dashboard; pub mod navigation; -pub mod refinery; -pub mod types; diff --git a/src/modules/refinery.rs b/src/modules/refinery.rs index 733fcd4..177f2c5 100644 --- a/src/modules/refinery.rs +++ b/src/modules/refinery.rs @@ -1,11 +1,17 @@ use std::time::SystemTime; +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +pub enum RefineryStatus { + None, + Refining, + Refined, +} + #[derive(Serialize, Deserialize, Debug, Clone)] pub struct Refinery { time : u64, start : Option<SystemTime>, - pub status : bool, - pub ready : bool, + pub status : RefineryStatus, } impl Refinery { @@ -13,8 +19,7 @@ impl Refinery { Refinery { time : 5, start : None, - status : false, - ready : false, + status : RefineryStatus::None, } } @@ -22,31 +27,35 @@ impl Refinery { match self.start.clone() { Some(timer) => { if timer.elapsed().unwrap().as_secs() > self.time { + self.status = RefineryStatus::Refined; self.start = Some(SystemTime::now()); - self.ready = true; } } _ => (), } - if !self.status { + if self.status == RefineryStatus::None { self.start = None; - self.ready = false; } } pub fn toggle(&mut self) { - self.status = !self.status; - self.start = match self.status { - true => Some(SystemTime::now()), - false => None, + self.status = match self.status { + RefineryStatus::None => { + self.start = Some(SystemTime::now()); + RefineryStatus::Refining + }, + _ => { + self.start = None; + RefineryStatus::None + } }; } pub fn off(&mut self) { - self.status = false; + self.status = RefineryStatus::None; } pub fn take(&mut self) { - self.ready = false; + self.status = RefineryStatus::Refining; } } |