Skip to content

Commit

Permalink
Add timer_current_split_index
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKnauth committed Nov 17, 2024
1 parent 2fd2b8c commit 2c163a5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crates/livesplit-auto-splitting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions crates/livesplit-auto-splitting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions crates/livesplit-auto-splitting/src/runtime/api/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ pub fn bind<T: Timer>(linker: &mut Linker<Context<T>>) -> Result<(), CreationErr
source,
name: "timer_reset",
})?
.func_wrap("env", "timer_current_split_index", {
|caller: Caller<'_, Context<T>>| {
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<T>>,
name_ptr: u32,
Expand Down
6 changes: 6 additions & 0 deletions src/auto_splitting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 2c163a5

Please sign in to comment.