Skip to content

Commit

Permalink
Implement SpeedRunIGT Parsing (#591)
Browse files Browse the repository at this point in the history
`SpeedRunIGT` is a Minecraft mod that brings a full timer with deep auto
splitting capabilities to Minecraft. They recently added support for
https://therun.gg and it seems like it's quite commonly used, probably
the most commonly used timer after LiveSplit at this point. So it makes
sense for us to be able to parse these splits.

I also snuck in a few cleanups along the way (some now possible because
of Rust 1.65).
  • Loading branch information
CryZe authored Nov 5, 2022
1 parent 2298fc2 commit 93da09e
Show file tree
Hide file tree
Showing 17 changed files with 5,599 additions and 59 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ std = [
"serde/std",
"simdutf8/std",
"snafu/std",
"time/formatting",
"time/local-offset",
"tiny-skia?/std",
"winapi",
Expand Down
2 changes: 1 addition & 1 deletion capi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ crate-type = ["staticlib", "cdylib"]
[dependencies]
livesplit-core = { path = "..", default-features = false, features = ["std"] }
serde_json = { version = "1.0.8", default-features = false }
time = { version = "0.3.4", default-features = false }
time = { version = "0.3.4", default-features = false, features = ["formatting"] }
simdutf8 = { version = "0.1.4", default-features = false }

[features]
Expand Down
7 changes: 3 additions & 4 deletions crates/livesplit-auto-splitting/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,10 @@ impl<T: Timer> Runtime<T> {
.get_typed_func(&mut store, "update")
.context(MissingUpdateFunction)?;

if let Some(Extern::Memory(mem)) = instance.get_export(&mut store, "memory") {
store.data_mut().memory = Some(mem);
} else {
let Some(Extern::Memory(mem)) = instance.get_export(&mut store, "memory") else {
return Err(CreationError::MissingMemory);
}
};
store.data_mut().memory = Some(mem);

Ok(Self {
engine,
Expand Down
15 changes: 8 additions & 7 deletions src/analysis/state_helper.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Provides different helper functions.

use crate::comparison::best_segments;
use crate::settings::SemanticColor;
use crate::{timing::Snapshot, Run, Segment, TimeSpan, Timer, TimerPhase, TimingMethod};
use crate::{
comparison::best_segments, settings::SemanticColor, timing::Snapshot, Run, Segment, TimeSpan,
Timer, TimerPhase, TimingMethod,
};

/// Gets the last non-live delta in the run starting from `segment_index`.
///
Expand Down Expand Up @@ -283,11 +284,11 @@ pub fn check_live_delta(
&& best_segment_delta.map_or(false, |d| d > TimeSpan::zero())
|| comparison_delta.map_or(false, |d| d > TimeSpan::zero())
{
if split_delta {
return catch! { current_time? - current_split? };
return if split_delta {
catch! { current_time? - current_split? }
} else {
return comparison_delta;
}
comparison_delta
};
}
}
None
Expand Down
14 changes: 6 additions & 8 deletions src/component/title/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,16 @@ impl Component {
let unchanged = catch! {
let mut rem = &**state.line1.last()?;

if let Some(rest) = rem.strip_prefix(game_name) {
rem = rest;
} else {
let Some(rest) = rem.strip_prefix(game_name) else {
return None;
}
};
rem = rest;

if !game_name.is_empty() && !full_category_name.is_empty() {
if let Some(rest) = rem.strip_prefix(" - ") {
rem = rest;
} else {
let Some(rest) = rem.strip_prefix(" - ") else {
return None;
}
};
rem = rest;
}

if rem != full_category_name {
Expand Down
13 changes: 9 additions & 4 deletions src/run/parser/composite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

use super::{
face_split, flitter, livesplit, llanfair, llanfair_gered, portal2_live_timer, shit_split,
source_live_timer, splits_io, splitterino, splitterz, splitty, time_split_tracker, urn, wsplit,
TimerKind,
source_live_timer, speedrun_igt, splits_io, splitterino, splitterz, splitty,
time_split_tracker, urn, wsplit, TimerKind,
};
use crate::{platform::path::PathBuf, Run};
use core::{result::Result as StdResult, str};
Expand Down Expand Up @@ -142,8 +142,9 @@ pub fn parse(source: &[u8], path: Option<PathBuf>, load_files: bool) -> Result<P
return Ok(parsed(run, TimerKind::Generic(timer)));
}

// Splitterino, SourceLiveTimer and Flitter need to be before Urn because of
// a false positive due to the nature of parsing json files.
// Splitterino, SourceLiveTimer, Flitter, and SpeedRunIGT need to be
// before Urn because of a false positive due to the nature of parsing
// JSON files.
if let Ok(run) = splitterino::parse(source) {
return Ok(parsed(run, TimerKind::Splitterino));
}
Expand All @@ -156,6 +157,10 @@ pub fn parse(source: &[u8], path: Option<PathBuf>, load_files: bool) -> Result<P
return Ok(parsed(run, TimerKind::SourceLiveTimer));
}

if let Ok(run) = speedrun_igt::parse(source) {
return Ok(parsed(run, TimerKind::SpeedRunIGT));
}

// Urn accepts entirely empty JSON files.
if let Ok(run) = urn::parse(source) {
return Ok(parsed(run, TimerKind::Urn));
Expand Down
1 change: 1 addition & 0 deletions src/run/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub mod llanfair_gered;
pub mod portal2_live_timer;
pub mod shit_split;
pub mod source_live_timer;
pub mod speedrun_igt;
pub mod splits_io;
pub mod splitterino;
pub mod splitterz;
Expand Down
Loading

0 comments on commit 93da09e

Please sign in to comment.