diff --git a/crates/livesplit-auto-splitting/README.md b/crates/livesplit-auto-splitting/README.md index 96e94b99..47676402 100644 --- a/crates/livesplit-auto-splitting/README.md +++ b/crates/livesplit-auto-splitting/README.md @@ -110,6 +110,12 @@ extern "C" { pub fn timer_undo_split(); /// Resets the timer. pub fn timer_reset(); + /// Accesses the index of the split the attempt is currently on. If there's + /// no attempt in progress, `-1` 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. + pub fn timer_current_split_index() -> i32; /// Sets a custom key value pair. This may be arbitrary information that the /// auto splitter wants to provide for visualization. The pointers need to /// point to valid UTF-8 encoded text with the respective given length. diff --git a/crates/livesplit-auto-splitting/src/lib.rs b/crates/livesplit-auto-splitting/src/lib.rs index 621fe334..01c2f564 100644 --- a/crates/livesplit-auto-splitting/src/lib.rs +++ b/crates/livesplit-auto-splitting/src/lib.rs @@ -110,6 +110,12 @@ //! pub fn timer_undo_split(); //! /// Resets the timer. //! pub fn timer_reset(); +//! /// Accesses the index of the split the attempt is currently on. If there's +//! /// no attempt in progress, `-1` 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. +//! pub fn timer_current_split_index() -> i32; //! /// Sets a custom key value pair. This may be arbitrary information that the //! /// auto splitter wants to provide for visualization. The pointers need to //! /// point to valid UTF-8 encoded text with the respective given length. diff --git a/crates/livesplit-auto-splitting/src/runtime/api/timer.rs b/crates/livesplit-auto-splitting/src/runtime/api/timer.rs index 5f88e035..708c5c29 100644 --- a/crates/livesplit-auto-splitting/src/runtime/api/timer.rs +++ b/crates/livesplit-auto-splitting/src/runtime/api/timer.rs @@ -69,6 +69,19 @@ pub fn bind(linker: &mut Linker>) -> Result<(), CreationErr source, name: "timer_reset", })? + .func_wrap("env", "timer_current_split_index", { + |caller: Caller<'_, Context>| { + caller + .data() + .timer + .current_split_index() + .map_or(-1, |i| i as i32) + } + }) + .map_err(|source| CreationError::LinkFunction { + source, + name: "timer_current_split_index", + })? .func_wrap("env", "timer_set_variable", { |mut caller: Caller<'_, Context>, name_ptr: u32, diff --git a/src/auto_splitting/mod.rs b/src/auto_splitting/mod.rs index 175090e7..0e01a166 100644 --- a/src/auto_splitting/mod.rs +++ b/src/auto_splitting/mod.rs @@ -110,6 +110,12 @@ //! pub fn timer_undo_split(); //! /// Resets the timer. //! pub fn timer_reset(); +//! /// Accesses the index of the split the attempt is currently on. If there's +//! /// no attempt in progress, `-1` 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. +//! pub fn timer_current_split_index() -> i32; //! /// Sets a custom key value pair. This may be arbitrary information that the //! /// auto splitter wants to provide for visualization. The pointers need to //! /// point to valid UTF-8 encoded text with the respective given length.