Skip to content

Commit edcf86b

Browse files
committed
Add timer_current_split_index
1 parent ee19d0a commit edcf86b

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

crates/livesplit-auto-splitting/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ extern "C" {
110110
pub fn timer_undo_split();
111111
/// Resets the timer.
112112
pub fn timer_reset();
113+
/// Accesses the index of the split the attempt is currently on. If there's
114+
/// no attempt in progress, `-1` is returned instead. This returns an
115+
/// index that is equal to the amount of segments when the attempt is
116+
/// finished, but has not been reset. So you need to be careful when using
117+
/// this value for indexing.
118+
pub fn timer_current_split_index() -> i32;
113119
/// Sets a custom key value pair. This may be arbitrary information that the
114120
/// auto splitter wants to provide for visualization. The pointers need to
115121
/// point to valid UTF-8 encoded text with the respective given length.

crates/livesplit-auto-splitting/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@
110110
//! pub fn timer_undo_split();
111111
//! /// Resets the timer.
112112
//! pub fn timer_reset();
113+
//! /// Accesses the index of the split the attempt is currently on. If there's
114+
//! /// no attempt in progress, `-1` is returned instead. This returns an
115+
//! /// index that is equal to the amount of segments when the attempt is
116+
//! /// finished, but has not been reset. So you need to be careful when using
117+
//! /// this value for indexing.
118+
//! pub fn timer_current_split_index() -> i32;
113119
//! /// Sets a custom key value pair. This may be arbitrary information that the
114120
//! /// auto splitter wants to provide for visualization. The pointers need to
115121
//! /// point to valid UTF-8 encoded text with the respective given length.

crates/livesplit-auto-splitting/src/runtime/api/timer.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ pub fn bind<T: Timer>(linker: &mut Linker<Context<T>>) -> Result<(), CreationErr
6969
source,
7070
name: "timer_reset",
7171
})?
72+
.func_wrap("env", "timer_current_split_index", {
73+
|caller: Caller<'_, Context<T>>| {
74+
caller
75+
.data()
76+
.timer
77+
.current_split_index()
78+
.map_or(-1, |i| i as i32)
79+
}
80+
})
81+
.map_err(|source| CreationError::LinkFunction {
82+
source,
83+
name: "timer_current_split_index",
84+
})?
7285
.func_wrap("env", "timer_set_variable", {
7386
|mut caller: Caller<'_, Context<T>>,
7487
name_ptr: u32,

src/auto_splitting/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@
110110
//! pub fn timer_undo_split();
111111
//! /// Resets the timer.
112112
//! pub fn timer_reset();
113+
//! /// Accesses the index of the split the attempt is currently on. If there's
114+
//! /// no attempt in progress, `-1` is returned instead. This returns an
115+
//! /// index that is equal to the amount of segments when the attempt is
116+
//! /// finished, but has not been reset. So you need to be careful when using
117+
//! /// this value for indexing.
118+
//! pub fn timer_current_split_index() -> i32;
113119
//! /// Sets a custom key value pair. This may be arbitrary information that the
114120
//! /// auto splitter wants to provide for visualization. The pointers need to
115121
//! /// point to valid UTF-8 encoded text with the respective given length.

0 commit comments

Comments
 (0)