Skip to content

Commit

Permalink
Timer trait: add current_split_index
Browse files Browse the repository at this point in the history
WebEventSink: current_split_index

web-sys, js-sys: 0.3.65

0.3.65 is when web_sys starts re-exporting js_sys, which web_event_sink relies on for use web_sys::js_sys
  • Loading branch information
AlexKnauth committed Jun 30, 2024
1 parent bb8cb41 commit 65045ef
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ log = { version = "0.4.14", default-features = false, optional = true }

[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies]
# WebAssembly in the Web
js-sys = { version = "0.3.55", optional = true }
js-sys = { version = "0.3.65", optional = true }
wasm-bindgen = { version = "0.2.78", optional = true }
wasm-bindgen-futures = { version = "0.4.28", optional = true }
web-sys = { version = "0.3.28", default-features = false, features = [
web-sys = { version = "0.3.65", default-features = false, features = [
"Document",
"Performance",
"VisibilityState",
Expand Down
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: 2 additions & 2 deletions crates/livesplit-hotkey/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ x11-dl = { version = "2.20.0", optional = true }

[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies]
wasm-bindgen = { version = "0.2.54", optional = true }
web-sys = { version = "0.3.28", default-features = false, features = [
web-sys = { version = "0.3.65", default-features = false, features = [
"EventTarget",
"Gamepad",
"GamepadButton",
"KeyboardEvent",
"Navigator",
"Window",
], optional = true }
js-sys = { version = "0.3.28", default-features = false, optional = true }
js-sys = { version = "0.3.65", default-features = false, optional = true }

[dependencies]
cfg-if = "1.0.0"
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 @@ -749,6 +749,10 @@ impl<E: event::CommandSink + TimerQuery> AutoSplitTimer for Timer<E> {
drop(self.0.reset(None));
}

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

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

0 comments on commit 65045ef

Please sign in to comment.