Skip to content

Commit

Permalink
Timer trait: add current_split_index
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKnauth committed Feb 3, 2024
1 parent d8ba361 commit b487f06
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crates/livesplit-auto-splitting/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ pub trait Timer {
fn undo_split(&mut self);
/// Resets the timer.
fn reset(&mut self);
/// Accesses the index of the split the attempt is currently on. If there's
/// no attempt in progress, `None` is returned instead. This returns an
/// index that is equal to the amount of segments when the attempt is
/// finished, but has not been reset. So you need to be careful when using
/// this value for indexing.
fn current_split_index(&self) -> Option<usize>;
/// Sets the game time.
fn set_game_time(&mut self, time: time::Duration);
/// Pauses the game time. This does not pause the timer, only the automatic
Expand Down
3 changes: 3 additions & 0 deletions crates/livesplit-auto-splitting/tests/sandboxing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ impl Timer for DummyTimer {
fn skip_split(&mut self) {}
fn undo_split(&mut self) {}
fn reset(&mut self) {}
fn current_split_index(&self) -> Option<usize> {
None
}
fn set_game_time(&mut self, _time: time::Duration) {}
fn pause_game_time(&mut self) {}
fn resume_game_time(&mut self) {}
Expand Down
4 changes: 4 additions & 0 deletions src/auto_splitting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,10 @@ impl AutoSplitTimer for Timer {
self.0.write().unwrap().reset(true)
}

fn current_split_index(&self) -> Option<usize> {
self.0.read().unwrap().current_split_index()
}

fn set_game_time(&mut self, time: time::Duration) {
self.0.write().unwrap().set_game_time(time.into());
}
Expand Down

0 comments on commit b487f06

Please sign in to comment.