rosu_pp/catch/
score_state.rs

1/// Aggregation for a score's current state.
2#[derive(Clone, Debug, PartialEq, Eq)]
3pub struct CatchScoreState {
4    /// Maximum combo that the score has had so far.
5    /// **Not** the maximum possible combo of the map so far.
6    ///
7    /// Note that only fruits and droplets are considered for osu!catch combo.
8    pub max_combo: u32,
9    /// Amount of current fruits (300s).
10    pub fruits: u32,
11    /// Amount of current droplets (100s).
12    pub droplets: u32,
13    /// Amount of current tiny droplets (50s).
14    pub tiny_droplets: u32,
15    /// Amount of current tiny droplet misses (katus).
16    pub tiny_droplet_misses: u32,
17    /// Amount of current misses (fruits and droplets).
18    pub misses: u32,
19}
20
21impl CatchScoreState {
22    /// Create a new empty score state.
23    pub const fn new() -> Self {
24        Self {
25            max_combo: 0,
26            fruits: 0,
27            droplets: 0,
28            tiny_droplets: 0,
29            tiny_droplet_misses: 0,
30            misses: 0,
31        }
32    }
33
34    /// Return the total amount of hits by adding everything up.
35    pub const fn total_hits(&self) -> u32 {
36        self.fruits + self.droplets + self.tiny_droplets + self.tiny_droplet_misses + self.misses
37    }
38
39    /// Calculate the accuracy between `0.0` and `1.0` for this state.
40    pub fn accuracy(&self) -> f64 {
41        let total_hits = self.total_hits();
42
43        if total_hits == 0 {
44            return 0.0;
45        }
46
47        let numerator = self.fruits + self.droplets + self.tiny_droplets;
48        let denominator = total_hits;
49
50        f64::from(numerator) / f64::from(denominator)
51    }
52}
53
54impl Default for CatchScoreState {
55    fn default() -> Self {
56        Self::new()
57    }
58}