restructure Difficulty and ModeDifficulty

This commit is contained in:
MaxOhn
2024-03-03 09:57:44 +01:00
parent 3705338d12
commit e749a791fc
39 changed files with 446 additions and 448 deletions
+8 -8
View File
@@ -5,7 +5,7 @@ use crate::{
mania::{object::ObjectParams, ManiaBeatmap},
model::{beatmap::HitWindows, hit_object::HitObject},
util::float_ext::FloatExt,
ModeDifficulty,
Difficulty,
};
use super::{
@@ -25,14 +25,14 @@ use super::{
/// # Example
///
/// ```
/// use rosu_pp::{Beatmap, ModeDifficulty};
/// use rosu_pp::{Beatmap, Difficulty};
/// use rosu_pp::mania::ManiaGradualDifficulty;
///
/// let converted = Beatmap::from_path("./resources/1638954.osu")
/// .unwrap()
/// .unchecked_into_converted();
///
/// let difficulty = ModeDifficulty::new().mods(64); // DT
/// let difficulty = Difficulty::new().mods(64); // DT
/// let mut iter = ManiaGradualDifficulty::new(&difficulty, &converted);
///
/// // the difficulty of the map after the first hit object
@@ -61,7 +61,7 @@ pub struct ManiaGradualDifficulty {
impl ManiaGradualDifficulty {
/// Create a new difficulty attributes iterator for osu!mania maps.
pub fn new(difficulty: &ModeDifficulty, converted: &ManiaBeatmap<'_>) -> Self {
pub fn new(difficulty: &Difficulty, converted: &ManiaBeatmap<'_>) -> Self {
let take = difficulty.get_passed_objects();
let mods = difficulty.get_mods();
let total_columns = converted.cs.round_even().max(1.0);
@@ -209,7 +209,7 @@ fn increment_combo_raw(is_circle: bool, start_time: f64, end_time: f64, curr_com
#[cfg(test)]
mod tests {
use crate::{mania::Mania, Beatmap};
use crate::{any::difficulty::converted::ConvertedDifficulty, mania::Mania, Beatmap};
use super::*;
@@ -219,7 +219,7 @@ mod tests {
.unwrap()
.unchecked_into_converted::<Mania>();
let difficulty = ModeDifficulty::new();
let difficulty = Difficulty::new();
let mut gradual = ManiaGradualDifficulty::new(&difficulty, &converted);
assert!(gradual.next().is_none());
@@ -231,7 +231,7 @@ mod tests {
.unwrap()
.unchecked_into_converted::<Mania>();
let difficulty = ModeDifficulty::new();
let difficulty = Difficulty::new();
let mut gradual = ManiaGradualDifficulty::new(&difficulty, &converted);
let mut gradual_2nd = ManiaGradualDifficulty::new(&difficulty, &converted);
@@ -257,7 +257,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);
+3 -3
View File
@@ -1,7 +1,7 @@
use std::cmp;
use crate::{
any::difficulty::{mode::ModeDifficulty, skills::Skill},
any::difficulty::{skills::Skill, Difficulty},
mania::{
difficulty::{object::ManiaDifficultyObject, skills::strain::Strain},
object::{ManiaObject, ObjectParams},
@@ -18,7 +18,7 @@ mod skills;
const STAR_SCALING_FACTOR: f64 = 0.018;
pub fn difficulty(
difficulty: &ModeDifficulty,
difficulty: &Difficulty,
converted: &ManiaBeatmap<'_>,
) -> ManiaDifficultyAttributes {
let n_objects = cmp::min(difficulty.get_passed_objects(), converted.hit_objects.len()) as u32;
@@ -47,7 +47,7 @@ pub struct DifficultyValues {
}
impl DifficultyValues {
pub fn calculate(difficulty: &ModeDifficulty, converted: &ManiaBeatmap<'_>) -> Self {
pub fn calculate(difficulty: &Difficulty, converted: &ManiaBeatmap<'_>) -> Self {
let take = difficulty.get_passed_objects();
let total_columns = converted.cs.round_even().max(1.0);
let clock_rate = difficulty.get_clock_rate();
+5 -5
View File
@@ -1,9 +1,9 @@
use crate::{
any::ModeDifficulty,
model::{
beatmap::Beatmap,
mode::{ConvertStatus, IGameMode},
},
Difficulty,
};
pub use self::{
@@ -44,13 +44,13 @@ impl IGameMode for Mania {
}
fn difficulty(
difficulty: &ModeDifficulty,
difficulty: &Difficulty,
converted: &ManiaBeatmap<'_>,
) -> Self::DifficultyAttributes {
difficulty::difficulty(difficulty, converted)
}
fn strains(difficulty: &ModeDifficulty, converted: &ManiaBeatmap<'_>) -> Self::Strains {
fn strains(difficulty: &Difficulty, converted: &ManiaBeatmap<'_>) -> Self::Strains {
strains::strains(difficulty, converted)
}
@@ -59,14 +59,14 @@ impl IGameMode for Mania {
}
fn gradual_difficulty(
difficulty: &ModeDifficulty,
difficulty: &Difficulty,
map: &ManiaBeatmap<'_>,
) -> Self::GradualDifficulty {
ManiaGradualDifficulty::new(difficulty, map)
}
fn gradual_performance(
difficulty: &ModeDifficulty,
difficulty: &Difficulty,
map: &ManiaBeatmap<'_>,
) -> Self::GradualPerformance {
ManiaGradualPerformance::new(difficulty, map)
+5 -5
View File
@@ -1,6 +1,6 @@
use crate::{
mania::{ManiaBeatmap, ManiaGradualDifficulty},
ModeDifficulty,
Difficulty,
};
use super::{ManiaPerformanceAttributes, ManiaScoreState};
@@ -20,14 +20,14 @@ use super::{ManiaPerformanceAttributes, ManiaScoreState};
/// # Example
///
/// ```
/// use rosu_pp::{Beatmap, ModeDifficulty};
/// use rosu_pp::{Beatmap, Difficulty};
/// use rosu_pp::mania::{Mania, ManiaGradualPerformance, ManiaScoreState};
///
/// let converted = Beatmap::from_path("./resources/1638954.osu")
/// .unwrap()
/// .unchecked_into_converted::<Mania>();
///
/// let difficulty = ModeDifficulty::new().mods(64); // DT
/// let difficulty = Difficulty::new().mods(64); // DT
/// let mut gradual = ManiaGradualPerformance::new(&difficulty, &converted);
/// let mut state = ManiaScoreState::new(); // empty state, everything is on 0.
///
@@ -75,7 +75,7 @@ pub struct ManiaGradualPerformance {
impl ManiaGradualPerformance {
/// Create a new gradual performance calculator for osu!mania maps.
pub fn new(difficulty: &ModeDifficulty, converted: &ManiaBeatmap<'_>) -> Self {
pub fn new(difficulty: &Difficulty, converted: &ManiaBeatmap<'_>) -> Self {
let difficulty = ManiaGradualDifficulty::new(difficulty, converted);
Self { difficulty }
@@ -129,7 +129,7 @@ mod tests {
.unchecked_into_converted::<Mania>();
let mods = 88; // HDHRDT
let difficulty = ModeDifficulty::new().mods(88);
let difficulty = Difficulty::new().mods(88);
let mut gradual = ManiaGradualPerformance::new(&difficulty, &converted);
let mut gradual_2nd = ManiaGradualPerformance::new(&difficulty, &converted);
+8 -13
View File
@@ -1,8 +1,7 @@
use std::cmp;
use crate::{
any::ModeDifficulty,
any::{HitResultPriority, ModeAttributeProvider},
any::{Difficulty, HitResultPriority, ModeAttributeProvider},
osu::OsuPerformance,
util::{map_or_attrs::MapOrAttrs, mods::Mods},
};
@@ -21,7 +20,7 @@ pub mod gradual;
#[must_use]
pub struct ManiaPerformance<'map> {
map_or_attrs: MapOrAttrs<'map, Mania>,
difficulty: ModeDifficulty,
difficulty: Difficulty,
n320: Option<u32>,
n300: Option<u32>,
n200: Option<u32>,
@@ -37,7 +36,7 @@ impl<'map> ManiaPerformance<'map> {
pub const fn new(map: ManiaBeatmap<'map>) -> Self {
Self {
map_or_attrs: MapOrAttrs::Map(map),
difficulty: ModeDifficulty::new(),
difficulty: Difficulty::new(),
n320: None,
n300: None,
n200: None,
@@ -52,7 +51,7 @@ impl<'map> ManiaPerformance<'map> {
pub(crate) const fn from_mania_attributes(attrs: ManiaDifficultyAttributes) -> Self {
Self {
map_or_attrs: MapOrAttrs::Attrs(attrs),
difficulty: ModeDifficulty::new(),
difficulty: Difficulty::new(),
n320: None,
n300: None,
n200: None,
@@ -192,7 +191,7 @@ impl<'map> ManiaPerformance<'map> {
pub fn generate_state(&mut self) -> ManiaScoreState {
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)
}
@@ -718,7 +717,7 @@ impl<'map> ManiaPerformance<'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,
};
@@ -731,10 +730,6 @@ impl<'map> ManiaPerformance<'map> {
inner.calculate()
}
fn generate_attributes(&self, map: &ManiaBeatmap<'_>) -> ManiaDifficultyAttributes {
self.difficulty.calculate(map)
}
/// Try to create [`ManiaPerformance`] through a [`ModeAttributeProvider`].
///
/// If you already calculated the attributes for the current map-mod
@@ -921,7 +916,7 @@ mod tests {
use proptest::prelude::*;
use crate::Beatmap;
use crate::{any::difficulty::converted::ConvertedDifficulty, Beatmap};
use super::*;
@@ -936,7 +931,7 @@ mod tests {
.unwrap()
.unchecked_into_converted::<Mania>();
let attrs = ModeDifficulty::new().calculate(&converted);
let attrs = ConvertedDifficulty::new().calculate(&converted);
assert_eq!(N_OBJECTS, converted.hit_objects.len() as u32);
+2 -2
View File
@@ -1,4 +1,4 @@
use crate::{any::ModeDifficulty, mania::difficulty::DifficultyValues};
use crate::{any::Difficulty, mania::difficulty::DifficultyValues};
use super::convert::ManiaBeatmap;
@@ -16,7 +16,7 @@ impl ManiaStrains {
pub const SECTION_LEN: f64 = 400.0;
}
pub fn strains(difficulty: &ModeDifficulty, converted: &ManiaBeatmap<'_>) -> ManiaStrains {
pub fn strains(difficulty: &Difficulty, converted: &ManiaBeatmap<'_>) -> ManiaStrains {
let values = DifficultyValues::calculate(difficulty, converted);
ManiaStrains {