Skip to content

Commit

Permalink
Fix incorrect handling of missing pre_sudden_death_break
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanDebrunner committed Jul 9, 2023
1 parent e9fe77a commit cbbb039
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions uwh-common/src/uwhscores.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ pub struct TimingRules {
pub min_game_break: Duration,
pub overtime_allowed: bool,
pub sudden_death_allowed: bool,
#[serde(deserialize_with = "deser_secs_to_opt_dur")]
pub pre_sudden_death_break: Option<Duration>,
pub pre_sudden_death_break: Option<u64>,
}

#[allow(clippy::from_over_into)]
Expand All @@ -80,9 +79,11 @@ impl Into<GameConfig> for TimingRules {
minimum_break: self.min_game_break,
overtime_allowed: self.overtime_allowed,
sudden_death_allowed: self.sudden_death_allowed,
pre_sudden_death_duration: self
.pre_sudden_death_break
.unwrap_or(GameConfig::default().pre_sudden_death_duration),
pre_sudden_death_duration: if let Some(len) = self.pre_sudden_death_break {
Duration::from_secs(len)
} else {
GameConfig::default().pre_sudden_death_duration
},
..Default::default()
}
}
Expand All @@ -103,13 +104,6 @@ where
u64::deserialize(deserializer).map(Duration::from_secs)
}

fn deser_secs_to_opt_dur<'de, D>(deserializer: D) -> Result<Option<Duration>, D::Error>
where
D: Deserializer<'de>,
{
u64::deserialize(deserializer).map(|len| Some(Duration::from_secs(len)))
}

// Deserialize noramlly, but use the value's default if `null` is found
fn deser_with_null_to_default<'de, D, T: Deserialize<'de> + Default>(
deserializer: D,
Expand Down

0 comments on commit cbbb039

Please sign in to comment.