feat: added convenience methods

This commit is contained in:
MaxOhn
2023-12-29 11:31:35 +01:00
parent f2854dbde5
commit f3c39c7891
10 changed files with 164 additions and 57 deletions
+6
View File
@@ -262,6 +262,12 @@ impl ManiaDifficultyAttributes {
pub fn is_convert(&self) -> bool {
self.is_convert
}
/// Returns a builder for performance calculation.
#[inline]
pub fn pp(self) -> ManiaPP<'static> {
ManiaPP::from(self)
}
}
/// The result of a performance calculation on an osu!mania map.
+27 -15
View File
@@ -803,21 +803,7 @@ impl<'map> ManiaPP<'map> {
/// attributes for mania e.g. if it's [`DifficultyAttributes::Taiko`].
#[inline]
pub fn try_from_attributes(attributes: impl ManiaAttributeProvider) -> Option<Self> {
attributes.attributes().map(|attrs| Self {
map_or_attrs: MapOrElse::Else(attrs),
is_convert_overwrite: None,
mods: 0,
passed_objects: None,
clock_rate: None,
n320: None,
n300: None,
n200: None,
n100: None,
n50: None,
n_misses: None,
acc: None,
hitresult_priority: None,
})
attributes.attributes().map(Self::from)
}
}
@@ -913,6 +899,32 @@ fn accuracy(
numerator as f64 / denominator as f64
}
impl From<ManiaDifficultyAttributes> for ManiaPP<'_> {
fn from(attrs: ManiaDifficultyAttributes) -> Self {
Self {
map_or_attrs: MapOrElse::Else(attrs),
is_convert_overwrite: None,
mods: 0,
passed_objects: None,
clock_rate: None,
n320: None,
n300: None,
n200: None,
n100: None,
n50: None,
n_misses: None,
acc: None,
hitresult_priority: None,
}
}
}
impl From<ManiaPerformanceAttributes> for ManiaPP<'_> {
fn from(attrs: ManiaPerformanceAttributes) -> Self {
attrs.difficulty.into()
}
}
/// Abstract type to provide flexibility when passing difficulty attributes to a performance calculation.
pub trait ManiaAttributeProvider {
/// Provide the actual difficulty attributes.