Skip to content

Commit

Permalink
Update countdown and demo duration for hoonymode.
Browse files Browse the repository at this point in the history
  • Loading branch information
vikpe committed Jun 18, 2024
1 parent 73a74ec commit 8ec57e2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ categories = ["parsing"]
keywords = ["demos", "mvd", "parser", "quake", "quakeworld"]
repository = "https://github.com/vikpe/mvdparser"
authors = ["Viktor Persson <viktor.persson@arcsin.se>"]
version = "0.15.0"
version = "0.15.1"
edition = "2021"
license = "MIT"
include = [
Expand Down
22 changes: 21 additions & 1 deletion src/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ use anyhow::{anyhow as e, Result};
use bstr::ByteSlice;

use crate::qw::frame;
use crate::{bytesextra, ktxstats_string, matchdate};
use crate::{bytesextra, ktxstats_string, matchdate, serverinfo};

pub fn countdown_duration(data: &[u8]) -> Result<Duration> {
if serverinfo(data).is_ok_and(|s| s.mode == Some("hoonymode".to_string())) {
return Ok(Duration::ZERO);
}

let Some(offset) = data.find(matchdate::MATCHDATE_NEEDLE) else {
return Err(e!("Countdown not found"));
};
Expand All @@ -23,6 +27,10 @@ pub fn demo_duration(data: &[u8]) -> Result<Duration> {
}

pub fn match_duration(data: &[u8]) -> Result<Duration> {
if serverinfo(data).is_ok_and(|s| s.mode == Some("hoonymode".to_string())) {
return match_duration_from_seeking(data);
}

match_duration_from_ktxstats(data).or_else(|_| match_duration_from_seeking(data))
}

Expand Down Expand Up @@ -70,6 +78,12 @@ mod tests {

#[test]
fn test_countdown_duration() -> Result<()> {
assert_eq!(
countdown_duration(&read(
"tests/files/1on1_milton_vs_mushi[tron]20240616-1719.mvd"
)?)?,
Duration::ZERO,
);
assert_eq!(
countdown_duration(&read("tests/files/ffa_5[dm4]20240501-1229.mvd")?)?,
Duration::from_secs_f32(10.116),
Expand Down Expand Up @@ -105,6 +119,12 @@ mod tests {

#[test]
fn test_demo_duration() -> Result<()> {
assert_eq!(
demo_duration(&read(
"tests/files/1on1_milton_vs_mushi[tron]20240616-1719.mvd"
)?)?,
Duration::from_secs_f32(174.609),
);
assert_eq!(
demo_duration(&read("tests/files/ffa_5[dm4]20240501-1229.mvd")?)?,
Duration::from_secs_f32(71.503),
Expand Down
Binary file not shown.

0 comments on commit 8ec57e2

Please sign in to comment.