rosu_pp/any/difficulty/
inspect.rs

1use crate::{model::mods::GameMods, Difficulty};
2
3use super::ModsDependent;
4
5/// [`Difficulty`] but all fields are public for inspection.
6#[derive(Clone, Debug, Default, PartialEq)]
7pub struct InspectDifficulty {
8    /// Specify mods.
9    pub mods: GameMods,
10    /// Amount of passed objects for partial plays, e.g. a fail.
11    pub passed_objects: Option<u32>,
12    /// Adjust the clock rate used in the calculation.
13    pub clock_rate: Option<f64>,
14    /// Override a beatmap's set AR.
15    ///
16    /// Only relevant for osu! and osu!catch.
17    pub ar: Option<ModsDependent>,
18    /// Override a beatmap's set CS.
19    ///
20    /// Only relevant for osu! and osu!catch.
21    pub cs: Option<ModsDependent>,
22    /// Override a beatmap's set HP.
23    pub hp: Option<ModsDependent>,
24    /// Override a beatmap's set OD.
25    pub od: Option<ModsDependent>,
26    /// Adjust patterns as if the HR mod is enabled.
27    ///
28    /// Only relevant for osu!catch.
29    pub hardrock_offsets: Option<bool>,
30    /// Whether the calculated attributes belong to an osu!lazer or osu!stable
31    /// score.
32    ///
33    /// Defaults to `true`.
34    pub lazer: Option<bool>,
35}
36
37impl InspectDifficulty {
38    /// Convert `self` into a [`Difficulty`].
39    pub fn into_difficulty(self) -> Difficulty {
40        let Self {
41            mods,
42            passed_objects,
43            clock_rate,
44            ar,
45            cs,
46            hp,
47            od,
48            hardrock_offsets,
49            lazer,
50        } = self;
51
52        let mut difficulty = Difficulty::new().mods(mods);
53
54        if let Some(passed_objects) = passed_objects {
55            difficulty = difficulty.passed_objects(passed_objects);
56        }
57
58        if let Some(clock_rate) = clock_rate {
59            difficulty = difficulty.clock_rate(clock_rate);
60        }
61
62        if let Some(ar) = ar {
63            difficulty = difficulty.ar(ar.value, ar.with_mods);
64        }
65
66        if let Some(cs) = cs {
67            difficulty = difficulty.cs(cs.value, cs.with_mods);
68        }
69
70        if let Some(hp) = hp {
71            difficulty = difficulty.hp(hp.value, hp.with_mods);
72        }
73
74        if let Some(od) = od {
75            difficulty = difficulty.od(od.value, od.with_mods);
76        }
77
78        if let Some(hardrock_offsets) = hardrock_offsets {
79            difficulty = difficulty.hardrock_offsets(hardrock_offsets);
80        }
81
82        if let Some(lazer) = lazer {
83            difficulty = difficulty.lazer(lazer);
84        }
85
86        difficulty
87    }
88}
89
90impl From<InspectDifficulty> for Difficulty {
91    fn from(difficulty: InspectDifficulty) -> Self {
92        difficulty.into_difficulty()
93    }
94}
95
96impl From<Difficulty> for InspectDifficulty {
97    fn from(difficulty: Difficulty) -> Self {
98        difficulty.inspect()
99    }
100}