add Strains for any mode
This commit is contained in:
+31
-11
@@ -12,7 +12,7 @@ use crate::{
|
|||||||
|
|
||||||
use self::mode::ModeDifficulty;
|
use self::mode::ModeDifficulty;
|
||||||
|
|
||||||
use super::attributes::DifficultyAttributes;
|
use super::{attributes::DifficultyAttributes, Strains};
|
||||||
|
|
||||||
pub mod gradual;
|
pub mod gradual;
|
||||||
pub mod mode;
|
pub mod mode;
|
||||||
@@ -191,25 +191,45 @@ impl Difficulty<'_> {
|
|||||||
///
|
///
|
||||||
/// The returned attributes depend on the map's mode.
|
/// The returned attributes depend on the map's mode.
|
||||||
pub fn calculate(&self) -> DifficultyAttributes {
|
pub fn calculate(&self) -> DifficultyAttributes {
|
||||||
|
let is_convert = self.is_convert;
|
||||||
let map = Cow::Borrowed(self.map.as_ref());
|
let map = Cow::Borrowed(self.map.as_ref());
|
||||||
|
|
||||||
match self.map.mode {
|
match self.map.mode {
|
||||||
GameMode::Osu => DifficultyAttributes::Osu(
|
GameMode::Osu => {
|
||||||
self.inner
|
DifficultyAttributes::Osu(self.inner.calculate(&OsuBeatmap::new(map, is_convert)))
|
||||||
.calculate(&Converted::<Osu>::new(map, self.is_convert)),
|
}
|
||||||
),
|
|
||||||
GameMode::Taiko => DifficultyAttributes::Taiko(
|
GameMode::Taiko => DifficultyAttributes::Taiko(
|
||||||
self.inner
|
self.inner.calculate(&TaikoBeatmap::new(map, is_convert)),
|
||||||
.calculate(&Converted::<Taiko>::new(map, self.is_convert)),
|
|
||||||
),
|
),
|
||||||
GameMode::Catch => DifficultyAttributes::Catch(
|
GameMode::Catch => DifficultyAttributes::Catch(
|
||||||
self.inner
|
self.inner.calculate(&CatchBeatmap::new(map, is_convert)),
|
||||||
.calculate(&Converted::<Catch>::new(map, self.is_convert)),
|
|
||||||
),
|
),
|
||||||
GameMode::Mania => DifficultyAttributes::Mania(
|
GameMode::Mania => DifficultyAttributes::Mania(
|
||||||
self.inner
|
self.inner.calculate(&ManiaBeatmap::new(map, is_convert)),
|
||||||
.calculate(&Converted::<Mania>::new(map, self.is_convert)),
|
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Perform the difficulty calculation but instead of evaluating the skill
|
||||||
|
/// strains, return them as is.
|
||||||
|
///
|
||||||
|
/// Suitable to plot the difficulty of a map over time.
|
||||||
|
pub fn strains(&self) -> Strains {
|
||||||
|
let map = Cow::Borrowed(self.map.as_ref());
|
||||||
|
|
||||||
|
match self.map.mode {
|
||||||
|
GameMode::Osu => {
|
||||||
|
Strains::Osu(self.inner.strains(&OsuBeatmap::new(map, self.is_convert)))
|
||||||
|
}
|
||||||
|
GameMode::Taiko => {
|
||||||
|
Strains::Taiko(self.inner.strains(&TaikoBeatmap::new(map, self.is_convert)))
|
||||||
|
}
|
||||||
|
GameMode::Catch => {
|
||||||
|
Strains::Catch(self.inner.strains(&CatchBeatmap::new(map, self.is_convert)))
|
||||||
|
}
|
||||||
|
GameMode::Mania => {
|
||||||
|
Strains::Mania(self.inner.strains(&ManiaBeatmap::new(map, self.is_convert)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ pub use self::{
|
|||||||
difficulty::{gradual::GradualDifficulty, mode::ModeDifficulty, Difficulty},
|
difficulty::{gradual::GradualDifficulty, mode::ModeDifficulty, Difficulty},
|
||||||
performance::{gradual::GradualPerformance, HitResultPriority, Performance},
|
performance::{gradual::GradualPerformance, HitResultPriority, Performance},
|
||||||
score_state::ScoreState,
|
score_state::ScoreState,
|
||||||
|
strains::Strains,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod attributes;
|
mod attributes;
|
||||||
pub(crate) mod difficulty;
|
pub(crate) mod difficulty;
|
||||||
mod performance;
|
mod performance;
|
||||||
mod score_state;
|
mod score_state;
|
||||||
|
mod strains;
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
use crate::{catch::CatchStrains, mania::ManiaStrains, osu::OsuStrains, taiko::TaikoStrains};
|
||||||
|
|
||||||
|
/// The result of calculating the strains on a map.
|
||||||
|
///
|
||||||
|
/// Suitable to plot the difficulty of a map over time.
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
pub enum Strains {
|
||||||
|
Osu(OsuStrains),
|
||||||
|
Taiko(TaikoStrains),
|
||||||
|
Catch(CatchStrains),
|
||||||
|
Mania(ManiaStrains),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Strains {
|
||||||
|
/// Time inbetween two strains in ms.
|
||||||
|
pub const fn section_len(&self) -> f64 {
|
||||||
|
match self {
|
||||||
|
Strains::Osu(_) => OsuStrains::SECTION_LEN,
|
||||||
|
Strains::Taiko(_) => TaikoStrains::SECTION_LEN,
|
||||||
|
Strains::Catch(_) => CatchStrains::SECTION_LEN,
|
||||||
|
Strains::Mania(_) => ManiaStrains::SECTION_LEN,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! from_mode_strains {
|
||||||
|
( $mode:ident: $strains:ident ) => {
|
||||||
|
impl From<$strains> for Strains {
|
||||||
|
fn from(strains: $strains) -> Self {
|
||||||
|
Self::$mode(strains)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
from_mode_strains!(Osu: OsuStrains);
|
||||||
|
from_mode_strains!(Taiko: TaikoStrains);
|
||||||
|
from_mode_strains!(Catch: CatchStrains);
|
||||||
|
from_mode_strains!(Mania: ManiaStrains);
|
||||||
Reference in New Issue
Block a user