peace_performance/parse/
hitobject.rs

1use super::Pos2;
2
3#[cfg(any(
4    feature = "fruits",
5    all(feature = "osu", not(feature = "no_sliders_no_leniency"))
6))]
7use super::PathType;
8
9use std::cmp::Ordering;
10
11/// "Intermediate" hitobject created through parsing.
12/// Each mode will handle them differently.
13#[derive(Clone, Debug, PartialEq)]
14pub struct HitObject {
15    pub pos: Pos2,
16    pub start_time: f32,
17    pub kind: HitObjectKind,
18    pub sound: u8,
19}
20
21impl HitObject {
22    #[inline]
23    pub fn end_time(&self) -> f32 {
24        match &self.kind {
25            HitObjectKind::Circle { .. } => self.start_time,
26            // incorrect, only called in mania which has no sliders though
27            HitObjectKind::Slider { .. } => self.start_time,
28            HitObjectKind::Spinner { end_time } => *end_time,
29            HitObjectKind::Hold { end_time, .. } => *end_time,
30        }
31    }
32
33    #[inline]
34    pub fn is_circle(&self) -> bool {
35        matches!(self.kind, HitObjectKind::Circle { .. })
36    }
37
38    #[inline]
39    pub fn is_slider(&self) -> bool {
40        matches!(self.kind, HitObjectKind::Slider { .. })
41    }
42
43    #[inline]
44    pub fn is_spinner(&self) -> bool {
45        matches!(self.kind, HitObjectKind::Spinner { .. })
46    }
47}
48
49impl PartialOrd for HitObject {
50    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
51        self.start_time.partial_cmp(&other.start_time)
52    }
53}
54
55/// Further data related to specific object types.
56#[derive(Clone, Debug, PartialEq)]
57pub enum HitObjectKind {
58    Circle,
59    #[cfg(any(
60        feature = "fruits",
61        all(feature = "osu", not(feature = "no_sliders_no_leniency"))
62    ))]
63    Slider {
64        pixel_len: f32,
65        repeats: usize,
66        curve_points: Vec<Pos2>,
67        path_type: PathType,
68    },
69    #[cfg(not(any(
70        feature = "fruits",
71        all(feature = "osu", not(feature = "no_sliders_no_leniency"))
72    )))]
73    Slider {
74        pixel_len: f32,
75        repeats: usize,
76    },
77    Spinner {
78        end_time: f32,
79    },
80    Hold {
81        end_time: f32,
82    },
83}