added some convenience methods

This commit is contained in:
MaxOhn
2024-02-26 17:10:54 +01:00
parent 8d2132c124
commit 1a5f9b9681
11 changed files with 211 additions and 70 deletions
+19 -23
View File
@@ -8,7 +8,7 @@ use crate::{
mania::{ManiaBeatmap, ManiaGradualPerformance},
osu::{OsuBeatmap, OsuGradualPerformance},
taiko::{TaikoBeatmap, TaikoGradualPerformance},
Beatmap, Converted, ModeDifficulty,
Beatmap, ModeDifficulty,
};
/// Gradually calculate the performance attributes on maps of any mode.
@@ -97,10 +97,10 @@ pub enum GradualPerformance {
}
macro_rules! from_converted {
( $fn:ident, $mode:ident, $converted:ident, $gradual:ident ) => {
( $fn:ident, $mode:ident, $converted:ident ) => {
#[doc = concat!("Create a [`GradualPerformance`] for a [`", stringify!($converted), "`]")]
pub fn $fn(difficulty: &ModeDifficulty, converted: &$converted<'_>) -> Self {
Self::$mode($gradual::new(difficulty, converted))
Self::$mode(difficulty.gradual_performance(converted))
}
};
}
@@ -111,29 +111,25 @@ impl GradualPerformance {
let map = Cow::Borrowed(map);
match map.mode {
GameMode::Osu => Self::Osu(OsuGradualPerformance::new(
difficulty,
&Converted::new(map, false),
)),
GameMode::Taiko => Self::Taiko(TaikoGradualPerformance::new(
difficulty,
&Converted::new(map, false),
)),
GameMode::Catch => Self::Catch(CatchGradualPerformance::new(
difficulty,
&Converted::new(map, false),
)),
GameMode::Mania => Self::Mania(ManiaGradualPerformance::new(
difficulty,
&Converted::new(map, false),
)),
GameMode::Osu => {
Self::Osu(difficulty.gradual_performance(&OsuBeatmap::new(map, false)))
}
GameMode::Taiko => {
Self::Taiko(difficulty.gradual_performance(&TaikoBeatmap::new(map, false)))
}
GameMode::Catch => {
Self::Catch(difficulty.gradual_performance(&CatchBeatmap::new(map, false)))
}
GameMode::Mania => {
Self::Mania(difficulty.gradual_performance(&ManiaBeatmap::new(map, false)))
}
}
}
from_converted!(from_osu_map, Osu, OsuBeatmap, OsuGradualPerformance);
from_converted!(from_taiko_map, Taiko, TaikoBeatmap, TaikoGradualPerformance);
from_converted!(from_catch_map, Catch, CatchBeatmap, CatchGradualPerformance);
from_converted!(from_mania_map, Mania, ManiaBeatmap, ManiaGradualPerformance);
from_converted!(from_osu_map, Osu, OsuBeatmap);
from_converted!(from_taiko_map, Taiko, TaikoBeatmap);
from_converted!(from_catch_map, Catch, CatchBeatmap);
from_converted!(from_mania_map, Mania, ManiaBeatmap);
/// Process the next hit object and calculate the performance attributes
/// for the resulting score state.
+7 -7
View File
@@ -288,25 +288,25 @@ impl<A: AttributeProvider> From<A> for Performance<'_> {
}
macro_rules! impl_from_converted {
( $mode:ident: $performance:ident ) => {
( $mode:ident ) => {
impl<'a> From<Converted<'a, $mode>> for Performance<'a> {
fn from(converted: Converted<'a, $mode>) -> Self {
Self::$mode($performance::new(converted))
Self::$mode(converted.into())
}
}
impl<'a, 'b: 'a> From<&'b Converted<'a, $mode>> for Performance<'a> {
fn from(converted: &'b Converted<'a, $mode>) -> Self {
Self::$mode($performance::new(converted.as_owned()))
Self::$mode(converted.as_owned().into())
}
}
};
}
impl_from_converted!(Osu: OsuPerformance);
impl_from_converted!(Taiko: TaikoPerformance);
impl_from_converted!(Catch: CatchPerformance);
impl_from_converted!(Mania: ManiaPerformance);
impl_from_converted!(Osu);
impl_from_converted!(Taiko);
impl_from_converted!(Catch);
impl_from_converted!(Mania);
/// While generating remaining hitresults, decide how they should be distributed.
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]