moved BeatmapExt into beatmap module

This commit is contained in:
MaxOhn
2023-01-27 12:50:15 +01:00
parent 28bcf107f1
commit 3b8a5f987d
3 changed files with 95 additions and 88 deletions
+92
View File
@@ -0,0 +1,92 @@
use crate::{
AnyPP, AnyStars, Beatmap, CatchPP, CatchStars, GameMode, GradualDifficultyAttributes,
GradualPerformanceAttributes, ManiaPP, ManiaStars, OsuPP, OsuStars, PerformanceAttributes,
Strains, TaikoPP, TaikoStars,
};
/// Provides some additional methods on [`Beatmap`].
pub trait BeatmapExt {
/// Calculate the stars and other attributes of a beatmap which are required for pp calculation.
fn stars(&self) -> AnyStars<'_>;
/// Calculate the max pp of a beatmap.
///
/// If you seek more fine-tuning you can use the [`pp`](BeatmapExt::pp) method.
fn max_pp(&self, mods: u32) -> PerformanceAttributes;
/// Returns a builder for performance calculation.
///
/// Convenient method that matches on the map's mode to choose the appropriate calculator.
fn pp(&self) -> AnyPP<'_>;
/// Calculate the strains of a map.
/// This essentially performs the same calculation as [`BeatmapExt::stars`] but
/// instead of evaluating the final strains, they are just returned as is.
///
/// Suitable to plot the difficulty of a map over time.
fn strains(&self, mods: u32) -> Strains;
/// Return an iterator that gives you the [`DifficultyAttributes`] after each hit object.
///
/// Suitable to efficiently get the map's star rating after multiple different locations.
fn gradual_difficulty(&self, mods: u32) -> GradualDifficultyAttributes<'_>;
/// Return a struct that gives you the [`PerformanceAttributes`] after every (few) hit object(s).
///
/// Suitable to efficiently get a score's performance after multiple different locations,
/// i.e. live update a score's pp.
fn gradual_performance(&self, mods: u32) -> GradualPerformanceAttributes<'_>;
}
impl BeatmapExt for Beatmap {
#[inline]
fn stars(&self) -> AnyStars<'_> {
match self.mode {
GameMode::Osu => AnyStars::Osu(OsuStars::new(self)),
GameMode::Taiko => AnyStars::Taiko(TaikoStars::new(self)),
GameMode::Catch => AnyStars::Catch(CatchStars::new(self)),
GameMode::Mania => AnyStars::Mania(ManiaStars::new(self)),
}
}
#[inline]
fn max_pp(&self, mods: u32) -> PerformanceAttributes {
match self.mode {
GameMode::Osu => PerformanceAttributes::Osu(OsuPP::new(self).mods(mods).calculate()),
GameMode::Taiko => {
PerformanceAttributes::Taiko(TaikoPP::new(self).mods(mods).calculate())
}
GameMode::Catch => {
PerformanceAttributes::Catch(CatchPP::new(self).mods(mods).calculate())
}
GameMode::Mania => {
PerformanceAttributes::Mania(ManiaPP::new(self).mods(mods).calculate())
}
}
}
#[inline]
fn pp(&self) -> AnyPP<'_> {
AnyPP::new(self)
}
#[inline]
fn strains(&self, mods: u32) -> Strains {
match self.mode {
GameMode::Osu => Strains::Osu(OsuStars::new(self).mods(mods).strains()),
GameMode::Taiko => Strains::Taiko(TaikoStars::new(self).mods(mods).strains()),
GameMode::Catch => Strains::Catch(CatchStars::new(self).mods(mods).strains()),
GameMode::Mania => Strains::Mania(ManiaStars::new(self).mods(mods).strains()),
}
}
#[inline]
fn gradual_difficulty(&self, mods: u32) -> GradualDifficultyAttributes<'_> {
GradualDifficultyAttributes::new(self, mods)
}
#[inline]
fn gradual_performance(&self, mods: u32) -> GradualPerformanceAttributes<'_> {
GradualPerformanceAttributes::new(self, mods)
}
}
+2
View File
@@ -6,6 +6,7 @@ pub use self::{
attributes::{BeatmapAttributes, BeatmapAttributesBuilder, BeatmapHitWindows},
breaks::Break,
control_points::{DifficultyPoint, EffectPoint, TimingPoint},
ext::*,
mode::GameMode,
};
@@ -13,6 +14,7 @@ mod attributes;
mod breaks;
mod control_points;
mod converts;
mod ext;
mod mode;
/// The main beatmap struct containing all data relevant
+1 -88
View File
@@ -196,7 +196,7 @@ pub mod parse;
/// Beatmap and contained types
pub mod beatmap;
pub use beatmap::{Beatmap, GameMode};
pub use beatmap::{Beatmap, BeatmapExt, GameMode};
mod gradual;
pub use gradual::{GradualDifficultyAttributes, GradualPerformanceAttributes, ScoreState};
@@ -220,93 +220,6 @@ pub use mods::Mods;
pub use parse::{ParseError, ParseResult};
pub use util::SortedVec;
/// Provides some additional methods on [`Beatmap`].
pub trait BeatmapExt {
/// Calculate the stars and other attributes of a beatmap which are required for pp calculation.
fn stars(&self) -> AnyStars<'_>;
/// Calculate the max pp of a beatmap.
///
/// If you seek more fine-tuning you can use the [`pp`](BeatmapExt::pp) method.
fn max_pp(&self, mods: u32) -> PerformanceAttributes;
/// Returns a builder for performance calculation.
///
/// Convenient method that matches on the map's mode to choose the appropriate calculator.
fn pp(&self) -> AnyPP<'_>;
/// Calculate the strains of a map.
/// This essentially performs the same calculation as [`BeatmapExt::stars`] but
/// instead of evaluating the final strains, they are just returned as is.
///
/// Suitable to plot the difficulty of a map over time.
fn strains(&self, mods: u32) -> Strains;
/// Return an iterator that gives you the [`DifficultyAttributes`] after each hit object.
///
/// Suitable to efficiently get the map's star rating after multiple different locations.
fn gradual_difficulty(&self, mods: u32) -> GradualDifficultyAttributes<'_>;
/// Return a struct that gives you the [`PerformanceAttributes`] after every (few) hit object(s).
///
/// Suitable to efficiently get a score's performance after multiple different locations,
/// i.e. live update a score's pp.
fn gradual_performance(&self, mods: u32) -> GradualPerformanceAttributes<'_>;
}
impl BeatmapExt for Beatmap {
#[inline]
fn stars(&self) -> AnyStars<'_> {
match self.mode {
GameMode::Osu => AnyStars::Osu(OsuStars::new(self)),
GameMode::Taiko => AnyStars::Taiko(TaikoStars::new(self)),
GameMode::Catch => AnyStars::Catch(CatchStars::new(self)),
GameMode::Mania => AnyStars::Mania(ManiaStars::new(self)),
}
}
#[inline]
fn max_pp(&self, mods: u32) -> PerformanceAttributes {
match self.mode {
GameMode::Osu => PerformanceAttributes::Osu(OsuPP::new(self).mods(mods).calculate()),
GameMode::Taiko => {
PerformanceAttributes::Taiko(TaikoPP::new(self).mods(mods).calculate())
}
GameMode::Catch => {
PerformanceAttributes::Catch(CatchPP::new(self).mods(mods).calculate())
}
GameMode::Mania => {
PerformanceAttributes::Mania(ManiaPP::new(self).mods(mods).calculate())
}
}
}
#[inline]
fn pp(&self) -> AnyPP<'_> {
AnyPP::new(self)
}
#[inline]
fn strains(&self, mods: u32) -> Strains {
match self.mode {
GameMode::Osu => Strains::Osu(OsuStars::new(self).mods(mods).strains()),
GameMode::Taiko => Strains::Taiko(TaikoStars::new(self).mods(mods).strains()),
GameMode::Catch => Strains::Catch(CatchStars::new(self).mods(mods).strains()),
GameMode::Mania => Strains::Mania(ManiaStars::new(self).mods(mods).strains()),
}
}
#[inline]
fn gradual_difficulty(&self, mods: u32) -> GradualDifficultyAttributes<'_> {
GradualDifficultyAttributes::new(self, mods)
}
#[inline]
fn gradual_performance(&self, mods: u32) -> GradualPerformanceAttributes<'_> {
GradualPerformanceAttributes::new(self, mods)
}
}
/// The result of calculating the strains on a map.
/// Suitable to plot the difficulty of a map over time.
#[derive(Clone, Debug)]