restructure Difficulty and ModeDifficulty
This commit is contained in:
@@ -8,7 +8,7 @@ use crate::{
|
||||
OsuBeatmap,
|
||||
},
|
||||
util::mods::Mods,
|
||||
ModeDifficulty,
|
||||
Difficulty,
|
||||
};
|
||||
|
||||
use self::osu_objects::OsuObjects;
|
||||
@@ -31,14 +31,14 @@ use super::{
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use rosu_pp::{Beatmap, ModeDifficulty};
|
||||
/// use rosu_pp::{Beatmap, Difficulty};
|
||||
/// use rosu_pp::osu::{Osu, OsuGradualDifficulty};
|
||||
///
|
||||
/// let converted = Beatmap::from_path("./resources/2785319.osu")
|
||||
/// .unwrap()
|
||||
/// .unchecked_into_converted::<Osu>();
|
||||
///
|
||||
/// let difficulty = ModeDifficulty::new().mods(64); // DT
|
||||
/// let difficulty = Difficulty::new().mods(64); // DT
|
||||
/// let mut iter = OsuGradualDifficulty::new(&difficulty, &converted);
|
||||
///
|
||||
/// // the difficulty of the map after the first hit object
|
||||
@@ -73,7 +73,7 @@ struct NotClonable;
|
||||
|
||||
impl OsuGradualDifficulty {
|
||||
/// Create a new difficulty attributes iterator for osu!standard maps.
|
||||
pub fn new(difficulty: &ModeDifficulty, converted: &OsuBeatmap<'_>) -> Self {
|
||||
pub fn new(difficulty: &Difficulty, converted: &OsuBeatmap<'_>) -> Self {
|
||||
let mods = difficulty.get_mods();
|
||||
let clock_rate = difficulty.get_clock_rate();
|
||||
|
||||
@@ -262,7 +262,7 @@ mod osu_objects {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use crate::{osu::Osu, Beatmap};
|
||||
use crate::{any::difficulty::converted::ConvertedDifficulty, osu::Osu, Beatmap};
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -272,7 +272,7 @@ mod tests {
|
||||
.unwrap()
|
||||
.unchecked_into_converted::<Osu>();
|
||||
|
||||
let difficulty = ModeDifficulty::new();
|
||||
let difficulty = Difficulty::new();
|
||||
let mut gradual = OsuGradualDifficulty::new(&difficulty, &converted);
|
||||
|
||||
assert!(gradual.next().is_none());
|
||||
@@ -284,7 +284,7 @@ mod tests {
|
||||
.unwrap()
|
||||
.unchecked_into_converted::<Osu>();
|
||||
|
||||
let difficulty = ModeDifficulty::new();
|
||||
let difficulty = Difficulty::new();
|
||||
|
||||
let mut gradual = OsuGradualDifficulty::new(&difficulty, &converted);
|
||||
let mut gradual_2nd = OsuGradualDifficulty::new(&difficulty, &converted);
|
||||
@@ -310,7 +310,7 @@ mod tests {
|
||||
assert_eq!(next_gradual, next_gradual_3rd);
|
||||
}
|
||||
|
||||
let expected = ModeDifficulty::new()
|
||||
let expected = ConvertedDifficulty::new()
|
||||
.passed_objects(i as u32)
|
||||
.calculate(&converted);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::{cmp, pin::Pin};
|
||||
|
||||
use crate::{
|
||||
any::difficulty::{mode::ModeDifficulty, skills::Skill},
|
||||
any::difficulty::{skills::Skill, Difficulty},
|
||||
model::beatmap::BeatmapAttributes,
|
||||
osu::{
|
||||
convert::convert_objects,
|
||||
@@ -26,10 +26,7 @@ const DIFFICULTY_MULTIPLIER: f64 = 0.0675;
|
||||
const HD_FADE_IN_DURATION_MULTIPLIER: f64 = 0.4;
|
||||
const HD_FADE_OUT_DURATION_MULTIPLIER: f64 = 0.3;
|
||||
|
||||
pub fn difficulty(
|
||||
difficulty: &ModeDifficulty,
|
||||
converted: &OsuBeatmap<'_>,
|
||||
) -> OsuDifficultyAttributes {
|
||||
pub fn difficulty(difficulty: &Difficulty, converted: &OsuBeatmap<'_>) -> OsuDifficultyAttributes {
|
||||
let DifficultyValues {
|
||||
skills:
|
||||
OsuSkills {
|
||||
@@ -70,7 +67,7 @@ pub struct OsuDifficultySetup {
|
||||
}
|
||||
|
||||
impl OsuDifficultySetup {
|
||||
pub fn new(difficulty: &ModeDifficulty, converted: &OsuBeatmap) -> Self {
|
||||
pub fn new(difficulty: &Difficulty, converted: &OsuBeatmap) -> Self {
|
||||
let mods = difficulty.get_mods();
|
||||
let clock_rate = difficulty.get_clock_rate();
|
||||
|
||||
@@ -106,7 +103,7 @@ pub struct DifficultyValues {
|
||||
}
|
||||
|
||||
impl DifficultyValues {
|
||||
pub fn calculate(difficulty: &ModeDifficulty, converted: &OsuBeatmap<'_>) -> Self {
|
||||
pub fn calculate(difficulty: &Difficulty, converted: &OsuBeatmap<'_>) -> Self {
|
||||
let mods = difficulty.get_mods();
|
||||
let take = difficulty.get_passed_objects();
|
||||
|
||||
@@ -218,7 +215,7 @@ impl DifficultyValues {
|
||||
}
|
||||
|
||||
pub fn create_difficulty_objects<'a>(
|
||||
difficulty: &ModeDifficulty,
|
||||
difficulty: &Difficulty,
|
||||
scaling_factor: &ScalingFactor,
|
||||
osu_objects: impl ExactSizeIterator<Item = Pin<&'a mut OsuObject>>,
|
||||
) -> Vec<OsuDifficultyObject<'a>> {
|
||||
|
||||
+5
-5
@@ -1,11 +1,11 @@
|
||||
use rosu_map::util::Pos;
|
||||
|
||||
use crate::{
|
||||
any::ModeDifficulty,
|
||||
model::{
|
||||
beatmap::Beatmap,
|
||||
mode::{ConvertStatus, IGameMode},
|
||||
},
|
||||
Difficulty,
|
||||
};
|
||||
|
||||
pub use self::{
|
||||
@@ -48,13 +48,13 @@ impl IGameMode for Osu {
|
||||
}
|
||||
|
||||
fn difficulty(
|
||||
difficulty: &ModeDifficulty,
|
||||
difficulty: &Difficulty,
|
||||
converted: &OsuBeatmap<'_>,
|
||||
) -> Self::DifficultyAttributes {
|
||||
difficulty::difficulty(difficulty, converted)
|
||||
}
|
||||
|
||||
fn strains(difficulty: &ModeDifficulty, converted: &OsuBeatmap<'_>) -> Self::Strains {
|
||||
fn strains(difficulty: &Difficulty, converted: &OsuBeatmap<'_>) -> Self::Strains {
|
||||
strains::strains(difficulty, converted)
|
||||
}
|
||||
|
||||
@@ -63,14 +63,14 @@ impl IGameMode for Osu {
|
||||
}
|
||||
|
||||
fn gradual_difficulty(
|
||||
difficulty: &ModeDifficulty,
|
||||
difficulty: &Difficulty,
|
||||
map: &OsuBeatmap<'_>,
|
||||
) -> Self::GradualDifficulty {
|
||||
OsuGradualDifficulty::new(difficulty, map)
|
||||
}
|
||||
|
||||
fn gradual_performance(
|
||||
difficulty: &ModeDifficulty,
|
||||
difficulty: &Difficulty,
|
||||
map: &OsuBeatmap<'_>,
|
||||
) -> Self::GradualPerformance {
|
||||
OsuGradualPerformance::new(difficulty, map)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
osu::{OsuBeatmap, OsuGradualDifficulty},
|
||||
ModeDifficulty,
|
||||
Difficulty,
|
||||
};
|
||||
|
||||
use super::{OsuPerformanceAttributes, OsuScoreState};
|
||||
@@ -20,14 +20,14 @@ use super::{OsuPerformanceAttributes, OsuScoreState};
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use rosu_pp::{Beatmap, ModeDifficulty};
|
||||
/// use rosu_pp::{Beatmap, Difficulty};
|
||||
/// use rosu_pp::osu::{Osu, OsuGradualPerformance, OsuScoreState};
|
||||
///
|
||||
/// let converted = Beatmap::from_path("./resources/2785319.osu")
|
||||
/// .unwrap()
|
||||
/// .unchecked_into_converted::<Osu>();
|
||||
///
|
||||
/// let difficulty = ModeDifficulty::new().mods(64); // DT
|
||||
/// let difficulty = Difficulty::new().mods(64); // DT
|
||||
/// let mut gradual = OsuGradualPerformance::new(&difficulty, &converted);
|
||||
/// let mut state = OsuScoreState::new(); // empty state, everything is on 0.
|
||||
///
|
||||
@@ -85,7 +85,7 @@ pub struct OsuGradualPerformance {
|
||||
|
||||
impl OsuGradualPerformance {
|
||||
/// Create a new gradual performance calculator for osu!standard maps.
|
||||
pub fn new(difficulty: &ModeDifficulty, converted: &OsuBeatmap<'_>) -> Self {
|
||||
pub fn new(difficulty: &Difficulty, converted: &OsuBeatmap<'_>) -> Self {
|
||||
let difficulty = OsuGradualDifficulty::new(difficulty, converted);
|
||||
|
||||
Self { difficulty }
|
||||
@@ -139,7 +139,7 @@ mod tests {
|
||||
.unchecked_into_converted::<Osu>();
|
||||
|
||||
let mods = 88; // HDHRDT
|
||||
let difficulty = ModeDifficulty::new().mods(88);
|
||||
let difficulty = Difficulty::new().mods(88);
|
||||
|
||||
let mut gradual = OsuGradualPerformance::new(&difficulty, &converted);
|
||||
let mut gradual_2nd = OsuGradualPerformance::new(&difficulty, &converted);
|
||||
|
||||
@@ -3,8 +3,7 @@ use std::cmp;
|
||||
use rosu_map::section::general::GameMode;
|
||||
|
||||
use crate::{
|
||||
any::ModeDifficulty,
|
||||
any::{HitResultPriority, ModeAttributeProvider, Performance},
|
||||
any::{Difficulty, HitResultPriority, ModeAttributeProvider, Performance},
|
||||
catch::CatchPerformance,
|
||||
mania::ManiaPerformance,
|
||||
taiko::TaikoPerformance,
|
||||
@@ -25,7 +24,7 @@ pub mod gradual;
|
||||
#[must_use]
|
||||
pub struct OsuPerformance<'map> {
|
||||
pub(crate) map_or_attrs: MapOrAttrs<'map, Osu>,
|
||||
pub(crate) difficulty: ModeDifficulty,
|
||||
pub(crate) difficulty: Difficulty,
|
||||
pub(crate) acc: Option<f64>,
|
||||
pub(crate) combo: Option<u32>,
|
||||
pub(crate) n300: Option<u32>,
|
||||
@@ -40,7 +39,7 @@ impl<'map> OsuPerformance<'map> {
|
||||
pub const fn new(map: OsuBeatmap<'map>) -> Self {
|
||||
Self {
|
||||
map_or_attrs: MapOrAttrs::Map(map),
|
||||
difficulty: ModeDifficulty::new(),
|
||||
difficulty: Difficulty::new(),
|
||||
acc: None,
|
||||
combo: None,
|
||||
n300: None,
|
||||
@@ -54,7 +53,7 @@ impl<'map> OsuPerformance<'map> {
|
||||
pub(crate) const fn from_osu_attributes(attrs: OsuDifficultyAttributes) -> Self {
|
||||
Self {
|
||||
map_or_attrs: MapOrAttrs::Attrs(attrs),
|
||||
difficulty: ModeDifficulty::new(),
|
||||
difficulty: Difficulty::new(),
|
||||
acc: None,
|
||||
combo: None,
|
||||
n300: None,
|
||||
@@ -233,7 +232,7 @@ impl<'map> OsuPerformance<'map> {
|
||||
pub fn generate_state(&mut self) -> OsuScoreState {
|
||||
let attrs = match self.map_or_attrs {
|
||||
MapOrAttrs::Map(ref map) => {
|
||||
let attrs = self.generate_attributes(map);
|
||||
let attrs = self.difficulty.with_mode().calculate(map);
|
||||
|
||||
self.map_or_attrs.insert_attrs(attrs)
|
||||
}
|
||||
@@ -417,7 +416,7 @@ impl<'map> OsuPerformance<'map> {
|
||||
let state = self.generate_state();
|
||||
|
||||
let attrs = match self.map_or_attrs {
|
||||
MapOrAttrs::Map(ref map) => self.generate_attributes(map),
|
||||
MapOrAttrs::Map(ref map) => self.difficulty.with_mode().calculate(map),
|
||||
MapOrAttrs::Attrs(attrs) => attrs,
|
||||
};
|
||||
|
||||
@@ -434,10 +433,6 @@ impl<'map> OsuPerformance<'map> {
|
||||
inner.calculate()
|
||||
}
|
||||
|
||||
fn generate_attributes(&self, map: &OsuBeatmap<'_>) -> OsuDifficultyAttributes {
|
||||
self.difficulty.calculate(map)
|
||||
}
|
||||
|
||||
/// Try to create [`OsuPerformance`] through a [`ModeAttributeProvider`].
|
||||
///
|
||||
/// If you already calculated the attributes for the current map-mod
|
||||
@@ -828,7 +823,7 @@ mod test {
|
||||
|
||||
use proptest::prelude::*;
|
||||
|
||||
use crate::Beatmap;
|
||||
use crate::{any::difficulty::converted::ConvertedDifficulty, Beatmap};
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -843,7 +838,7 @@ mod test {
|
||||
.unwrap()
|
||||
.unchecked_into_converted::<Osu>();
|
||||
|
||||
let attrs = ModeDifficulty::new().calculate(&converted);
|
||||
let attrs = ConvertedDifficulty::new().calculate(&converted);
|
||||
|
||||
assert_eq!(
|
||||
(attrs.n_circles, attrs.n_sliders, attrs.n_spinners),
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
use crate::any::ModeDifficulty;
|
||||
use crate::Difficulty;
|
||||
|
||||
use super::{
|
||||
convert::OsuBeatmap,
|
||||
@@ -25,7 +25,7 @@ impl OsuStrains {
|
||||
pub const SECTION_LEN: f64 = 400.0;
|
||||
}
|
||||
|
||||
pub fn strains(difficulty: &ModeDifficulty, converted: &OsuBeatmap<'_>) -> OsuStrains {
|
||||
pub fn strains(difficulty: &Difficulty, converted: &OsuBeatmap<'_>) -> OsuStrains {
|
||||
let DifficultyValues {
|
||||
skills:
|
||||
OsuSkills {
|
||||
|
||||
Reference in New Issue
Block a user