rosu_pp/any/
attributes.rs

1use crate::{
2    catch::{CatchDifficultyAttributes, CatchPerformanceAttributes},
3    mania::{ManiaDifficultyAttributes, ManiaPerformanceAttributes},
4    osu::{OsuDifficultyAttributes, OsuPerformanceAttributes},
5    taiko::{TaikoDifficultyAttributes, TaikoPerformanceAttributes},
6};
7
8use super::performance::{into::IntoPerformance, Performance};
9
10/// The result of a difficulty calculation based on the mode.
11#[derive(Clone, Debug, PartialEq)]
12pub enum DifficultyAttributes {
13    /// osu!standard difficulty calculation result.
14    Osu(OsuDifficultyAttributes),
15    /// osu!taiko difficulty calculation result.
16    Taiko(TaikoDifficultyAttributes),
17    /// osu!catch difficulty calculation result.
18    Catch(CatchDifficultyAttributes),
19    /// osu!mania difficulty calculation result.
20    Mania(ManiaDifficultyAttributes),
21}
22
23impl DifficultyAttributes {
24    /// The star value.
25    pub const fn stars(&self) -> f64 {
26        match self {
27            Self::Osu(attrs) => attrs.stars,
28            Self::Taiko(attrs) => attrs.stars,
29            Self::Catch(attrs) => attrs.stars,
30            Self::Mania(attrs) => attrs.stars,
31        }
32    }
33
34    /// The maximum combo of the map.
35    pub const fn max_combo(&self) -> u32 {
36        match self {
37            Self::Osu(attrs) => attrs.max_combo,
38            Self::Taiko(attrs) => attrs.max_combo,
39            Self::Catch(attrs) => attrs.max_combo(),
40            Self::Mania(attrs) => attrs.max_combo,
41        }
42    }
43
44    /// Returns a builder for performance calculation.
45    pub fn performance<'a>(self) -> Performance<'a> {
46        self.into_performance()
47    }
48}
49
50/// The result of a performance calculation based on the mode.
51#[derive(Clone, Debug, PartialEq)]
52pub enum PerformanceAttributes {
53    /// osu!standard performance calculation result.
54    Osu(OsuPerformanceAttributes),
55    /// osu!taiko performance calculation result.
56    Taiko(TaikoPerformanceAttributes),
57    /// osu!catch performance calculation result.
58    Catch(CatchPerformanceAttributes),
59    /// osu!mania performance calculation result.
60    Mania(ManiaPerformanceAttributes),
61}
62
63impl PerformanceAttributes {
64    /// The pp value.
65    pub const fn pp(&self) -> f64 {
66        match self {
67            Self::Osu(attrs) => attrs.pp,
68            Self::Taiko(attrs) => attrs.pp,
69            Self::Catch(attrs) => attrs.pp,
70            Self::Mania(attrs) => attrs.pp,
71        }
72    }
73
74    /// The star value.
75    pub const fn stars(&self) -> f64 {
76        match self {
77            Self::Osu(attrs) => attrs.stars(),
78            Self::Taiko(attrs) => attrs.stars(),
79            Self::Catch(attrs) => attrs.stars(),
80            Self::Mania(attrs) => attrs.stars(),
81        }
82    }
83
84    /// Difficulty attributes that were used for the performance calculation.
85    pub fn difficulty_attributes(&self) -> DifficultyAttributes {
86        match self {
87            Self::Osu(attrs) => DifficultyAttributes::Osu(attrs.difficulty.clone()),
88            Self::Taiko(attrs) => DifficultyAttributes::Taiko(attrs.difficulty.clone()),
89            Self::Catch(attrs) => DifficultyAttributes::Catch(attrs.difficulty.clone()),
90            Self::Mania(attrs) => DifficultyAttributes::Mania(attrs.difficulty.clone()),
91        }
92    }
93
94    /// The maximum combo of the map.
95    pub const fn max_combo(&self) -> u32 {
96        match self {
97            Self::Osu(attrs) => attrs.difficulty.max_combo,
98            Self::Taiko(attrs) => attrs.difficulty.max_combo,
99            Self::Catch(attrs) => attrs.difficulty.max_combo(),
100            Self::Mania(attrs) => attrs.difficulty.max_combo,
101        }
102    }
103
104    /// Returns a builder for performance calculation.
105    pub fn performance<'a>(self) -> Performance<'a> {
106        self.into_performance()
107    }
108}
109
110impl From<PerformanceAttributes> for DifficultyAttributes {
111    fn from(attrs: PerformanceAttributes) -> Self {
112        attrs.difficulty_attributes()
113    }
114}