osu: clean up of feature based functions

This commit is contained in:
MaxOhn
2021-11-03 18:10:49 +01:00
parent 528f1b2a7e
commit 3f8d023e71
4 changed files with 15 additions and 42 deletions
+1 -2
View File
@@ -256,8 +256,7 @@ impl<'m> FruitsPP<'m> {
} }
} }
/// Returns an object which contains the pp and [`DifficultyAttributes`](crate::fruits::DifficultyAttributes) /// Calculate all performance related values, including pp and stars.
/// containing stars and other attributes.
pub fn calculate(mut self) -> PerformanceAttributes { pub fn calculate(mut self) -> PerformanceAttributes {
let attributes = self let attributes = self
.attributes .attributes
+1 -1
View File
@@ -89,7 +89,7 @@ impl<'m> ManiaPP<'m> {
self self
} }
/// Returns an object which contains the pp and stars. /// Calculate all performance related values, including pp and stars.
pub fn calculate(self) -> PerformanceAttributes { pub fn calculate(self) -> PerformanceAttributes {
let stars = self let stars = self
.stars .stars
+12 -38
View File
@@ -1,6 +1,15 @@
use super::{DifficultyAttributes, PerformanceAttributes}; use super::{DifficultyAttributes, PerformanceAttributes};
use crate::{Beatmap, Mods, PpResult, StarResult}; use crate::{Beatmap, Mods, PpResult, StarResult};
#[cfg(feature = "no_sliders_no_leniency")]
use super::no_sliders_no_leniency::stars;
#[cfg(feature = "no_leniency")]
use super::no_leniency::stars;
#[cfg(feature = "all_included")]
use super::all_included::stars;
/// Calculator for pp on osu!standard maps. /// Calculator for pp on osu!standard maps.
/// ///
/// # Example /// # Example
@@ -277,47 +286,12 @@ impl<'m> OsuPP<'m> {
} }
} }
/// Returns an object which contains the pp and [`DifficultyAttributes`](crate::osu::DifficultyAttributes) /// Calculate all performance related values, including pp and stars.
/// containing stars and other attributes. pub fn calculate(mut self) -> PerformanceAttributes {
#[cfg(feature = "no_leniency")]
pub fn calculate(self) -> PerformanceAttributes {
self.calculate_with_func(super::no_leniency::stars)
}
/// Returns an object which contains the pp and [`DifficultyAttributes`](crate::osu::DifficultyAttributes)
/// containing stars and other attributes.
#[cfg(feature = "no_sliders_no_leniency")]
pub fn calculate(self) -> PerformanceAttributes {
self.calculate_with_func(super::no_sliders_no_leniency::stars)
}
/// Returns an object which contains the pp and [`DifficultyAttributes`](crate::osu::DifficultyAttributes)
/// containing stars and other attributes.
#[cfg(feature = "all_included")]
pub fn calculate(self) -> PerformanceAttributes {
self.calculate_with_func(super::all_included::stars)
}
// TODO: import `stars` function based on features
// Omits an unnecessary error when enabled features are invalid
#[cfg(not(any(
feature = "no_leniency",
feature = "no_sliders_no_leniency",
feature = "all_included"
)))]
pub(crate) fn calculate(self) -> PerformanceAttributes {
unreachable!()
}
fn calculate_with_func(
mut self,
stars_func: impl FnOnce(&Beatmap, u32, Option<usize>) -> DifficultyAttributes,
) -> PerformanceAttributes {
let attributes = self let attributes = self
.attributes .attributes
.take() .take()
.unwrap_or_else(|| stars_func(self.map, self.mods, self.passed_objects)); .unwrap_or_else(|| stars(self.map, self.mods, self.passed_objects));
self.assert_hitresults(attributes).calculate() self.assert_hitresults(attributes).calculate()
} }
+1 -1
View File
@@ -135,7 +135,7 @@ impl<'m> TaikoPP<'m> {
self self
} }
/// Returns an object which contains the pp and stars. /// Calculate all performance related values, including pp and stars.
pub fn calculate(mut self) -> PerformanceAttributes { pub fn calculate(mut self) -> PerformanceAttributes {
let stars = self let stars = self
.stars .stars