restructure Difficulty and ModeDifficulty
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use std::{
|
||||
any,
|
||||
borrow::Cow,
|
||||
fmt::{Debug, Formatter, Result as FmtResult},
|
||||
marker::PhantomData,
|
||||
@@ -8,7 +7,8 @@ use std::{
|
||||
|
||||
use crate::{
|
||||
model::mode::{ConvertStatus, IGameMode},
|
||||
ModeDifficulty,
|
||||
util::generic_fmt::GenericFormatter,
|
||||
Difficulty,
|
||||
};
|
||||
|
||||
use super::Beatmap;
|
||||
@@ -74,13 +74,13 @@ impl<M: IGameMode> Converted<'_, M> {
|
||||
}
|
||||
|
||||
/// Create a gradual difficulty calculator for the map.
|
||||
pub fn gradual_difficulty(&self, difficulty: &ModeDifficulty) -> M::GradualDifficulty {
|
||||
difficulty.gradual_difficulty(self)
|
||||
pub fn gradual_difficulty(&self, difficulty: &Difficulty) -> M::GradualDifficulty {
|
||||
M::gradual_difficulty(difficulty, self)
|
||||
}
|
||||
|
||||
/// Create a gradual performance calculator for the map.
|
||||
pub fn gradual_performance(&self, difficulty: &ModeDifficulty) -> M::GradualPerformance {
|
||||
difficulty.gradual_performance(self)
|
||||
pub fn gradual_performance(&self, difficulty: &Difficulty) -> M::GradualPerformance {
|
||||
M::gradual_performance(difficulty, self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,34 +189,9 @@ impl<M> Clone for Converted<'_, M> {
|
||||
|
||||
impl<M> Debug for Converted<'_, M> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
struct GenericFormatter<T>(PhantomData<T>);
|
||||
|
||||
impl<T> Default for GenericFormatter<T> {
|
||||
fn default() -> Self {
|
||||
Self(PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Debug for GenericFormatter<T> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
fn fmt_stripped(full_type_name: &str, f: &mut Formatter<'_>) -> FmtResult {
|
||||
// Strip fully qualified syntax
|
||||
if let Some(position) = full_type_name.rfind("::") {
|
||||
if let Some(type_name) = full_type_name.get(position + 2..) {
|
||||
f.write_str(type_name)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fmt_stripped(any::type_name::<T>(), f)
|
||||
}
|
||||
}
|
||||
|
||||
f.debug_struct("Converted")
|
||||
.field("map", &self.map)
|
||||
.field("mode", &GenericFormatter::<M>::default())
|
||||
.field("mode", &GenericFormatter::<M>::new())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use rosu_map::{
|
||||
|
||||
use crate::{
|
||||
catch::Catch, mania::Mania, osu::Osu, taiko::Taiko, Difficulty, GradualDifficulty,
|
||||
GradualPerformance, ModeDifficulty, Performance,
|
||||
GradualPerformance, Performance,
|
||||
};
|
||||
|
||||
pub use self::{
|
||||
@@ -85,23 +85,18 @@ impl Beatmap {
|
||||
bpm::bpm(self.hit_objects.last(), &self.timing_points)
|
||||
}
|
||||
|
||||
/// Create a difficulty calculator for this [`Beatmap`].
|
||||
pub const fn difficulty(&self) -> Difficulty<'_> {
|
||||
Difficulty::new(self)
|
||||
}
|
||||
|
||||
/// Create a performance calculator for this [`Beatmap`].
|
||||
pub const fn performance(&self) -> Performance<'_> {
|
||||
Performance::new(self)
|
||||
}
|
||||
|
||||
/// Create a gradual difficulty calculator for this [`Beatmap`].
|
||||
pub fn gradual_difficulty(&self, difficulty: &ModeDifficulty) -> GradualDifficulty {
|
||||
pub fn gradual_difficulty(&self, difficulty: &Difficulty) -> GradualDifficulty {
|
||||
GradualDifficulty::new(difficulty, self)
|
||||
}
|
||||
|
||||
/// Create a gradual performance calculator for this [`Beatmap`].
|
||||
pub fn gradual_performance(&self, difficulty: &ModeDifficulty) -> GradualPerformance {
|
||||
pub fn gradual_performance(&self, difficulty: &Difficulty) -> GradualPerformance {
|
||||
GradualPerformance::new(difficulty, self)
|
||||
}
|
||||
|
||||
@@ -126,7 +121,7 @@ impl Beatmap {
|
||||
}
|
||||
|
||||
/// Convert a [`&mut Beatmap`] to the specified mode with an argument
|
||||
/// instead of a generic parameter and return the [`ConvertStatus`].
|
||||
/// instead of a generic parameter.
|
||||
///
|
||||
/// [`&mut Beatmap`]: Beatmap
|
||||
pub fn convert_inplace(&mut self, mode: GameMode) -> ConvertStatus {
|
||||
|
||||
+6
-8
@@ -1,6 +1,6 @@
|
||||
pub use rosu_map::section::general::GameMode;
|
||||
|
||||
use crate::any::ModeDifficulty;
|
||||
use crate::Difficulty;
|
||||
|
||||
use super::beatmap::{Beatmap, Converted};
|
||||
|
||||
@@ -40,27 +40,25 @@ pub trait IGameMode: Sized {
|
||||
|
||||
/// Perform a difficulty calculation for a [`Converted`] beatmap and
|
||||
/// process the final skill values.
|
||||
fn difficulty(
|
||||
difficulty: &ModeDifficulty,
|
||||
map: &Converted<'_, Self>,
|
||||
) -> Self::DifficultyAttributes;
|
||||
fn difficulty(difficulty: &Difficulty, map: &Converted<'_, Self>)
|
||||
-> Self::DifficultyAttributes;
|
||||
|
||||
/// Perform a difficulty calculation for a [`Converted`] beatmap without
|
||||
/// processing the final skill values.
|
||||
fn strains(difficulty: &ModeDifficulty, map: &Converted<'_, Self>) -> Self::Strains;
|
||||
fn strains(difficulty: &Difficulty, map: &Converted<'_, Self>) -> Self::Strains;
|
||||
|
||||
/// Create a performance calculator for a [`Converted`] beatmap.
|
||||
fn performance(map: Converted<'_, Self>) -> Self::Performance<'_>;
|
||||
|
||||
/// Create a gradual difficulty calculator for a [`Converted`] beatmap.
|
||||
fn gradual_difficulty(
|
||||
difficulty: &ModeDifficulty,
|
||||
difficulty: &Difficulty,
|
||||
map: &Converted<'_, Self>,
|
||||
) -> Self::GradualDifficulty;
|
||||
|
||||
/// Create a gradual performance calculator for a [`Converted`] beatmap.
|
||||
fn gradual_performance(
|
||||
difficulty: &ModeDifficulty,
|
||||
difficulty: &Difficulty,
|
||||
map: &Converted<'_, Self>,
|
||||
) -> Self::GradualPerformance;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user