#[derive(Default, Clone, Copy)]
pub struct Timer {
  time: i32,
  wait_countdown: u32,
  stopped: bool,
}

impl Timer {
  pub fn time(&self) -> i32 {
    self.time
  }

  pub fn set_time(&mut self, time: i32) {
    self.time = time;
  }

  pub fn waiting(&self) -> bool {
    self.wait_countdown > 0 || self.stopped
  }

  pub fn wait(&mut self, time: u32) {
    self.wait_countdown = time;
  }

  pub fn stop(&mut self) {
    self.stopped = true;
  }

  pub fn tick(&mut self) {
    if self.stopped {
      return;
    }

    if self.wait_countdown > 0 {
      self.wait_countdown = self.wait_countdown.saturating_sub(1);
      return;
    }

    self.time += 1;
  }
}
