summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/construction.rs61
-rw-r--r--src/modules/mining.rs22
-rw-r--r--src/modules/mod.rs1
-rw-r--r--src/modules/refinery.rs21
-rw-r--r--src/modules/types.rs1
5 files changed, 81 insertions, 25 deletions
diff --git a/src/modules/construction.rs b/src/modules/construction.rs
new file mode 100644
index 0000000..22086a5
--- /dev/null
+++ b/src/modules/construction.rs
@@ -0,0 +1,61 @@
+use std::time::SystemTime;
+use modules::types::ModuleType;
+
+#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
+pub enum ConstructionStatus {
+ None,
+ Constructing,
+ Constructed,
+}
+
+#[derive(Serialize, Deserialize, Debug, Clone)]
+pub struct Construction {
+ pub status : ConstructionStatus,
+ construction : Option<ModuleType>,
+ time : u64,
+ start : Option<SystemTime>,
+}
+
+impl Construction {
+ pub fn new() -> Construction {
+ Construction {
+ status : ConstructionStatus::None,
+ construction : None,
+ time : 5,
+ start : None,
+ }
+ }
+
+ pub fn process(&mut self) {
+ match self.start.clone() {
+ Some(timer) => {
+ if timer.elapsed().unwrap().as_secs() > self.time {
+ self.start = Some(SystemTime::now());
+ self.status = ConstructionStatus::Constructed;
+ }
+ }
+ _ => (),
+ }
+ }
+
+ pub fn toggle(&mut self) {
+ match self.status {
+ ConstructionStatus::None => self.on(),
+ _ => self.off(),
+ };
+ }
+
+ pub fn on(&mut self) {
+ self.start = Some(SystemTime::now());
+ self.status = ConstructionStatus::Constructing;
+ }
+
+ pub fn off(&mut self) {
+ self.start = None;
+ self.status = ConstructionStatus::None;
+ }
+
+ pub fn take(&mut self) {
+ self.status = ConstructionStatus::None;
+ }
+}
diff --git a/src/modules/mining.rs b/src/modules/mining.rs
index 4a1a37f..7a6461a 100644
--- a/src/modules/mining.rs
+++ b/src/modules/mining.rs
@@ -35,30 +35,26 @@ impl Mining {
}
_ => (),
}
- if self.status == MiningStatus::None {
- self.start = None;
- }
}
pub fn toggle(&mut self) {
- self.status = match self.status {
- MiningStatus::None => {
- self.start = Some(SystemTime::now());
- MiningStatus::Mining
- }
- _ => {
- self.start = None;
- MiningStatus::None
- }
+ match self.status {
+ MiningStatus::None => self.on(),
+ _ => self.off(),
};
}
+ pub fn on(&mut self) {
+ self.start = Some(SystemTime::now());
+ self.status = MiningStatus::Mining;
+ }
+
pub fn off(&mut self) {
+ self.start = None;
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 18cba81..d0ffd38 100644
--- a/src/modules/mod.rs
+++ b/src/modules/mod.rs
@@ -4,3 +4,4 @@ pub mod engines;
pub mod refinery;
pub mod dashboard;
pub mod navigation;
+pub mod construction;
diff --git a/src/modules/refinery.rs b/src/modules/refinery.rs
index 177f2c5..cdb5de0 100644
--- a/src/modules/refinery.rs
+++ b/src/modules/refinery.rs
@@ -33,25 +33,22 @@ impl Refinery {
}
_ => (),
}
- if self.status == RefineryStatus::None {
- self.start = None;
- }
}
pub fn toggle(&mut self) {
- self.status = match self.status {
- RefineryStatus::None => {
- self.start = Some(SystemTime::now());
- RefineryStatus::Refining
- },
- _ => {
- self.start = None;
- RefineryStatus::None
- }
+ match self.status {
+ RefineryStatus::None => self.on(),
+ _ => self.off(),
};
}
+ pub fn on(&mut self) {
+ self.start = Some(SystemTime::now());
+ self.status = RefineryStatus::Refining;
+ }
+
pub fn off(&mut self) {
+ self.start = None;
self.status = RefineryStatus::None;
}
diff --git a/src/modules/types.rs b/src/modules/types.rs
index 48b3473..17e7c6c 100644
--- a/src/modules/types.rs
+++ b/src/modules/types.rs
@@ -5,4 +5,5 @@ pub enum ModuleType {
Refinery,
Dashboard,
Navigation,
+ Construction,
}