use bincode::{Decode, Encode};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Encode, Decode)]
pub enum NoteType {
Tap,
Hold { duration_us: i64 },
Burst { duration_us: i64 },
Mine,
}
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
pub struct Note {
pub time_us: i64,
pub column: u8,
pub note_type: NoteType,
pub hitsound_index: Option<u16>,
}
impl Note {
#[must_use]
pub fn tap(time_us: i64, column: u8) -> Self {
Self {
time_us,
column,
note_type: NoteType::Tap,
hitsound_index: None,
}
}
#[must_use]
pub fn hold(time_us: i64, duration_us: i64, column: u8) -> Self {
Self {
time_us,
column,
note_type: NoteType::Hold { duration_us },
hitsound_index: None,
}
}
#[must_use]
pub fn burst(time_us: i64, duration_us: i64, column: u8) -> Self {
Self {
time_us,
column,
note_type: NoteType::Burst { duration_us },
hitsound_index: None,
}
}
#[must_use]
pub fn mine(time_us: i64, column: u8) -> Self {
Self {
time_us,
column,
note_type: NoteType::Mine,
hitsound_index: None,
}
}
#[must_use]
pub fn is_hold(&self) -> bool {
matches!(self.note_type, NoteType::Hold { .. })
}
#[must_use]
pub fn is_burst(&self) -> bool {
matches!(self.note_type, NoteType::Burst { .. })
}
#[must_use]
pub fn is_mine(&self) -> bool {
matches!(self.note_type, NoteType::Mine)
}
#[must_use]
pub fn duration_us(&self) -> i64 {
match self.note_type {
NoteType::Tap | NoteType::Mine => 0,
NoteType::Hold { duration_us } | NoteType::Burst { duration_us } => duration_us,
}
}
#[must_use]
pub fn end_time_us(&self) -> i64 {
self.time_us + self.duration_us()
}
}