diff options
| author | tom barrett <spalf0@gmail.com> | 2018-06-27 07:51:47 -0500 | 
|---|---|---|
| committer | tom barrett <spalf0@gmail.com> | 2018-06-27 07:51:47 -0500 | 
| commit | ae79327d4f0ee6de0ef6b8e3c51299aebfe3bc25 (patch) | |
| tree | db6d4b049d94e41989178566a3dca52ab24b5b1e /src/modules/construction.rs | |
| parent | 25d556ad995a83c0c783f0bf9ca555b17cb0bfb0 (diff) | |
-added elementry construction module, doesnt do anything other than exist as a mass
Diffstat (limited to 'src/modules/construction.rs')
| -rw-r--r-- | src/modules/construction.rs | 61 | 
1 files changed, 61 insertions, 0 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; +    } +} | 
