|
99 | 99 | //! unsafe extern "C" { |
100 | 100 | //! /// Gets the state that the timer currently is in. |
101 | 101 | //! pub safe fn timer_get_state() -> TimerState; |
| 102 | +//! /// Accesses the index of the split the attempt is currently on. |
| 103 | +//! /// If there's no attempt in progress, `-1` is returned instead. |
| 104 | +//! /// This returns an index that is equal to the amount of segments |
| 105 | +//! /// when the attempt is finished, but has not been reset. |
| 106 | +//! /// So you need to be careful when using this value for indexing. |
| 107 | +//! /// Same index does not imply same split on undo and then split. |
| 108 | +//! pub safe fn timer_current_split_index() -> i64; |
| 109 | +//! /// Whether the segment at `idx` was splitted this attempt. |
| 110 | +//! /// Returns `1` if the segment was splitted, or `0` if skipped. |
| 111 | +//! /// If `idx` is greater than or equal to the current split index, |
| 112 | +//! /// `-1` is returned instead. |
| 113 | +//! pub safe fn timer_segment_splitted(idx: u64) -> i32; |
102 | 114 | //! |
103 | 115 | //! /// Starts the timer. |
104 | 116 | //! pub safe fn timer_start(); |
@@ -787,6 +799,25 @@ impl<E: event::CommandSink + TimerQuery + Send> AutoSplitTimer for Timer<E> { |
787 | 799 | } |
788 | 800 | } |
789 | 801 |
|
| 802 | + fn current_split_index(&self) -> Option<usize> { |
| 803 | + self.0.get_timer().current_split_index() |
| 804 | + } |
| 805 | + |
| 806 | + fn segment_splitted(&self, idx: usize) -> Option<bool> { |
| 807 | + let t = self.0.get_timer(); |
| 808 | + if !(idx < t.current_split_index()?) { |
| 809 | + return None; |
| 810 | + } |
| 811 | + Some( |
| 812 | + t.run() |
| 813 | + .segments() |
| 814 | + .get(idx)? |
| 815 | + .split_time() |
| 816 | + .real_time |
| 817 | + .is_some(), |
| 818 | + ) |
| 819 | + } |
| 820 | + |
790 | 821 | fn start(&mut self) { |
791 | 822 | drop(self.0.start()); |
792 | 823 | } |
|
0 commit comments