Skip to content

Commit

Permalink
refactor(animation): avoid unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
thearturca authored and LGUG2Z committed Apr 30, 2024
1 parent 57e9b2f commit fa6d5bb
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions komorebi/src/animation_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,25 @@ impl AnimationManager {
}

pub fn is_cancelled(&self, hwnd: isize) -> bool {
if !self.animations.contains_key(&hwnd) {
return false;
if let Some(animation_state) = self.animations.get(&hwnd) {
animation_state.is_cancelled
} else {
false
}

self.animations.get(&hwnd).unwrap().is_cancelled
}

pub fn in_progress(&self, hwnd: isize) -> bool {
if !self.animations.contains_key(&hwnd) {
return false;
if let Some(animation_state) = self.animations.get(&hwnd) {
animation_state.in_progress
} else {
false
}

self.animations.get(&hwnd).unwrap().in_progress
}

pub fn cancel(&mut self, hwnd: isize) {
if !self.animations.contains_key(&hwnd) {
return;
if let Some(animation_state) = self.animations.get_mut(&hwnd) {
animation_state.is_cancelled = true;
}

let state = self.animations.get_mut(&hwnd).unwrap();
state.is_cancelled = true;
}

pub fn start(&mut self, hwnd: isize) {
Expand All @@ -55,22 +52,17 @@ impl AnimationManager {
return;
}

let state = self.animations.get_mut(&hwnd).unwrap();

if !state.in_progress {
state.in_progress = true;
if let Some(animation_state) = self.animations.get_mut(&hwnd) {
animation_state.in_progress = true;
}
}

pub fn end(&mut self, hwnd: isize) {
if !self.animations.contains_key(&hwnd) {
return;
}

let state = self.animations.get_mut(&hwnd).unwrap();
state.in_progress = false;
state.is_cancelled = false;
if let Some(animation_state) = self.animations.get_mut(&hwnd) {
animation_state.in_progress = false;
animation_state.is_cancelled = false;

self.animations.remove(&hwnd);
self.animations.remove(&hwnd);
}
}
}

0 comments on commit fa6d5bb

Please sign in to comment.