feat: added convenience methods
This commit is contained in:
@@ -274,6 +274,12 @@ impl CatchDifficultyAttributes {
|
||||
pub fn max_combo(&self) -> usize {
|
||||
self.n_fruits + self.n_droplets
|
||||
}
|
||||
|
||||
/// Returns a builder for performance calculation.
|
||||
#[inline]
|
||||
pub fn pp(self) -> CatchPP<'static> {
|
||||
CatchPP::from(self)
|
||||
}
|
||||
}
|
||||
|
||||
/// The result of a performance calculation on an osu!catch map.
|
||||
|
||||
+26
-14
@@ -418,20 +418,7 @@ impl<'map> CatchPP<'map> {
|
||||
/// attributes for catch e.g. if it's [`DifficultyAttributes::Taiko`].
|
||||
#[inline]
|
||||
pub fn try_from_attributes(attributes: impl CatchAttributeProvider) -> Option<Self> {
|
||||
attributes.attributes().map(|attrs| Self {
|
||||
map_or_attrs: MapOrElse::Else(attrs),
|
||||
mods: 0,
|
||||
acc: None,
|
||||
combo: None,
|
||||
|
||||
n_fruits: None,
|
||||
n_droplets: None,
|
||||
n_tiny_droplets: None,
|
||||
n_tiny_droplet_misses: None,
|
||||
n_misses: None,
|
||||
passed_objects: None,
|
||||
clock_rate: None,
|
||||
})
|
||||
attributes.attributes().map(Self::from)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -529,6 +516,31 @@ fn accuracy(
|
||||
numerator as f64 / denominator as f64
|
||||
}
|
||||
|
||||
impl From<CatchDifficultyAttributes> for CatchPP<'_> {
|
||||
fn from(attrs: CatchDifficultyAttributes) -> Self {
|
||||
Self {
|
||||
map_or_attrs: MapOrElse::Else(attrs),
|
||||
mods: 0,
|
||||
acc: None,
|
||||
combo: None,
|
||||
|
||||
n_fruits: None,
|
||||
n_droplets: None,
|
||||
n_tiny_droplets: None,
|
||||
n_tiny_droplet_misses: None,
|
||||
n_misses: None,
|
||||
passed_objects: None,
|
||||
clock_rate: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CatchPerformanceAttributes> for CatchPP<'_> {
|
||||
fn from(attrs: CatchPerformanceAttributes) -> Self {
|
||||
attrs.difficulty.into()
|
||||
}
|
||||
}
|
||||
|
||||
/// Abstract type to provide flexibility when passing difficulty attributes to a performance calculation.
|
||||
pub trait CatchAttributeProvider {
|
||||
/// Provide the actual difficulty attributes.
|
||||
|
||||
Reference in New Issue
Block a user